# Externally Managed Mode > [!WARNING] > In NServiceBus version 10.2.0 and above, externally managed mode is no longer a relevant concept, as integration with the Microsoft .NET Host is integrated directly into NServiceBus. > > See the documentation on [hosting with Microsoft.Extensions.Hosting](/nservicebus/hosting/core-hosting.md) or the [NServiceBus version 10 to 11 upgrade guide](/nservicebus/upgrades/10to11/index.md) for more information. ### Configuring the endpoint This sample configures an endpoint to use [externally managed mode](/nservicebus/dependency-injection/index.md#modes-of-operation-externally-managed-mode) with [Microsoft's dependency injection container](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection) and registers some dependencies. ```cs // ServiceCollection is provided by Microsoft.Extensions.DependencyInjection var serviceCollection = new ServiceCollection(); // most dependencies may now be registered serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); // EndpointWithExternallyManagedContainer.Create accepts an IServiceCollection, // which is inherited by ServiceCollection var endpointWithExternallyManagedContainer = EndpointWithExternallyManagedContainer .Create(endpointConfiguration, serviceCollection); // if IMessageSession is required as dependency, it may now be registered serviceCollection.AddSingleton(p => endpointWithExternallyManagedContainer.MessageSession.Value); ``` ### Injecting dependencies into handlers Registered dependencies may be injected into message handlers using constructor injection: ```cs public class MyHandler(Greeter greeter) : IHandleMessages { public Task Handle(MyMessage message, IMessageHandlerContext context) { greeter.SayHello(); return Task.CompletedTask; } } ``` ### Injecting the message session into other types When `IMessageSession` has been registered as shown above, it may be injected into other types using constructor injection: ```cs public class MessageSender(IMessageSession messageSession) { public Task SendMessage() { var myMessage = new MyMessage(); return messageSession.SendLocal(myMessage); } } ``` > [!NOTE] > An `IMessageSession` may only be injected by the container _after the endpoint has been started_.