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

  • Home
  • SEARCH
  • 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 9228727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:23:47+00:00 2026-06-18T05:23:47+00:00

I am trying to create a A(UserManager) needs to create instances of B(UserClient) relationship

  • 0

I am trying to create a “A(UserManager) needs to create instances of B(UserClient)” relationship (http://code.google.com/p/autofac/wiki/RelationshipTypes) where B(UserClient) needs a HttpSessionStateBase..

UserClient

public class UserClient : IUserClient
    {
        public UserClient(HttpSessionStateBase session)
        {
             //...
        }

        //...
    }

UserManager

public class UserManager : IUserManager
    {
        private readonly Func<IUserClient> userClientPerRequest;
        private IUserClient UserClient
        {
            get
            {
                return userClientPerRequest();
            }
        }

        public UserManager(Func<IUserClient> userClientPerRequest)
        {
            this.userClientPerRequest = userClientPerRequest;
        }

        public void DoStuff()
        {
            UserClient.DoStuff();
        }

This is where is register autofac stuff

public class MyModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterType<UserManager>().As<IUserManager>().SingleInstance();

            builder.RegisterType<UserClient>().As<IUserClient>().InstancePerHttpRequest();

            builder.RegisterModule(new AutofacWebTypesModule());


            //If i try this, i get Error 1 (printing errors after this code-block)
            builder.Register<Func<IUserClient>>(c => c.Resolve<IUserClient>);

            //If i try this, i get Error 2                
            builder.Register<Func<IUserClient>>(c => {
            var ctx = c.Resolve<IComponentContext>();
            return ctx.Resolve<IUserClient>;                
            });

            //If i try this, well i always get null from GetService..
            builder.Register<Func<IUserClient>>(c =>            
            DependencyResolver.Current.GetService<IUserClient>);
        }

Looking at Autofac: Reference from a SingleInstance'd type to a HttpRequestScoped , they use some RequestContainer but i can find no such thing. 🙂

Error 1

This resolve operation has already ended. When registering components using lambdas, the IComponentContext 'c' parameter to the lambda cannot be stored. Instead, either resolve IComponentContext again from 'c', or resolve a Func<> based factory to create subsequent components from.

Error 2

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 have tried switching .InstancePerHttpRequest() to .InstancePerLifetimeScope() and a whole other different stuff.. Anyone have any ideas?

Thanks

  • 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-18T05:23:48+00:00Added an answer on June 18, 2026 at 5:23 am

    When adding Autofac registrations manually in Orchard, use InstancePerMatchingLifetimeScope("shell"), if you need a singleton or InstancePerMatchingLifetimeScope("work"), if you need per-request instance.

    I’m not sure if HttpSessionStateBase ctor argument can actually be resolved from the container. You could put IHttpContextAccessor there instead and use it to access the session state object inside IUserClient implementation.

    And as Jim Bolla suggested – Func<IUserClient> (factory) is already available out of the box.

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

Sidebar

Related Questions

I am trying create a xmldocument object by a different XML see the code
I'm trying create a small http proxy service. This is not working so well.
I trying create empty white image with php, this s my code $bg =
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
Trying to create a black line in my view to separate text blocks but
Trying to create a facebook app just to learn and coming across a strange
Trying to create a new Dedicated Cache Role in Windows Azure but get the

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.