2011-10-10 115 views
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); 
    } 
} 

StubCommunicatorRealCommunicator實現相同的接口,我希望該配置文件將刪除舊的依賴關係,並使用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); 

回答

2

代替配置實際組件,請考慮在處理其他NServiceBus配置文件的類中進行註冊 - Lite,Integration,Production。

+0

謝謝烏迪,這就是我最終做的。乾杯 – user987506