在之前的ASP.Net版本中,NServiceBus示例声明在global.asax中创建Bus实例。然后在应用程序的Dispose上(在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中没有处置。是否应该以某种方式保持公交车的实例? vNext是否应该遵循其他一些模式?
谢谢!
答案 0 :(得分:6)
如果我没有弄错的话,您似乎将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
所以一旦他们发布了,我们应该能够在那里开始公共汽车。