使用ninject进行nservicebus saga属性注入 [英] nservicebus saga property injection with ninject

查看:77
本文介绍了使用ninject进行nservicebus saga属性注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在配置NSB时,我正在使用ninject.这是我的注册方式:

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
}

我需要传奇中的IAggregateRootFactory.

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
}

传奇成功启动,并且调用了处理程序的命令.但是IAggregateRootFactory属性注入无法正常工作.工厂始终为空.我接线错了吗?

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?

推荐答案

我不太确定为什么您的传奇人物需要在其中添加RegistrationFactory/IAggregateRootFactory,但这可能不是一个好主意.

I'm not quite sure why your saga needs to have RegistrationFactory/IAggregateRootFactory in it, but it probably isn't a good idea.

这篇关于使用ninject进行nservicebus saga属性注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆