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 7757539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:07:22+00:00 2026-06-01T13:07:22+00:00

I have registered a component like this in my Global.asax.cs: ContainerBuilder builder = new

  • 0

I have registered a component like this in my Global.asax.cs:

ContainerBuilder builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());

builder.RegisterType<WebWorkContext>().As<IWorkContext>().InstancePerHttpRequest();

IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

// This is where my error happens, not sure why?
var workContext = container.Resolve<IWorkContext>();

WebWorkContext class:

public class WebWorkContext : IWorkContext
{
     // Left out other code
}

IWorkContext interface:

public interface IWorkContext
{
     // Left out other code
}

The error that I am getting is:

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.

How do I get this to work? This reason why I want it this way is because the work context handles stuff like getting the current customer etc.

Some more questions. Is it wise/best practices to register every at once? Will the be scenarios that I will need to add more components at another stage?

  • 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-01T13:07:24+00:00Added an answer on June 1, 2026 at 1:07 pm

    Registrations that are marked with InstancePerHttpRequest are expected to be resolved from a particular nested lifetime scope that is created and disposed during each HTTP request.

    If you add IWorkContext as a constructor parameter to one of your controllers you will find that an instance is injected. In your code you are attempting to resolve your service from the root lifetime scope and not the nested “per request” lifetime scope.

    If you want to test resolving the service without running up your application you will need to create a lifetime scope with the same tag as the one created during the HTTP request. In the MVC 3 integration the lifetime scope is tagged “httpRequest”.

    using (var httpRequestScope = container.BeginLifetimeScope("httpRequest"))
    {
        Assert.That(httpRequestScope.Resolve<IWorkContext>(), Is.Not.Null);
    }
    

    I think I will update the MVC integration to expose the “httpRequest” tag name publicly through the API so that string values don’t need to be hard coded. It is also possible to pass your own ILifetimeScopeProvider implementation to the AutofacDependencyResolver so that you can control the creation of lifetime scopes outside of the ASP.NET runtime. This is useful in unit tests when there is no HTTP request available.

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

Sidebar

Related Questions

I have a drag-and-drop event handler registered to a parent form, this.DragDrop += new
I have a visual component that I built from a TFrame (but then registered
I have registered an enumeration type ClefType within my header file - this enum
I am creating C# application that uses OCX component. I have this component from
I have a component registered with Castle Windsor which depends on a list of
I have registered ProximityAlert in MapActivity. No problem with catching alerts in BroadcastReceiver and
I have a table of recent web guest who have registered. One of the
I am using the MVP design pattern and I have registered my presenter as
I have a domain registered and hosted at hostmonster. I want to create a
I have several domain names registered, each a slight variant of each other. E.g,

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.