Configuring an endpoint to use Unity
var endpointConfiguration = new EndpointConfiguration("Samples.Unity");
var container = new UnityContainer();
container.RegisterInstance(new MyService());
endpointConfiguration.UseContainer<IUnityContainer>(new ServiceProviderFactory(container));
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;
}
}