nservicebus saga property injection with ninject

孤人 提交于 2019-12-12 03:12:29

问题


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

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