question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MassTransit & Autofac Docs Seem Wrong (or I'm stupid!)

See original GitHub issue

Is 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

  1. Operating system: Win 10
  2. Visual Studio version: 2019 16.4.5
  3. 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

image

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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
matt-lethargiccommented, Feb 22, 2020

I think there was just a couple of things

  • The Autofac Example on your site using modules has methods such as 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 while
  • AddMassTransit is the way to go, don’t try yourself!
  • Only Autofac mentions Saga Repositories, I’m going to have to figure out Simple Injector and Microsoft IoC myself
  • One thing that could be useful. I’m building lots of microservices and they all need to send events for state transfer, keeping remote data updated from the source of truth. It would be great to have some sort of reference example for how this would work or could be setup. I’m sure this is a common thing these days. Excuse me if this is explained, I’ve only read about half the docs

Think that was it really. Otherwise thanks for MassTransit 😃

1reaction
phatboygcommented, Feb 21, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found