无法在 NServiceBus 中使用 CastleWindsor 解析 IMessageSession - 6.x [英] Cannot resolve IMessageSession with CastleWindsor in NServiceBus - 6.x

查看:57
本文介绍了无法在 NServiceBus 中使用 CastleWindsor 解析 IMessageSession - 6.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NServiceBus v6 和 NServiceBus.Host.我无法解析 messageSession 对象.我错过了什么?

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.

推荐答案

IMessageSession 未通过 NServiceBus 在容器中注册.启动端点时,您将获得对 IMessageSession 的引用:

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;

请参阅 https://docs.specific.net/nservicebus/upgrades/5to6/moving-away-from-ibus#dependency-injection 了解更多关于为什么 IMessageSession 没有被 NServiceBus 注入容器的信息.

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.

这篇关于无法在 NServiceBus 中使用 CastleWindsor 解析 IMessageSession - 6.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆