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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:16:30+00:00 2026-05-28T01:16:30+00:00

On the IOC Castle Windsor wiki [Editor’s Note: After this question was written, the

  • 0

On the IOC Castle Windsor wiki [Editor’s Note: After this question was written, the wiki has been updated with more example code], there is the following (incomplete) demo code.

How do I complete this code so it runs properly in a C# console app?

//application starts...
var container = new WindsorContainer();

// adds and configures all components using WindsorInstallers from executing assembly
container.Install(FromAssembly.This());

// instantiate and configure root component and all its dependencies and their dependencies and...
var king = container.Resolve<IKing>();
king.RuleTheCastle();

// clean up, application exits
container.Dispose();

Update:

Discovered tutorial videos on IOC in general.

Got as far as adding an interface and a concrete implementation of the interface:

interface IKing
{
    void RuleTheCastle();   
}

public class King
{
    void RuleTheCastle()
    {
        Consolel.Write("Rule the castle.");
    }
}

However, it threw a runtime error when I ran it.

Update:

I ended up using Ninject, because:

  1. The documentation is far superior to Castle Windsor (and Spring.NET for that matter).
  2. It uses expression compilation/LCG, so its faster (8x to 50x) compared to Castle Windsor, which uses Reflection.

To get started, click on “Visit the Dojo”, then follow through the series of NInject tutorials on GitHub.

After you’ve done this, you can view a tutorial video on TekPub. The video does go through the concepts quite fast, so it might be good to complete the series of NInject tutorials on GitHub first.

  • 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-28T01:16:31+00:00Added an answer on May 28, 2026 at 1:16 am

    Typically, in order to apply IoC in a C# console application you would use the entry point (e.g. the Main method) to:

    • instantiate and configure an IoC container – the first two lines in the sample code
    • use the container to build an object graph (an object and its dependencies) – 3rd line of code
    • pass control to the resolved object, usually by calling a method on it – 4th line of code
    • after the application is done, tell the container perform any clean up it needs to perform – 5th line of code

    This what that code demo presents, and from this point of view it’s complete.

    However, in order for this application to work there are two other very important prerequisites:

    • the application has to be designed with the Inversion-of-Control principle in mind (this is actually the hard part)
    • the entry-point assembly of the console app has to contain Windsor Installers that are used to configure the container and that basically define what concrete types will be used whenever an interface is needed.

    The code for the Installer class in this example would look like this:

    public class KingApplicationInstaller : IWindsorInstaller
    {
       public void Install(IWindsorContainer container, IConfigurationStore store)
       {
            container.Register(
                Component.For<IKing>().ImplementedBy<King>());
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to IoC and Castle Windsor. The question is more related to
This is probably a stupid question! I am being forced to use Castle Windsor
I'm really new to Castle Windsor IoC container. I wanted to know if theres
So my company uses Castle Windsor IoC container , but in a way that
I am using Castle Windsor for IoC, and have the configuration held in the
I'm building a winforms app utilizing passive-view MVP and Castle Windsor as an IoC
Ninject, Sprint.NET, Unity, Autofac, Castle.Windsor are all examples are IoC frameworks that are available.
I've been working on creating my own IoC container for learning purposes. After asking
This isn't a very simple question, but hopefully someone has run across it. I
I am using a custom ControllerFactory (to use Castle Windsor's IOC to create controllers),

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.