【发布时间】:2015-04-14 21:29:47
【问题描述】:
我有一个发送 nservicebus 消息的 asp.net web api 控制器,即 Bus.Send()。这个 api 控制器是使用 owinselfhost 包自行托管的。
如果我使用 owinselfhost,注入总线的正确方法是什么?
--编辑--
这是代码.. 我现在使用 autofac.. 拥有这些仍然会给我在总线上的 null ref 异常...
参考:
http://docs.autofac.org/en/latest/integration/webapi.html#owin-integration
http://docs.particular.net/nservicebus/containers/
--编辑--
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
//this two controllers are from two separate class libraries.
builder.RegisterApiControllers(typeof(Test1Controller).Assembly);
builder.RegisterApiControllers(typeof(Test2Controller).Assembly);
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
Configure.With()
.UsingContainer<AutofacObjectBuilder>()
.UnicastBus()
.SendOnly();
app.UseAutofacMiddleware(container);
app.UseAutofacWebApi(config);
app.UseWebApi(config);
}
【问题讨论】:
-
您使用的是什么容器?我用 Autofac 做到这一点没有任何问题,使用 Autofac 模块用于 Owin 和 WebAPI 完全没有问题。
-
你能分享一下这是如何使用 autofac 完成的吗? TIA
-
创建一个容器,根据您使用的功能和 Autofac 文档为您的 Web 框架进行所有注册,然后按照文档中的说明使用带有 NServiceBus 的 Autofac 容器。我不知道你用的是什么,Owin 只是 web 服务器和 web 框架之间的一层,我不知道你用的是什么 web 框架,注册是特定于框架的。
-
@AlexeyZimarev 见上面修改过的问题..
标签: asp.net asp.net-web-api nservicebus owin self-hosting