我正在使用NServiceBus v6和NServiceBus.Host。我无法解析messageSession对象。我错过了什么?
var container2 = new WindsorContainer();
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
log4net.Config.XmlConfigurator.Configure(new FileInfo("logging.config"));
LogManager.Use<Log4NetFactory>();
endpointConfiguration.DefineEndpointName("Strategy.Service");
endpointConfiguration.UseSerialization<JsonSerializer>();
endpointConfiguration.UsePersistence<NHibernatePersistence>();
endpointConfiguration.UseTransport<SqlServerTransport>();
endpointConfiguration.Conventions()
.DefiningCommandsAs(x => x.Namespace != null && x.Namespace.Contains("Commands"))
.DefiningEventsAs(x => x.Namespace != null && x.Namespace.Contains("Events"));
endpointConfiguration.UseContainer<WindsorBuilder>(
customizations: customizations =>
{
customizations.ExistingContainer(container2);
});
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.AuditProcessedMessagesTo("audit");
endpointConfiguration.DefineCriticalErrorAction(onCriticalError: async context =>
{
_logger.Fatal($"CRITICAL: {context.Error}", context.Exception);
await context.Stop()
.ConfigureAwait(false);
var output =
$"NServiceBus critical error: {Environment.NewLine}{context.Error}{Environment.NewLine}Shutting Down.";
Environment.FailFast(output, context.Exception);
});
var msgSessions = container2.Resolve<IMessageSession>(); // Cannot resolve IMessageSession.
答案 0 :(得分:3)
IMessageSession
。启动端点时,您将获得IMessageSession
的引用:
var endpointInstance = await Endpoint.Start(endpointConfiguration);
IMessageSession messageSession = endpointInstance as IMessageSession;
有关为什么IMessageSession
未被NServiceBus注入容器的详细信息,请参阅https://docs.particular.net/nservicebus/upgrades/5to6/moving-away-from-ibus#dependency-injection。