3
我想使用NServiceBus配置文件来覆盖Spring.net依赖注入中使用的具体类以用于Integration Testing。覆盖NServiceBus中的依赖关系
在我EndpointConfig
类,我有一个构件构造:
NServiceBus.Configure.Instance.Configurer.ConfigureComponent<RealCommunicator>(ComponentCallModelEnum.None);
(该位是OK!)
我创建了一个新的配置文件:
public class StubThirdPartyProfile : NServiceBus.IProfile
{
}
以及行为类实施它:
public class StubThirdPartyBehaviour : IHandleProfile<StubThirdPartyProfile>
{
public void ProfileActivated()
{
Configure.Instance.Configurer.ConfigureComponent<StubCommunicator>(ComponentCallModelEnum.None);
}
}
StubCommunicator
和RealCommunicator
实现相同的接口,我希望该配置文件将删除旧的依赖关系,并使用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);
谢谢乌迪,这就是我最终做的。干杯 – user987506