NServiceBus 与自定义 NHibernate ConnectionProvider

发布于 2024-11-26 10:49:38 字数 2882 浏览 3 评论 0原文

问题: NSB 不会使用我们的自定义 NHB ConnectionProvider。

我使用以下设置在代码中配置 NSB(log4net 是 app.config 文件中的唯一内容):

        NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

        NServiceBus.Configure.With()
            .CustomConfigurationSource(ObjectFactory.GetInstance<IConfigurationSource>())
                .StructureMapBuilder()
                .XmlSerializer()
                .DBSubcriptionStorage(GetNHibernateConfiguration(), false)
                .MsmqTransport()
                    .IsTransactional(false)
                    .PurgeOnStartup(false)
                    .UnicastBus()
                    .LoadMessageHandlers( First<MyEventHandler1>
                                            .Then<MyEventHandler2>())
                    .CreateBus()
            .Start();

只要我不使用 DBSubscription 存储而不是 MSMQ 存储,这就可以工作。但我需要 DBStorage。

目前我们有自己的自定义 ConnectionProvider,它在大约 10-15 个其他项目中运行良好,但是当我尝试将它与 NSB 一起使用时,我收到一个错误,这对我来说没有任何意义。如果我省略 ConnectionProvider 并使用标准 NHB,那么它就可以正常工作。

自定义提供商:

    public class MyProvider : DriverConnectionProvider
    {
        public override IDbConnection GetConnection()
        {
            var oracleRoleProvider = new OracleRoleProvider();
            var dbConnection = Driver.CreateConnection();
            return oracleRoleProvider.SetUserRoles(dbConnection);            }
    }

与标准 NHB 提供商一起使用的配置(但这不是我想要的):

        retval.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
        retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
        retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");

不起作用的配置,但应该:

        retval.Add("connection.provider", "MyNamespace.MyProvider, MyNamespace");
        retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
        retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
        retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");

<强>抛出异常:

       Exception:
       Could not instantiate connection provider:   MyProvider

       Inner:
       Unable to cast object of type 'MyProvider' to type 'NHibernate.Connection.IConnectionProvider'.

使用的版本

       NServiceBus: 2.5.0.1476
       NHibernate: 3.1.0.4000

任何人都可以阐明这个问题吗?

我在这里拔掉了我的头发,显然 MyProvider 通过 DriverConnectionProvider 实现 IConnectionProvider :) :S。

亲切的问候

Problem:
NSB won't use our Custom NHB ConnectionProvider.

Im configuring NSB in code with the following setup (log4net is the only thing in the app.config file):

        NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

        NServiceBus.Configure.With()
            .CustomConfigurationSource(ObjectFactory.GetInstance<IConfigurationSource>())
                .StructureMapBuilder()
                .XmlSerializer()
                .DBSubcriptionStorage(GetNHibernateConfiguration(), false)
                .MsmqTransport()
                    .IsTransactional(false)
                    .PurgeOnStartup(false)
                    .UnicastBus()
                    .LoadMessageHandlers( First<MyEventHandler1>
                                            .Then<MyEventHandler2>())
                    .CreateBus()
            .Start();

And this works as long as I do not use DBSubscription storage instead of MSMQ storage. But I need the DBStorage.

Currently we have our own custom ConnectionProvider, which works fine in about 10-15 other projects, but when I try to use it with NSB i get an error which dosent make any sense to me. If I leave out the ConnectionProvider and go with standard NHB then it works just fine.

Custom Provider:

    public class MyProvider : DriverConnectionProvider
    {
        public override IDbConnection GetConnection()
        {
            var oracleRoleProvider = new OracleRoleProvider();
            var dbConnection = Driver.CreateConnection();
            return oracleRoleProvider.SetUserRoles(dbConnection);            }
    }

Config which works with standard NHB provider (but this is not what I want):

        retval.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
        retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
        retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");

Config that doesnt work, but should:

        retval.Add("connection.provider", "MyNamespace.MyProvider, MyNamespace");
        retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
        retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
        retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");

Exception thrown:

       Exception:
       Could not instantiate connection provider:   MyProvider

       Inner:
       Unable to cast object of type 'MyProvider' to type 'NHibernate.Connection.IConnectionProvider'.

Versions used

       NServiceBus: 2.5.0.1476
       NHibernate: 3.1.0.4000

Can anyone shed some light on this issue?

I'm pulling out my hair here sine obviously MyProvider implements IConnectionProvider via DriverConnectionProvider :) :S.

Kind regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-12-03 10:49:38

NServiceBus 合并并内部化了 NHibernate。这意味着您继承的类与 NSB 引用的类 (DriverConnectionProvider) 不同。 NSB 2.5 中的唯一解决方法是使用不合并任何依赖项的仅核心版本的 NSB。当我们将 NH 支持移至一个单独的 dll 且不进行合并时,这一切都将在 3.0 中发生改变。

另一种选择是构建您自己的子存储(阅读:复制并粘贴然后 NSB 子存储)

希望这会有所帮助!

NServiceBus merges and internalizes NHibernate. This means that the class you inherited is not that same as the one NSB is referencing (DriverConnectionProvider). The only workaround in NSB 2.5 is to use the core-only version of NSB that doesn't merge any dependencies. This will all change in 3.0 when we move the NH support to a separate dll with no merging.

Another option would be to build your own substorage (read: copy & paste then NSB one)

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文