Hi @gl0206
If you need IMessageSession
to be registered in the DI container, you have to register it yourself which might be a bit tricky as the registration of the session needs to happen at configuration time, while the actual instance of the session is only available once the endpoint is started. This can be achieved by something like this:
IMessageSession messageSession = null;
endpointConfiguration
.RegisterComponents(c => c
.ConfigureComponent<IMessageSession>(() => messageSession, DependencyLifecycle.InstancePerCall));
var endpointInstance = await Endpoint.Start(endpointConfiguration);
messageSession = endpointInstance;
// IMessageSession can be injected at this point
instead of the endpointConfiguration.RegisterComponents
API you can also use the Ninject API directly if you are using an external Ninject container.
For migration purposes, I’d also recommend you to look into our UniformSession helper package: https://docs.particular.net/nservicebus/messaging/uniformsession
Please also note that Ninject won’t be supported in upcoming major versions of NServiceBus as Ninject does not support the Microsoft.Extensions.DependencyInjection.Abstractions
model.
Does that help?