2017-04-19 11 views
1

私はハングファイアとサービススタックサービスを備えたコンソールアプリケーションを持っています。 Hangfireには独自のIOCアダプタ実装があり、Funqアダプタに統合されています。 Inprocサービスを呼び出すためにIGatewayServiceを使用しようとしています。ServiceStack非サービス/非コントローラとIOCのIServiceGateway

ゲートウェイは常にnullです。

public class Tests 
{ 
    public IServiceGateway gateway { get; set; } 
    public Tests() 
    { 
     gateway = HostContext.TryResolve<IServiceGateway>(); //tried this along with every type of registration 

    } 
    public void Test3() { 
     // I want to use gateway here to call an inproc service 
    } 
} 

私が試してみた:

Container.Register<IServiceGatewayFactory>(x => new TestServiceGatewayFactory()) 
      .ReusedWithin(ReuseScope.None); 

      Container.Register<Tests>(new Tests() { gateway = Container.Resolve<IServiceGateway>() }); 

そして、いくつかの他の非funqアダプタをし、ゲートウェイは常にnullです。私はレジスタnew TestServiceGateway()にゲートウェイを作成することができましたが、IRequestが必要です。そこにnullを渡すと、どちらもうまくいきません。

hangfire呼び出しは単純です:

RecurringJob.AddOrUpdate<Tests>((t) => t.Test3(), Cron.Yearly(12, 12)); 

答えて

0

サービス・ゲートウェイを取得するためのAPIです:Requestはあなたが外ASP.NET要求から作成することができますServiceStack IRequestある

HostContext.AppHost.GetServiceGateway(Request); 

ServiceStackの:

var request = HttpContext.Current.ToRequest(); 

Oあなたはモックリクエストを作成することができます:

var request = new MockHttpRequest(); 
+0

HttpContextがない場合は、 – lucuma

+0

@lucuma「MockHttpRequest」を含むように私の答えを更新しました – mythz

+0

それを追跡してくれてありがとうございました。ありがとうございました。私は 'LightContainer.Register ((x)=> new tests() {Gateway = LightContainer.GetInstance ()} GetServiceGateway(new MockHttpRequest())}))のようになりました。私はLightInjectとFunqの両方を使用しています。 – lucuma

関連する問題