1

我有一个带有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));
4

1 回答 1

0

获取服务网关的 API 是:

HostContext.AppHost.GetServiceGateway(Request);

您可以从 ServiceStack 之外的 ASP.NET 请求创建Request的 ServiceStack在哪里:IRequest

var request = HttpContext.Current.ToRequest();

或者您可以使用以下命令创建模拟请求:

var request = new MockHttpRequest();
于 2017-04-19T21:52:09.007 回答