title: Resolving HttpRequestScoped services in ASMX with Autofac 2.1.12
body: <p><strong>The Description</strong> I had a legacy type that is <code>HttpRequestScoped</code> and a legacy web service consuming that service. To resolve services in legacy concerns, I have a global resolver. This was all working well in 1.4, and now that I'm using 2.1.12 I'm experiencing <code>DependencyResolutionException</code>.</p>
  
  <p><strong>The Code</strong> In 2.1.12, my Global.asax.cs:</p>
  
  <pre><code>builder.Register(c =&gt; new SomeLegacyType(HttpContext.Current)) // note: it relies on HttpContext.Current
  .As&lt;SomeLegacyType&gt;()
  .HttpRequestScoped();
  
  _containerProvider = new ContainerProvider(builder.Build()); // this is my app's IContainerProvider
  Setup.Resolver = new AutofacResolver(_containerProvider.ApplicationContainer);
  </code></pre>
  
  <p>Setup.Resolver is a singleton, and it is being set to AutofacResolver which looks something like this:</p>
  
  <pre><code>public class AutofacResolver : IResolver
  {
      private readonly IContainer _container;
  
      public AutofacResolver(IContainer container)
      {
          _container = container;
      }
  
      public TService Get&lt;TService&gt;()
      {
          return _container.Resolve&lt;TService&gt;();
      }
  }
  </code></pre>
  
  <p>The web service looks like this:</p>
  
  <pre><code>[WebService]
  public LegacyWebService : WebService
  {
     [WebMethod(EnableSession=true)]
     public String SomeMethod() 
     {
        var legacyType = Setup.Resolver.Get&lt;SomeLegacyType&gt;();
     }
  }
  </code></pre>
  
  <p><strong>The Exception</strong> The following exception when <code>Setup.Resolver.Get&lt;SomeLegacyType&gt;()</code> is called:</p>
  
  <pre><code>Autofac.Core.DependencyResolutionException: No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+&lt;&gt;c__DisplayClass0[SomeAssembly.SomeLegacyType,Autofac.Builder.SimpleActivatorData,Autofac.Builder.SingleRegistrationStyle]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which the instance was requested. 
  at Autofac.Core.Lifetime.MatchingScopeLifetime.FindScope(ISharingLifetimeScope mostNestedVisibleScope)
     at Autofac.Core.Resolving.ComponentActivation..ctor(IComponentRegistration registration, IResolveOperation context, ISharingLifetimeScope mostNestedVisibleScope)
     at Autofac.Core.Resolving.ResolveOperation.Resolve(ISharingLifetimeScope activationScope, IComponentRegistration registration, IEnumerable`1 parameters)
     at Autofac.Core.Lifetime.LifetimeScope.Resolve(IComponentRegistration registration, IEnumerable`1 parameters)
     at Autofac.Core.Container.Resolve(IComponentRegistration registration, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.TryResolve(IComponentContext context, Service service, IEnumerable`1 parameters, Object&amp; instance)
     at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Service service, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
  </code></pre>
  
  <p><strong>Side Question</strong> Is there a better way to have properties injected in ASMX, the same way my ASPX pages are injected (rather than use <code>Setup.Resolver</code>)? I use the <code>AttributedInjectionModule</code> because of legacy concerns. It doesn't appear that the module works on ASMX.</p>