How do I use AutofacWebTypesModule to Resolve HttpServerUtilityBase
I have the following registrations
builder.RegisterModule(new AutofacWebTypesModule());
builder.Register<MyType>(ctx =>
{
var server = ctx.Resolve<HttpServerUtilityBase>();
...
});
When I try to resolve MyType via a constructor on an Controller, I get the following exception. What am I doing wrong?
Autofac.Core.DependencyResolutionException was unhandled by user code
Message=No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+<>c__DisplayClass0[System.Web.HttpServerUtilityBase,Autofac.Builder.SimpleActivatorData,Autofac.Builder.SingleRegistrationStyle]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which 开发者_Python百科the instance was requested.
Yikes - that error message has gone all wrong :)
The problem is most likely that you're trying to resolve MyType
directly from the container (as opposed to the DependencyResolver
or else you're taking a dependency on it from a singleton. The HttpServerUtilityBase
component can only be used in the context of a web request.
Trying to resolve it from Applicaiton_Start
will also fail in IIS7 integrated pipeline mode.
HTH! Nick
精彩评论