Hi, I have a Windows service (.Net FW 4.7.2) in which I’m using Nservicebus 7.2.0 and I have setup MS extensions DI.
I’d like to use the existing DI container, where I have a Singleton service configured. I want this service to be injected in one of my Handlers (so my Handler will call one of its methods and pass the new incoming message).
I was able to configure DI on my endpoint using a new container, so my Handler was injected with a new instance of my service:
var containerSettings = endpointConfiguration.UseContainer(new DefaultServiceProviderFactory());
containerSettings.ServiceCollection.AddSingleton();
Alternatively - is there another way to pass the incoming message object from my Handler to my service (which is Injected as Singleton, NOT static).
Thanks,
MK
The standard integration of DI sample did not refer to using an existing container. However I was able to resolve this by configuring DI for the endpoint and injecting an instance of a service provided by app’s main container to the new NSB container. Then
I was able to consume this service in my handler and use it there, leaving the handler slim.