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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:01:22+00:00 2026-05-14T09:01:22+00:00

New to Castle/Windsor, please bear with me. I am currently using the framework System.Web.Mvc.Extensibility

  • 0

New to Castle/Windsor, please bear with me.

I am currently using the framework System.Web.Mvc.Extensibility and in its start up code, it registered HttpContextBase like the following:

container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));

What I wanted to do is to change the behavior and change the lifestyle of httpContextBase to be PerWebRequest.

so I have change the code to the following:

container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));

However, when I do this, I got the following error:

 System.Configuration.ConfigurationErrorsException: Looks like you forgot to 
 register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
 Add '<add name="PerRequestLifestyle" 
 type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" 
 />' to the <httpModules> section on your web.config

which I did under <system.web> and <system.webServer>, however, I am still getting the same error. Any hints?

Thanks in advance.

Update

added code block per request

In the system.web.mvc.extensibility framework, there is a class called extendedMvcApplication which inherit from HttpApplication, and in the Application_start method, it calls BootStrapper.Execute(). This implementation of this method is the following:

public void Execute()
    {
        bool shouldSkip = false;

        foreach (IBootstrapperTask task in ServiceLocator.GetAllInstances<IBootstrapperTask>().OrderBy(task => task.Order))
        {
            if (shouldSkip)
            {
                shouldSkip = false;
                continue;
            }

            TaskContinuation continuation = task.Execute(ServiceLocator);

            if (continuation == TaskContinuation.Break)
            {
                break;
            }

            shouldSkip = continuation == TaskContinuation.Skip;
        }
    }

As you can see, it loops through a list of IBootStrapperTask and tries to execute them. It so happens that I have one task that register the routes in my mvc app:

public class RegisterRoutes : RegisterRoutesBase
{
    private HttpContextBase contextBase;

    protected override TaskContinuation ExecuteCore(IServiceLocator serviceLocator)
    {
        contextBase = serviceLocator.GetInstance<HttpContextBase>();
        return base.ExecuteCore(serviceLocator);
    }

    protected override void Register(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
        routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });

        XmlRouting.SetAppRoutes(routes, contextBase.Server.MapPath("~/Configuration/Routes.xml"));
    }
}

you can see that I need to getInstance(resolve) a httpcontextbase object such that I can get the server path of a xml file.

  • 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-05-14T09:01:22+00:00Added an answer on May 14, 2026 at 9:01 am

    As of this writing, PerWebRequest lifestyle does not support resolving in Application_Start().

    See issue description and discussion:

    • http://support.castleproject.org/projects/IOC/issues/view/IOC-ISSUE-166
    • http://groups.google.com/group/castle-project-users/browse_thread/thread/d44d96f4b548611e

    Workarounds for this particular case:

    1. Register RegisterRoutes as an instance, explicitly passing it the current context as constructor parameter, e.g.:

      container.Register(Component.For<IBootstrapperTask>()
                                  .Instance(new RegisterRoutes(Context)));
      
    2. Use HostingEnvironment.MapPath instead of contextBase.Server.MapPath. Want to make it mockable? Use it through a simple interface, e.g.:

      interface IServerMapPath {
          string MapPath(string virtualPath);
      }
      
      class ServerMapPath: IServerMapPath {
          public string MapPath(string virtualPath) {
              return HostingEnvironment.MapPath(virtualPath);
          }
      }
      
      container.AddComponent<IServerMapPath, ServerMapPath>();
      

    Then inject IServerMapPath into your RegisterRoutes.

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

Sidebar

Related Questions

Given the following Code. [TestMethod] public void CanResolveILoggerTest() { var Container = new Castle.Windsor.WindsorContainer();
I'm new to Castle Windsor and am just using the latest version. I've created
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
I'm using Castle Windsor in my project. Some registered components are intercepted. Because the
I'm really new to Castle Windsor IoC container. I wanted to know if theres
I'm trying to host a WCF service inside a console app using Castle-Windsor 2.5
I generally use StructureMap, but on a current project I'm using Castle Windsor (2.1).
New to javascript/jquery and having a hard time with using this or $(this) to
In new C++ code, I tend to use the C++ iostream library instead of
I have the following mapping in my Castle Windsor xml file which has worked

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.