-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
The current implementation of injecting HttpRequestMessage relies on updating the component registry
internal static void UpdateScopeWithHttpRequestMessage(HttpRequestMessage request)
{
var scope = request.GetDependencyScope();
var requestScope = scope.GetRequestLifetimeScope();
if (requestScope == null) return;
var registry = requestScope.ComponentRegistry;
var builder = new ContainerBuilder();
builder.Register(c => request).InstancePerRequest();
builder.Update(registry);
}However this defeats the best practices in the documentation: the container should be considered immutable.
Also ContainerBuilder.Update is marked as obsolete in this commit autofac/Autofac@8a89e94
Should another approach be considered? Like the one Simple Injector is using, by capturing the HttpRequestMessage in a provider:
https://github.com/simpleinjector/SimpleInjector/blob/master/src/SimpleInjector.Integration.WebApi/SimpleInjectorWebApiExtensions.cs
I will be happy to help with a pull request if needed.
Metadata
Metadata
Assignees
Labels
No labels