Spring Dependency Injection Usage

Component: Spring Dependency Injection
NuGet Package NServiceBus.Spring (8-pre)
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.

Configuring an endpoint to use Spring

var endpointConfiguration = new EndpointConfiguration("Samples.Spring");
var applicationContext = new GenericApplicationContext();
    .RegisterSingleton("MyService", new MyService());
    customizations: customizations =>

Injecting the dependency in the handler

public class MyHandler :
    MyService myService;

    public MyHandler(MyService myService)
        this.myService = myService;

    public Task Handle(MyMessage message, IMessageHandlerContext context)
        return Task.CompletedTask;

Related Articles

  • Dependency Injection
    NServiceBus automatically registers components, handlers, and sagas.
  • Spring
    Details on how to Configure NServiceBus to use Spring for dependency injection. Includes usage examples as well as lifecycle mappings.

Last modified