MassTransit & Autofac Docs Seem Wrong (or I'm stupid!)
See original GitHub issueIs this a bug report?
Maybe?! Documentation doesn’t match what I’m seeing
MassTransit 6.1.0 Autofac 5.1.2 MassTransit.Autofac 6.1.0 MassTransit.Azure.ServiceBus.Core 6.1.0
I’m trying to get Autofac registration working using a module as in Official Docs but I get an error cannot resolve symbol for line cfg.AddConsumersFromContainer(context)
. I also looked at the sample apps on Github and tried using cfg.AddConsumersFromContainer()
but it takes in a context
and Idon’t know where to get that context from!
Can you also reproduce the problem with the latest version?
Yes
Environment
- Operating system: Win 10
- Visual Studio version: 2019 16.4.5
- Dotnet version: netcoreapp2.2 & netstandard2.0
Steps to Reproduce
First way:
public class MyBusModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(context =>
{
var busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
{
cfg.Host("connectionString");
cfg.AddConsumersFromContainer(context); <----- Cannot find this method
cfg.ReceiveEndpoint("queueName", ec =>
{
ec.ConfigureConsumers(context);
});
});
})
.SingleInstance()
.As<IBusControl>()
.As<IBus>();
}
}
Second way:
public class MyBusModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.AddMassTransit(cfg =>
{
cfg.AddConsumersFromNamespaceContaining<SubmitOrderConsumer>();
cfg.AddConsumersFromContainer( <WHAT GOES IN HERE > );
});
}
}
Expected Behavior
Compile!!
Really though, was expecting either the method AddConsumersFromContainer
to be found or some documentation showing where to get the context from in my second way
Actual Behavior
Reproducible Demo
{
protected override void Load(ContainerBuilder builder)
{
builder.AddMassTransit(cfg =>
{
cfg.AddConsumersFromContainer();
});
builder.Register(context =>
{
var busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
{
cfg.Host("connectionString");
cfg.AddConsumersFromContainer(context);
cfg.ReceiveEndpoint("queueName", ec =>
{
ec.ConfigureConsumers(context);
});
});
})
.SingleInstance()
.As<IBusControl>()
.As<IBus>();
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Register an IConsumer<T> with dependency in Masstransit ...
I've followed Masstransit documentation but I can't get this to work. What am I doing wrong? Framework versions: .Net Framework 4.6.1; Autofac: ...
Read more >Re: MassTransit ServiceBusFactory.New() hangs running ...
However, I am having an issue getting ServiceBusFactory.New()to complete when being hosted as a Windows Service. A bit of detail. We are using...
Read more >Newest 'masstransit' Questions - Page 28
I use RabbitMQ with C#, MassTransit, Autofac. ... I'm using MassTransit to create this client, and my code looks this way: static ...
Read more >MassTransit Documentation - Read the Docs
MassTransit Documentation - Read the Docs. ... The biggest difficulty seems to be just<br /> ... 2.6.3 AutoFac<br />.
Read more >Microservices Architecture for Containerized NET Applications
microservices for complex queries, it might be a symptom of a bad design -a microservice should be as isolated as possible from other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think there was just a couple of things
cfg.AddConsumersFromContainer(context);
just doesn’t exist and by what you’ve said above is best left alone!x.AddConsumer<>
&x.AddConsumers
actually registers the consumers with the container, I didn’t get this for a whileAddMassTransit
is the way to go, don’t try yourself!Think that was it really. Otherwise thanks for MassTransit 😃
So, I kind of feel like you’re off in left field, and I’m not sure how you got there.
The very first example for Autofac works perfectly.
https://masstransit-project.com/usage/containers/autofac.html#using-nested-container
But to be clear, you only need to add your consumers one way, within the AddMassTransit call. And you only need to call one of the (ConfigureConsumer) methods, or just call COnfigureEndpoints and conventions are used to name the queues.
I’m not sure about the Module usage, because, honestly, that’s something I haven’t used in probably 5-7 years. I get the value, but I’m not sure how it works.