通过对象属性表达的不满足的依赖关系

发布于 2024-10-16 15:22:26 字数 2480 浏览 1 评论 0原文

所以我正在构建发布者,以下是我的配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="DBSubscriptionStorageConfig" type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
</configSections>


<!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
   2. Input queue must be on the same machine as the process feeding off of it.
   3. Error queue can (and often should) be on a different machine.
   4. The community edition doesn't support more than one worker thread.
-->

<MsmqTransportConfig
InputQueue="HomeOfficePublisherQueue"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>

<DBSubscriptionStorageConfig>
<NHibernateProperties>
  <add Key="connection.provider"
       Value="NHibernate.Connection.DriverConnectionProvider"/>
  <add Key="connection.driver_class"
       Value="NHibernate.Driver.SqlClientDriver"/>
  <add Key="connection.connection_string"
       Value="Server=<dbserver>;initial catalog=NServiceBus;Integrated Security=SSPI"/>
  <add Key="dialect"
       Value="NHibernate.Dialect.MsSql2005Dialect"/>
 </NHibernateProperties>
</DBSubscriptionStorageConfig>


<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress=""
ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
</MessageEndpointMappings>
</UnicastBusConfig>


</configuration>

,这是我的端点

class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .UnicastBus()
            .ImpersonateSender(false)
            .MsmqTransport()
            .IsTransactional(true)
            .DBSubcriptionStorage();
    }
}

}

启动端点时出现以下异常

异常,已记录错误。原因:创建名为“NServiceBus.Unicast.UnicastBus”的对象时出错:通过对象属性“SubscriptionStorage”表达的依赖关系不满足:有 2 个类型为 [NServiceBus.Unicast.Subscriptions.ISubscriptionStorage] 的对象用于按类型自动装配,而本应有只需 1 即可自动装配对象“NServiceBus.Unicast.UnicastBus”的属性“SubscriptionStorage”。

任何帮助表示赞赏

So I am building publisher and following is my config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="DBSubscriptionStorageConfig" type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
</configSections>


<!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
   2. Input queue must be on the same machine as the process feeding off of it.
   3. Error queue can (and often should) be on a different machine.
   4. The community edition doesn't support more than one worker thread.
-->

<MsmqTransportConfig
InputQueue="HomeOfficePublisherQueue"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>

<DBSubscriptionStorageConfig>
<NHibernateProperties>
  <add Key="connection.provider"
       Value="NHibernate.Connection.DriverConnectionProvider"/>
  <add Key="connection.driver_class"
       Value="NHibernate.Driver.SqlClientDriver"/>
  <add Key="connection.connection_string"
       Value="Server=<dbserver>;initial catalog=NServiceBus;Integrated Security=SSPI"/>
  <add Key="dialect"
       Value="NHibernate.Dialect.MsSql2005Dialect"/>
 </NHibernateProperties>
</DBSubscriptionStorageConfig>


<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress=""
ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
</MessageEndpointMappings>
</UnicastBusConfig>


</configuration>

and here is my endpoint

class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .UnicastBus()
            .ImpersonateSender(false)
            .MsmqTransport()
            .IsTransactional(true)
            .DBSubcriptionStorage();
    }
}

}

I get following exception

Exception when starting endpoint, error has been logged. Reason: Error creating object with name 'NServiceBus.Unicast.UnicastBus' : Unsatisfied dependency expressed through object property 'SubscriptionStorage': There are 2 objects of Type [NServiceBus.Unicast.Subscriptions.ISubscriptionStorage] for autowire by type, when there should have been just 1 to be able to autowire property 'SubscriptionStorage' of object 'NServiceBus.Unicast.UnicastBus'.

Any help is appreciated

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

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

发布评论

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

评论(2

著墨染雨君画夕 2024-10-23 15:22:26

我刚刚遇到了同样的问题,并通过在配置末尾调用 .CreateBus() 解决了它:

class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .UnicastBus()
            .ImpersonateSender(false)
            .MsmqTransport()
            .IsTransactional(true)
            .DBSubcriptionStorage()
            .CreateBus();
    }
}

I just had the same problem, and solved it by calling .CreateBus() at the end of the configuration:

class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .UnicastBus()
            .ImpersonateSender(false)
            .MsmqTransport()
            .IsTransactional(true)
            .DBSubcriptionStorage()
            .CreateBus();
    }
}
誰認得朕 2024-10-23 15:22:26

仅当角色的设置符合您的要求时才使用这些角色。尝试删除 As_aPublisher 并查看是否适合您。在您的情况下,角色和您自己的代码都会注册一个 sub.storeage,这就是给您带来例外的原因。

Only use the roles if their settings are what you want. Try to remove As_aPublisher and see if that does it for you. In your case both the role and your own code will register a sub.storeage and that is what gives you the exception.

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