Cannot resolve IMessageSession with CastleWindsor in NServiceBus - 6.x

我怕爱的太早我们不能终老 提交于 2019-12-25 09:18:01

问题


I am using NServiceBus v6, with NServiceBus.Host. I am not able to resolve the messageSession object. What am I missing?

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.

回答1:


IMessageSession is not registered in the container by NServiceBus. You will get a reference to the IMessageSession when you start the endpoint:

var endpointInstance = await Endpoint.Start(endpointConfiguration);
IMessageSession messageSession = endpointInstance as IMessageSession;

See https://docs.particular.net/nservicebus/upgrades/5to6/moving-away-from-ibus#dependency-injection for more information about why IMessageSession is not injected into the container by NServiceBus.



来源:https://stackoverflow.com/questions/40619450/cannot-resolve-imessagesession-with-castlewindsor-in-nservicebus-6-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!