Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce generics to avoid the need for multiple DI containers #104

Open
moanrose opened this issue Oct 19, 2020 · 1 comment
Open

Introduce generics to avoid the need for multiple DI containers #104

moanrose opened this issue Oct 19, 2020 · 1 comment

Comments

@moanrose
Copy link

moanrose commented Oct 19, 2020

Having spend a few days getting acquainted with your approach to multiple endpoint hosting, I would like to make a suggestion:

Introduce generics to avoid the need for multiple DI containers:

If you constructed an interface representing an "Endpoint-Context"

IEndpointContext { Func<HostBuilderContext, EndpointConfiguration> endpointConfigurationBuilder; }
And register the "Endpoint-Context" like this

.UseNServicebusContext<T>(this IServiceCollection serviceCollection, Func<HostBuilderContext, T> nservicebusContextBuilder) : where T : IEndpointContext

You could then use the implementing type as a discriminator on your existing DI registrations, and as search criteria for the AssemblyScanner:

IMessageSession<MyEndpointContext> IHandleMessages<MyEndpointContext> IHostedService<MyEndpointContext>

This would in my opinion be a far more elegant solution than the "two containers" approach.

This would also eliminate the need for the assembly scanner exclude list.

@danielmarbach
Copy link
Contributor

Morten thanks for your feedback and brainstorming solutions.

The problem and solution you are describing is mostly relevant for people that need to share a common container between the multiple instances. Can you elaborate a bit more on your needs why you need to share a container and thus instances managed by that container? What kind of scenario are you solving?

FYI I've spiked the approach to share a container here

Particular/docs.particular.net#4813

Here is the summary of why we are currently not pursuing multi-hosting as part of this package

#27 (comment)

That being said keep the feedback coming because we want to understand the scenarios and needs of our customers better so that we can create better guidance and potentially even more integration libraries where necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants