我有一个带有hangfire和服务堆栈服务的控制台应用程序。Hangfire 有自己的 IOC 适配器实现,它已集成到 Funq 适配器中。我正在尝试使用 IGatewayService 来调用 inproc 服务。
网关始终为空。
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 适配器和网关始终为空。我可以在寄存器中创建网关,new TestServiceGateway()
但它需要一个IRequest
. 如果我在那里传递 null 它也不会工作。
hangfire 调用很简单:
RecurringJob.AddOrUpdate<Tests>((t) => t.Test3(), Cron.Yearly(12, 12));