首页 > 解决方案 > 将 MassTransit 与 StructureMap 注册表类一起使用

问题描述

我在大型代码库中使用 MassTransit (5.5.5) 和 StructureMap (4.7),使用 Registry 类来组织我的依赖项,遵循此处概述的内容:

class BusRegistry : Registry
{
    public BusRegistry()
    {
        For<IBusControl>(new SingletonLifecycle())
            .Use(context => Bus.Factory.CreateUsingInMemory(x =>
            {
                x.ReceiveEndpoint("customer_update_queue", e => e.LoadFrom(context));
            }));
        Forward<IBusControl, IBus>();
    }
}

// Snip...

public void CreateContainer()
{
    _container = new Container(x => {
        x.AddRegistry(new BusRegistry());
    });
}

但是,在调用 ReceiveEndpoint 时使用的 LoadFrom 扩展方法已被弃用。那么目前应该如何将 MassTransit 与 StructureMap Registry 类一起使用呢?

标签: structuremapmasstransit

解决方案


可能不会有一个好的答案,因为 StructureMap 即将退出。我最终没有使用 StructureMap 进行消费者配置:

class BusRegistry : Registry
{
    public BusRegistry()
    {
        For<IBusControl>(new SingletonLifecycle())
            .Use(context => Bus.Factory.CreateUsingInMemory(x =>
            {
                x.ReceiveEndpoint("customer_update_queue", endpointCfg => {
                    endpointCfg.Consumer<FirstSubscriber>(
                        GetFirstSubscriberFactoryMethod()
                    );
                    endpointCfg.Consumer<SecondSubscriber>(
                        GetSecondSubscriberFactoryMethod()
                    );
                    // etc...
                });
            }));
        Forward<IBusControl, IBus>();
    }
}

...虽然我使用 StructureMap 将依赖项注入消费者。


推荐阅读