How do I resolve an autowire conflict with NHibernateSagaPersister?

不羁的心 提交于 2020-01-03 02:08:11

问题


I'm trying to wire up my first Saga, and have been unable to get the receiving endpoint to handle start message properly. I get the following exception:

SagaMessageHandler Failed handling message. Spring.Objects.Factory.UnsatisfiedDependencyException: Error creating object with name 'NServiceBus.Sagas.Impl.SagaMessageHandler' : Unsatisfied dependency expressed through object property 'Persister': There are 2 objects of Type [NServiceBus.Saga.ISagaPersister] for autowire by type, when there should have been just 1 to be able to autowire property 'Persister' of object 'NServiceBus.Sagas.Impl.SagaMessageHandler'.

I'm guessing that both the in-memory persister and NHibernateSagaPersister are conflicting, but I can't figure out how to resolve this. My configuration is this:

public class SubscriberEndpointConfig : IWantCustomInitialization, IConfigureThisEndpoint
{      
    public void Init()
    {
        _logger.Info("Subscriber is initializing..");

        Configure.With()                 
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport().IsTransactional(true).IsolationLevel(IsolationLevel.ReadCommitted).PurgeOnStartup(false)
            .UnicastBus().LoadMessageHandlers(First<GridInterceptingMessageHandler>.Then<SagaMessageHandler>())  
            .Sagas()
            .NHibernateSagaPersister()
            .Log4Net();

    }
}

If I remove the LoadMessageHandlers(), the error disappears but of course my handler is never invoked. Any ideas what's wrong here? The saga works properly when I am using AsA_Server in the production profile, without the custom initialization, but I need to use that for other reasons.


回答1:


The nservicebus profiles are configuring the persister for you(http://www.nservicebus.com/Profiles.aspx)

NServiceBus.Lite (default) = InMemory

NServiceBus.Integration = NHibernate + Sqlite

NServiceBus.Production = NHibernate

So in your case you can remove the call to NHibernateSagaPersister() and let the profiles do it's work.



来源:https://stackoverflow.com/questions/6629726/how-do-i-resolve-an-autowire-conflict-with-nhibernatesagapersister

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!