I'm trying to setup MassTransit with Autofac (latest NuGet packages) but it seems that consumers cannot be registered at the ContainerBuilder
level.
Has anyone managed to use MassTransit with Autofac, especially with modules?
In the sample below, the DoSomethingConsumer cannot be resolved, unless I uncomment the x.AddConsumer
line and comment the registration on the builder.
builder.RegisterType<BusControlHostedService>().As<IHostedService>();
builder.RegisterType<DoSomethingConsumer>().AsSelf().AsImplementedInterfaces();
builder.AddMassTransit(x =>
{
//x.AddConsumer<DoSomethingConsumer>();
x.AddBus(componentContext => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("host", "vhost", h =>
{
h.Username("user");
h.Password("password");
});
cfg.UseExtensionsLogging(componentContext.Resolve<ILoggerFactory>());
cfg.ConfigureEndpoints(componentContext);
}));
x.AddRequestClient<DoSomethingRequest>();
});
The documentation at https://masstransit-project.com/MassTransit/usage/containers/autofac.html seems to be wrong. There is no .AddConsumer
extension method on the builder.
I'm looking to register consumers from modules and be able to configure endpoints by convention (as in the sample above) or using .RegisterEndpoint
.
Any help on this would be greatly appreciated.
builder
) but inside the configuration action for MassTransit, which is not what I need. If you look at the masstransit-project.com/MassTransit/usage/containers/… documentation, it shows how to do this via modules, which is what I need, but that documentation is either wrong or out of date since the methods used do not exist. Also seems there is some Ninject or Structuremap config in there too. – Lottibuilder.RegisterType<T>()
, then you could ask the container for all types which implementIConsumer
and add them to the registration in theAddMassTransit
section, similar to how they're added by namespace. – Malonylurea