Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:31:21+00:00 2026-06-06T21:31:21+00:00

I added ASP.NET Web API RC to my MVC3 project using NuGet: Install-Package AspNetWebApi

  • 0

I added ASP.NET Web API RC to my MVC3 project using NuGet:

Install-Package AspNetWebApi

Then I configured it. In Global.asax.cs:

// configure regular controllers
var configuration = GlobalConfiguration.Configuration;
var container = Bootstrapper.ConfigureContainer(configuration);
containterProvider = new ContainerProvider(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

// Set the dependency resolver implementation for Web API.
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.DependencyResolver = resolver;

And in Boostrapper.ConfigureContainer(...) I added:

// I register my types as InstancePerLifetimeScope() 
// but I also tried .InstancePerHttpRequest().InstancePerApiRequest()
// to the same end
builder.RegisterType<SomeService>()
    .AsImplementedInterfaces().InstancePerLifetimeScope();
// Register API controllers using assembly scanning.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);

This is described here and here.

I also updated Autofac, Autofac.Web, Autofac.Mvc3 packages using NuGet and installed Autofac.WebApi package.

With this configuration I tried running my ApiController and got the following error:

No scope with a Tag matching ‘httpRequest’ is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being reqested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

Then as I read this comment from Alex Meyer-Gleaves:

I suspect you are using the Web API package with MVC3 and this is causing the problem. In the MVC3 integration the tag for the InstancePerHttpRequest lifetime scope was “httpRequest”. It was in the MVC4 Beta and Web API Beta packages that I changed both InstancePerHttpRequest and InstancePerApiRequest to use the common tag “AutofacWebRequest”. You can grab the MVC4 integration package from NuGet using Autofac.Mvc4.

source article with comment

So following the advice from Alex I got the package Autofac.Mvc4 but it works only with Mvc4 and my project wouldn’t build. I then grabbed the source code of Autofac to build Autofac.Mvc4 against Mvc3:

hg clone https://code.google.com/p/autofac/ --branch "MVC4 beta" C:\my\path

After using this assembly as my reference ApiController started working but regular Controllers worked ok only for a single controller action call. When the view called Html.RenderAction(…) and when I refresh or navigate to another controller action it crashes with this error:

No scope with a Tag matching ‘AutofacWebRequest’ is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being reqested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

I thought building from the newest source for Autofac.Mvc4 version 2.6.2.859 against Mvc3 could help but I can’t find the source for that. Or maybe there’s something else wrong in here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:31:23+00:00Added an answer on June 6, 2026 at 9:31 pm

    I found the problem. I also used Autofac.Integration.Web to inject dependencies into custom Membership and Role providers. But in WebLiftime.cs there was this line:

    public static readonly object Request = "httpRequest";
    

    Once I changed it to:

    public static readonly object Request = "AutofacWebRequest";
    

    and used the built assembly everything works fine and I get no errors 🙂

    I believe this constant value should the same as in all projects Autofac.Integration.Web, Autofac.Integration.Mvc and ‘Autofac.Integration.WebApi for Mvc4 so this supposedly is a bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've added a pre-build action for an ASP.NET web control (server control) project, that
I am using ASP.NET 4.0 membership api in web form application. I want to
I am using VS 2008. I have created a new Asp.net web site project
I have added a WCF service to an existing ASP.Net web project on our
A Silverlight-enabled WCF service was added into existing ASP.NET web-application. On attempt to add
I'm creating web site in asp.net web forms. I added validation to fields in
I've create a regular old ASMX web service in ASP.NET and added SoapDocumentMethod(OneWay =
I have an ASP.NET MVC application with a separate project added for tests. I
I created an ASP.NET web application (to consume a WCF Data Service) and added
Yesterday I added a custom MembershipProvider to an ASP.NET web application, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.