问题
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