R
R
Ruslan2020-01-21 05:37:21
.NET
Ruslan, 2020-01-21 05:37:21

How to connect the MassTransit bus with all consumers from Microsoft Dependency Injection?

Hello.
Situation:
There are many classes that implement the IConsumer<any type> interface.
These classes are registered in the DI container (Unity and MS DI, the one in the .net core)
When using Unity, when configuring message listening, it is enough to call the LoadFrom method on IReceiveEndpointConfigurator and specify the DI container in the parameter, and the bus will start creating classes for processing through it incoming connections. this is described in the documentation: https://masstransit-project.com/usage/containers/u... (line ec.LoadFrom(container);)
But when using .net core and its DI, the situation changes fundamentally (according to the documentation https ://masstransit-project.com/usage/containers/m...
Now, for some reason, you need to repeatedly specify each class that implements IConsumer
(In the documentation, these are the lines: x.AddConsumer(); and e.ConfigureConsumer(provider); and SubmitOrder is added for some reason)
and there is a nuget package MassTransit.Extensions.DependencyInjection , which adds the LoadFrom extension (intuitive for the same scenario as in Unity), but for some reason does not work (for me).
Another worrying circumstance: the LoadFrom method is marked with the [Obsolete] attribute - deprecated. It is not clear why and what the developers propose to use instead.
well, the question itself: how to implement a scenario when MassTransit independently creates instances of classes that process incoming messages through DI?
Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question