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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:51:11+00:00 2026-05-11T01:51:11+00:00

I am trying to wire up dependency injection with Windsor to standard asp.net web

  • 0

I am trying to wire up dependency injection with Windsor to standard asp.net web forms. I think I have achieved this using a HttpModule and a CustomAttribute (code shown below), although the solution seems a little clunky and was wondering if there is a better supported solution out of the box with Windsor?

There are several files all shown together here

    // index.aspx.cs     public partial class IndexPage : System.Web.UI.Page     {         protected void Page_Load(object sender, EventArgs e)         {             Logger.Write('page loading');         }          [Inject]         public ILogger Logger { get; set; }     }      // WindsorHttpModule.cs     public class WindsorHttpModule : IHttpModule     {         private HttpApplication _application;         private IoCProvider _iocProvider;          public void Init(HttpApplication context)         {             _application = context;             _iocProvider = context as IoCProvider;              if(_iocProvider == null)             {                 throw new InvalidOperationException('Application must implement IoCProvider');             }              _application.PreRequestHandlerExecute += InitiateWindsor;         }          private void InitiateWindsor(object sender, System.EventArgs e)         {             Page currentPage = _application.Context.CurrentHandler as Page;             if(currentPage != null)             {                 InjectPropertiesOn(currentPage);                 currentPage.InitComplete += delegate { InjectUserControls(currentPage); };             }         }          private void InjectUserControls(Control parent)         {             if(parent.Controls != null)             {                 foreach (Control control in parent.Controls)                 {                     if(control is UserControl)                     {                         InjectPropertiesOn(control);                     }                     InjectUserControls(control);                 }             }         }          private void InjectPropertiesOn(object currentPage)         {             PropertyInfo[] properties = currentPage.GetType().GetProperties();             foreach(PropertyInfo property in properties)             {                 object[] attributes = property.GetCustomAttributes(typeof (InjectAttribute), false);                 if(attributes != null && attributes.Length > 0)                 {                     object valueToInject = _iocProvider.Container.Resolve(property.PropertyType);                     property.SetValue(currentPage, valueToInject, null);                 }             }         }     }      // Global.asax.cs     public class Global : System.Web.HttpApplication, IoCProvider     {         private IWindsorContainer _container;          public override void Init()         {             base.Init();              InitializeIoC();         }          private void InitializeIoC()         {             _container = new WindsorContainer();             _container.AddComponent<ILogger, Logger>();         }          public IWindsorContainer Container         {             get { return _container; }         }     }      public interface IoCProvider     {         IWindsorContainer Container { get; }     } 
  • 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. 2026-05-11T01:51:12+00:00Added an answer on May 11, 2026 at 1:51 am

    I think you’re basically on the right track – If you have not already I would suggest taking a look at Rhino Igloo, an WebForms MVC framework, Here’s a good blog post on this and the source is here – Ayende (the Author of Rhino Igloo) tackles the issue of using Windsor with webforms quite well in this project/library.

    I would cache the reflection info if you’re going to inject the entire nested set of controls, that could end up being a bit of a performance hog I suspect.

    Last of all spring.net approaches this in a more configuration-oriented way, but it might be worth taking a look at their implementation – here’s a good reference blog post on this.

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 55k
  • Answers 55k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Use the ToList() extension method to convert the query to… May 11, 2026 at 7:45 am
  • added an answer Check out the connectWith option for sortables. Essentially, if you… May 11, 2026 at 7:45 am
  • added an answer The only difference is ease of typing and readability. The… May 11, 2026 at 7:45 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.