将 MassTransit 与 StructureMap Registry 结合使用 类
Using MassTransit with StructureMap Registry classes
我在一个大型代码库中使用 MassTransit (5.5.5) 和 StructureMap (4.7),使用 Registry 类 来保持我的依赖项有条理,遵循概述 here:
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 类 结合使用?
可能不会有好的答案,因为 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 将依赖项注入消费者。
我在一个大型代码库中使用 MassTransit (5.5.5) 和 StructureMap (4.7),使用 Registry 类 来保持我的依赖项有条理,遵循概述 here:
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 类 结合使用?
可能不会有好的答案,因为 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 将依赖项注入消费者。