Custom container, keep LightInject for internal use

I have a custom IOC container, with a very narrow interface

IDisposible BeginScope();
object GetInstance(Type);

In this all dependencies a IMessageHandler would need is registered. If needed I could register all IMessageHandlers as well. The container is locked and cannot be changed.

How do I configure NServicebus so it uses LightInject for internal needs, and use my API for resolving and executing MessageHandlers?

Like this

using (container.BeginScope())
    var messageHandler = container.getInstance(type)

Hi @Stig_Christensen

Did you find our documentation on how to plugin custom containers?

Yes I have read it.

But if I define my own IContainer, NServicebus will use it for internal dependencies as well, right? My container is locked and cannot be configured at this time.

Could you provide some more context on what it is you’re trying to achieve from a functional perspective? What is it you’re trying to achieve, that you can’t use a regular IoC and use that with NServiceBus? Maybe we can figure out what is a good solution that you can use?

Hi Dennis. I am enabling NServicebus in monolith with a custom IoC container. I have access to the container but it is already configured and locked. I would like NServicebus to scan for handlers on its own, but use our container to resolve business dependencies in the MessageHandlers (constructor injection)

Steven is given it a try here, but the code seems a little to much of a hack in my opinion.

@Stig_Christensen I don’t have much information to go on. Perhaps there are other ways to enable SimpleInjector with NServiceBus. But I’ll take your word for it that you can’t.

The solution that Steven provides seems like a valid solution. It’s not the most ideal solution, but his version or a modified version would at least work.

The person Steven worked with on this thing is Kijana, an NServiceBus champ. Together they have a lot of knowledge on the subject, I would try and see if you can make that work for you.