Questions around NServiceBus.CastleWindsor package and service lifetimes

Hello,

We are currently using Castle Windsor along with the corresponding NServiceBus.CastleWindsor adapter package. I have a couple of questions as shown below:

  1. Do i need to “create a scope” or “child container” for each message somewhere in the nservicebus pipeline in order to ensure that all the handlers injected dependencies get released or does nservicebus do this automatically for me?

  2. If i register classes directly with castle windsor ( as scoped ) and then pass the container to nservicebus will these behave the same as if i used the nservicebus container provided interface? For example will both of the registrations below behave the same from a lifetime/lifecycle perspective?

var container = new WindsorContainer();
var registration = Component.For<MyUnitOfWork>()
                         .ImplementedBy<MyUnitOfWork>()
                         .LifestyleScoped();
container.Register(registration);
endpointConfiguration.UseContainer<WindsorBuilder>(
    customizations: customizations =>
    {
        customizations.ExistingContainer(container);
    });
endpointConfiguration.RegisterComponents(
    registration: components =>
    {
        components.ConfigureComponent<MyUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork);
    });

NServiceBus handled the child containers for you

Yes

You should only register that once in your Castle Windsor configuration

Thanks for responding @ramonsmits.

If i register a singleton will this be newed up on every message recieved and live for the lifetime on the child container or will it live for the duration of the application?

Also, do all containers work this same way with nservicebus?