StructureMap Dependency Injection Usage

Component: StructureMap Dependency Injection
NuGet Package NServiceBus.StructureMap (6.x)
Target NServiceBus Version: 6.x
Standard support for version 6.x of NServiceBus has expired. For more information see our Support Policy.

Configuring an endpoint to use StructureMap

var endpointConfiguration = new EndpointConfiguration("Samples.StructureMap");
var container = new Container(
    action: expression =>
            .Use(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.
  • StructureMap
    Details on how to Configure NServiceBus to use StructureMap for dependency injection.

Last modified