How to get started with Castle-Windsor?
Asked Answered
C

3

19

I am completely new with IoC/windsor. I started with Google to learn it, but unfortunately, I haven't got proper documentation which could be easier for me to understand. so I came here with such this title/questions.

Every document/pages(web), Starting something similar like this

"We should start from registering the class/interface then resolve it ... "

but none of the page shows complete documentation on how to achieve that, I tried to make a simple project too, but I failed to run it. I don't know how to resolve container , where/how to call for install(), I am totally messed up.

Could anyone help me with a sample project which includes a complete demonstration of registration/installation?

Thanks in advance :)

Cracksman answered 2/2, 2013 at 16:51 Comment(0)
C
23

Also Mark Seemann's Dependency Injection in .NET book is a good place to start. Well written and has a chapter on Castle Windsor specifically.

They also have some good tutorials on code project, I used before:

UPDATE

Well, the most simplistic tutorial would be as follows:

1) In VS2010 create new console application

2) Right click on "References", select "Manage NuGet Packages", install Castle.Windsor

3) Use code below for Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace ExploringCastleWindsor
{
    internal class Program
    {
        interface ILogger
        {
            void Log(string message);
        }

        class Logger : ILogger
        {
            public void Log(string message)
            {
                Console.WriteLine(message);
            }
        }

        static void Main(string[] args)
        {
            // Registering
            var container = new WindsorContainer();
            container.Register(Component.For<ILogger>().ImplementedBy<Logger>());
            // Resolving
            var logger = container.Resolve<ILogger>();
            logger.Log("Hello World!");
        }
    }
}
Canker answered 2/2, 2013 at 21:4 Comment(2)
Thanks for the book, i went through those tutorials but unfortunately unable to integrate these all concepts at a time. plz provide me a simple complete project :)Cracksman
Thanks a lot, it helps me a lot :), but i got some issues when i make some changes in it, please check the this link #14670256Cracksman
X
1

If you are looking for a tutorial, check this link

It is explaining CastleWindsor, Nhibernate and UnitOfWork in one example.

Xerophyte answered 7/3, 2017 at 18:2 Comment(0)
E
0

Also you can add Castle Windsor using

Tools --> NuGet Package Manager --> Package Manager Console.

And than just type Install-Package Castle.Windsor

After you done with assamblies you are good to go with code. Sebastian K provided a good example of working code.

Enenstein answered 17/6, 2016 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.