在 MVC 6 中配置 NServiceBus 总线实例
Disposing NServiceBus bus instance in MVC 6
在之前的 ASP.Net 版本中,NServiceBus 示例声明在 global.asax 中创建一个 Bus 实例。然后在处理应用程序时(在 global.asax 中),将处理前面提到的总线实例。有点像下面的缩写版本:
IBus bus;
protected void Application_Start()
{
//Bunch of bus configuration and controller registration etc...
//Now Create the bus and assign to a local variable so we can dispose it
var startableBus = Bus.Create(busConfiguration);
bus = startableBus.Start();
}
public override void Dispose()
{
if (bus != null)
{
bus.Dispose();
}
base.Dispose();
}
但是在 vNext 中,据我所知 Startup.cs 中没有 dispose。是否应该保留并以某种方式处置总线实例? vNext 是否应该遵循其他一些模式?
谢谢!
如果我没记错的话,你好像是把IApplicationLifetime
添加到Configure
然后等待ApplicationStopping
被取消。
这是一个片段:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory, IApplicationLifetime lifetime)
{
// New up/start bus here
lifetime.ApplicationStopping.Register(() =>
{
// Stop the bus here
});
而且他们似乎正在计划 IApplicationLifetime.ApplicationStarted
所以一旦他们发布了,我们应该可以在那里启动公共汽车。
在之前的 ASP.Net 版本中,NServiceBus 示例声明在 global.asax 中创建一个 Bus 实例。然后在处理应用程序时(在 global.asax 中),将处理前面提到的总线实例。有点像下面的缩写版本:
IBus bus;
protected void Application_Start()
{
//Bunch of bus configuration and controller registration etc...
//Now Create the bus and assign to a local variable so we can dispose it
var startableBus = Bus.Create(busConfiguration);
bus = startableBus.Start();
}
public override void Dispose()
{
if (bus != null)
{
bus.Dispose();
}
base.Dispose();
}
但是在 vNext 中,据我所知 Startup.cs 中没有 dispose。是否应该保留并以某种方式处置总线实例? vNext 是否应该遵循其他一些模式?
谢谢!
如果我没记错的话,你好像是把IApplicationLifetime
添加到Configure
然后等待ApplicationStopping
被取消。
这是一个片段:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory, IApplicationLifetime lifetime)
{
// New up/start bus here
lifetime.ApplicationStopping.Register(() =>
{
// Stop the bus here
});
而且他们似乎正在计划 IApplicationLifetime.ApplicationStarted
所以一旦他们发布了,我们应该可以在那里启动公共汽车。