I have a custom DelegatingHandler
in a class library that I need to register with Autofac
. The webapi host resolves it's dependencies on runtime, so the host has no references to this library.
public class LocalizationHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken )
{}
}
On my Autofac initializer class I've tried things like:
protected override void Load( ContainerBuilder builder )
{
builder.RegisterType<LocalizationHandler>();
builder.Register(c => new LocalizationHandler());
}
The normal way to register such handlers within the host would be:
public static void Register(HttpConfiguration httpConfiguration)
{
httpConfiguration.MapHttpAttributeRoutes();
httpConfiguration.MessageHandlers.Add(new LocalizationHandler());
}
But I don't have access to the host project here. Any ideas how to inject the handler over the ContainerBuilder
?
Here is my solution for a late binding:
Global.asax
Helper
Library