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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:25:29+00:00 2026-06-02T13:25:29+00:00

I am using Castle Windsor’s inversion of control in my application. When the application

  • 0

I am using Castle Windsor’s inversion of control in my application. When the application first loads, IWindsorContainer.Resolve resolves the components (in particular, factories) into instances.

For example, ILoggerFactory gets resolved into MyCustomLoggerFactory (or anything which implements ILoggerFactory), whose method CreateLogger() creates a logger. I want to have each class call ILoggerFactory.CreateLogger(). However, I do not want to pass an ILoggerFactory into the constructor of each class.

How can each class access the particular ILoggerFactory factory to use without having to call IWindsorContainer.Resolve every single time?

  • 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-02T13:25:31+00:00Added an answer on June 2, 2026 at 1:25 pm

    As far as I know there are three ways to get hold of a dependency out of the windsor container (incidentally you shouldn’t ever need to explicitly resolve anything, except possibly some bottom level class, just make sure it is all registered with the container and the dependencies are wired up for you):

    1. Add a constructor argument (this is considered a required dependency)
    2. Add a property to the class (this is considered an optional dependency)
    3. Get hold of the IWindsorContainer instance and call Resolve (this is usually a bad idea)

    Normally for logging specifically you would make that an optional dependency so go for option 2 and do something like this (I used your ILoggerFactory idea, I actually wouldn’t define my own factory for this – see later):

    private ILoggerFactory _loggerFactory = LoggerFactory.NullLoggerFactory;
    
    public ILoggerFactory LoggerFactory
    {
        get { return _loggerFactory; }
        set { _loggerFactory = value; }
    }
    

    That way, in your code, you can use the LoggerFactory property and if one has not been added to the container you get the “null” version (this is just an instance of ILoggerFactory that creates a logger that does nothing) and if it has you get the real version (you could just check for null when you use it, or if you know that there will be one just use it). You define this property on the classes where you need the logger and you are done.

    An Aside

    Incidentally, there is such a thing as the logging facility in Windsor that you could use instead – I have a small issue with that since I don’t really want a windsor interface throughout my code base so what I have done in the past is defined my own ILogger interface (and a null implementation of it) and then created a “castle logger proxy” that implements my ILogger interface but has a dependency on the castle ILogger which is what it calls into to do the actual logging. That way I can separate that out into it’s own assembly and my application can have no idea that Windsor is injecting the dependencies.

    Maybe you don’t care though, just thought I would mention it.

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

Sidebar

Related Questions

I'm using Castle.Windsor in my application. My components and their parameters are configured within
I'm using Castle Windsor and Binsor to use dependency injection in my application. I'm
On my development machine, I am currently registering my components in Castle Windsor using
I'm using Castle Windsor in my project. Some registered components are intercepted. Because the
I'm using Castle Windsor to do some dependency injection, specifically I've abstracted the DAL
I'm using castle windsor for a pet-project I'm working on. I'm starting to notice
I am using Castle Windsor for IoC, and have the configuration held in the
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
I've got a pretty basic question about how to start using Castle Windsor. I've
I am using windsor castle as my IoC container, and has run in to

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.