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));
HttpContextがない場合は、 – lucuma
@lucuma「MockHttpRequest」を含むように私の答えを更新しました – mythz
それを追跡してくれてありがとうございました。ありがとうございました。私は 'LightContainer.Register((x)=> new tests() {Gateway = LightContainer.GetInstance ()} GetServiceGateway(new MockHttpRequest())}))のようになりました。私はLightInjectとFunqの両方を使用しています。 –
lucuma