我想使用 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);
}
}
StubCommunicator
和 RealCommunicator
都实现了相同的接口(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/