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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:21:02+00:00 2026-05-24T14:21:02+00:00

I was wondering how to wire up Castle Windsor in WebForms. I’m assuming that

  • 0

I was wondering how to wire up Castle Windsor in WebForms.

I’m assuming that the second line wires up the controllers in MVC:

// Initialize Windsor
IWindsorContainer container = new WindsorContainer().Install(FromAssembly.This());
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel));

How do I then wire up WebForms in ASP.NET?

I had a project which I have modified into an identical WebForms setup. Everything works up until the point where I want Castle Windsor to inject ISession into the ASPX page. It simply doesn’t and I am under the assumption that the second line of code, above, is what does it for MVC controllers.

I have this in my nHibernate installer, in teh same place on both projects:

container.Register(Component.For<ISession>()
            .LifeStyle.PerWebRequest
            .UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession()));

I had originally assumed this would do it but it is not the case.

I have been stuck on this for days and with very little official documentation on this I am close to ripping my hair out, what’s left of it.

I do know the ASP.NET WebForms are not specifically designed to work with dependancy injection but Ninject have done it, albeit with a little hacking, if I can confirm that Castle Windsor is not compatible and/or will no longer support WebForms I will move to something else.

  • 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-24T14:21:04+00:00Added an answer on May 24, 2026 at 2:21 pm

    I managed to stuff Castle Windsor in to WebForms using the code here How to use Castle Windsor with ASP.Net web forms? It uses an an attribute to mark where a dependency should be injected in the a WebFrom.

    I then used an MVP pattern. Each WebForm had a presenter

    public partial class TestPage : UserControl, IShowTestPage
    {
        [Inject]
        public TestPagePresenter Presenter { get; set; }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
    
            this.Presenter.OnViewInitialized();
        }
    
        public string TestMessage
        {
            get { return litTestMessage.Text; }
            set { litTestMessage.Text = value; }
        }
    }
    

    As the Presenter is resolved form the container, it is then back to normal for wiring up the dependencies

    public interface IShowTestPage {
        string TestMessage { get; set;}
    }
    
    public class TestPagePresenter {
        private ISession session;
    
        public TestPagePresenter(ISession session) {
            this.session = session;
        }
    
        private IShowTestPage view;
        public IShowTestPage { set { view = value; } }  
    
        public void OnViewInitialized {
            TestMessage = session.Query("some database query");
        }
    
    }
    

    My solution was based on a great article by Billy McCafferty

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

Sidebar

Related Questions

Wondering if this is possible. We have an 3rd Party library that contains identification
Wondering if anyone knows a nice way to execute a Java command-line program from
Wondering if there is any way to get the lambda expressions that result from
I'm noticing some behavior that I don't like, and I'm wondering if this is
I've noticed recently that spring can wire up my ejb's for me if I
Good afternoon everyone. I was wondering if there is anyway to have the MVC
I am trying to wire up dependency injection with Windsor to standard asp.net web
I have a DataTable that's had people wire into it's different column changed events,
Wondering if there is an existing ring buffer in .NET that has only one
Wondering if anyone has gotten the infamous database is locked error from Trac and

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.