I'm using NServiceBus 5's default dependency injection features. I want to register a singleton that depends on IBus in the endpoint config.
Ex:
configuration.RegisterComponents(r =>
{
r.RegisterSingleton(new MyDependency(resolveIBus()));
...
}
How can I resolve the instance of IBus in the above pseduo code using NServiceBus's out-of-the-box dependency injection?
The correct syntax would be:
The dependency mechanism will investigate the constructor(s) of the MyDependency type and chooses the simplest one it can completely resolve. So, you'll need to create your
MyDependencytype like this:More information in the NServiceBus Documentation
If you only know what type of service you need at runtime, you can use the
IServiceProviderservice like this: