I am working on a .NET 8 application that involves setting up NServiceBus. In our setup, we need to pass an instance of EndpointConfiguration
to the builder.UseNServiceBus
method. We have a class that returns this EndpointConfiguration
instance, but it depends on several other classes, each handling specific functionalities such as:
- RMQ client connection authentication
- Reading configuration settings specific to the endpoint from
appsettings.json
- Logic to resolve a connection string for a multi-tenant messaging service
To inject all necessary dependencies into the class responsible for creating the ‘EndpointConfiguration’ instance, I need to resolve the service provider once before calling UseNServiceBus(EndpointConfiguration)
. This results in two separate service providers.
I am curious to know how other teams are handling this scenario in .NET 8. Specifically, what are the best practices for setting up and configuring EndpointConfiguration
with multiple dependencies without ending up with multiple service providers? Any insights or examples would be greatly appreciated.
Thank you!