Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Windsor Dependency Injection Usage

Configuring an endpoint to use Windsor

var endpointConfiguration = new EndpointConfiguration("Samples.Castle");

var containerSettings = endpointConfiguration.UseContainer(new WindsorServiceProviderFactory());

containerSettings.ConfigureContainer(c => c.Register(Component.For<MyService>()
    .Instance(new MyService())));

Injecting the dependency in the handler

public class MyHandler :
    IHandleMessages<MyMessage>
{
    MyService myService;

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

    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        myService.WriteHello();
        return Task.CompletedTask;
    }
}

Related Articles

  • Castle Windsor
    Details on how to Configure NServiceBus to use Castle Windsor for dependency injection.
  • Dependency Injection
    NServiceBus automatically registers components, handlers, and sagas.