gpt4 book ai didi

c# - 覆盖 NServiceBus 中的依赖项

转载 作者:行者123 更新时间:2023-11-30 17:15:52 24 4
gpt4 key购买 nike

我想使用 NServiceBus 配置文件覆盖 Spring.net 依赖注入(inject)中使用的具体类,以便在集成测试中使用。

在我的 EndpointConfig 类中,我有一个正在配置的组件:

NServiceBus.Configure.Instance.Configurer.ConfigureComponent<RealCommunicator>(ComponentCallModelEnum.None);

(这一点没问题!)

我创建了一个新的配置文件:

public class StubThirdPartyProfile : NServiceBus.IProfile
{
}

还有一个行为类来实现它:

public class StubThirdPartyBehaviour : IHandleProfile<StubThirdPartyProfile>
{
public void ProfileActivated()
{
Configure.Instance.Configurer.ConfigureComponent<StubCommunicator>(ComponentCallModelEnum.None);
}
}

StubCommunicatorRealCommunicator 都实现了相同的接口(interface),我希望配置文件会删除旧的依赖项并改用 StubCommunicator 但是不是这种情况。有办法做到这一点吗?

运行解决方案时,出现以下错误:

Spring.Objects.Factory.UnsatisfiedDependencyException: 
Error creating object with name 'Namespace.CommandHandler' :
Unsatisfied dependency expressed through object property 'Communicator':
There are 2 objects of Type [Namespace.ICommunicator] for autowire by type,
when there should have been just 1 to be able to autowire property 'Communicator' of object

我们在 NServicebus 中使用 Spring.net 框架,配置如下:

Configure.With().SpringFrameworkBuilder()
.XmlSerializer().Log4Net()
.MsmqTransport()
.IsTransactional(true);

最佳答案

与其在端点配置类中配置实际组件,不如考虑将其注册到处理其他 NServiceBus 配置文件(精简版、集成、生产)的类中。

关于c# - 覆盖 NServiceBus 中的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7711643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com