Closed GoogleCodeExporter closed 8 years ago
I'm curious if AutofacDependencyResolver.Current is valuable as a static.
Should it be an extension on IDependencyResolver?
DependencyResolver.Current.AutofacResolver() or something, so the request
lifetime scope can be created first.
Alternatively... should a "base" lifetime scope be inserted between the
container and the request lifetime scope? For example, you create the resolver
and it does something like:
public AutofacDependencyResolver(IContainer container)
{
this._rootLifetimeScope = container.BeginLifetimeScope(b => b.RegisterInstance(this).AsSelf());
}
and the request scope is from the root lifetime:
public ILifetimeScope GetLifetimeScope()
{
return this._rootLifetimeScope.BeginLifetimeScope("AutofacWebRequest");
}
Of course, that would throw a wrench in the works for folks resolving things
right out of the container and expecting sharing between non-request lifetime
stuff in the resolver and resolutions right out of the container. That could be
a breaking change for a few edge cases.
Original comment by travis.illig
on 7 Jan 2013 at 9:16
(I'll fix it if it gets assigned to me but I need another set of eyes on it
first.)
Original comment by travis.illig
on 7 Jan 2013 at 9:17
Any on-the-fly registration should also be As<AutofacDependencyResolver>()
rather than AsSelf() so folks can derive/override and still have proper
behavior.
Original comment by travis.illig
on 7 Jan 2013 at 9:48
My bad. I found the problem and it all boiled down to the AsSelf vs
As<AutofacDependencyResolver> registration. It should have occurred to me that
AutofacDependencyResolver.Current calling DR.Current.GetService would
automatically instantiate the request lifetime scope.
Technically this still means you can only get the current ADR in a request
lifetime, but changing the registration type will fix the issue for me. I'll
commit the fix shortly. Sorry for the panic mode. :)
Original comment by travis.illig
on 7 Jan 2013 at 10:03
Pushed, including unit tests.
Original comment by travis.illig
on 7 Jan 2013 at 10:22
Original issue reported on code.google.com by
travis.illig
on 7 Jan 2013 at 9:05