问题
I am using ninject when configuring NSB. Here is how I register:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
#region Implementation of IWantCustomInitialization
public void Init()
{
var kernel = new StandardKernel();
Configure.With().NinjectBuilder(kernel);
kernel.Load(new BackendModule());
}
#endregion
}
public class BackendModule : NinjectModule
{
#region Overrides of NinjectModule
/// <summary>
/// Loads the module into the kernel.
/// </summary>
public override void Load()
{
Bind<IEventBus>().To<NsbBus>();
Bind<IRecordStorageConfig>().To<RegistrationEventStorageConfig>();
Bind<IRecordStorage>().To<RegistrationRecordStorage>();
Bind<IRecordStorageFactory>().To<RegistrationRecordStorageFactory>();
Bind<IAggregateRootFactory>().To<RegistrationFactory>();
}
#endregion
}
I need the IAggregateRootFactory in the saga.
public class RegistrationSaga : Saga<RegistrationSagaData>,
IAmStartedByMessages<StartRegistration>,
IHandleMessages<CreateRegistration>,
IHandleMessages<ValidateRegistration>,
IHandleMessages<CancelRegistration>
{
public RegistrationFactory Factory { get; set; }
// removed implementation
}
The saga is started successfully and the commands are handlers are invoked. But the IAggregateRootFactory property injection is not working. The Factory is always null. Am I wiring this wrong?
回答1:
I'm not quite sure why your saga needs to have RegistrationFactory/IAggregateRootFactory in it, but it probably isn't a good idea.
来源:https://stackoverflow.com/questions/10158739/nservicebus-saga-property-injection-with-ninject