What is the difference between IWindsorContainer vs IUnityContainer?
Asked Answered
B

2

7

I've worked with both 2 types of container between IWindsorContainer and IUnityContainer in different project for service and Interface binding. However I am not pretty sure what are the differences? Do they have same features? If yes then what is the need to develop another one on in case of existing one. Or do they have some differences? If yes, what is it? which purpose I am gonna use over which one? I have got a small documentation against this confusion, but I didn't quiet catch it. So if you let me know it then I will be grateful. Mention that, I am using NHibernet mapping here.

Borras answered 20/2, 2017 at 4:46 Comment(6)
Possible duplicate of Dependency injection container? What does it do?Dincolo
Dear @NightOwl888, I wanted to know the differences, and which shall I use in which situation. I think you didn't understand what I have asked. On the duplicate answer you provided there they have discussed only Windsor documentation nothing else about IUnityContainer I amlooking for this too.Borras
You can use any DI container you want (or no DI container at all) to implement the Dependency Injection pattern. But it would likely be a mistake to use more than one in the same application. To learn about Dependency Injection I suggest you read Dependency Injection in .NET. This is too broad of a topic to be discussed in a simple Q & A format.Dincolo
I didn't use different dependency injection in single project. I have seen varieties types of injection in multiple projects. So, in case of curiosity I wanted to know that. By the way, thanks for your support. The documentation is too large. :(Borras
It really isn't helpful to apply a bounty when a question is off-topic. There are many good questions that don't fit at Stack Overflow. Live with it.Souter
@AnandaM.Ghosh Looks like I missed a part the way I am using Castle Windsor for resolving type at the run time. I am deleting my answer right now. I will come up with better answer about this.Pleader
M
3

I have used both containers and the huge difference between them, over the years of using each has been that UnityContainer is managed by a team and is still being extended. The Windsor container was not very great at returning real errors. UnityContainer has great documentation and is very simple to install using nuget or some other repository manager.

Here is what I mean... if you look at how to use their code,https://github.com/castleproject/Windsor/blob/master/docs/README.md, windsor for example is very obfuscated.

public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Classes.FromThisAssembly()
                            .Where(Component.IsInSameNamespaceAs<King>())
                            .WithService.DefaultInterfaces()
                            .LifestyleTransient());
    }

If you would look at unity, https://github.com/unitycontainer/unity/blob/master/quickstarts/CS/EventBroker/Src/Stoplight/Program.cs, it becomes more clear what is happening by registering them in a different way. The error codes when you are down the rabbit hole are also much more clean with Unity.

IUnityContainer container = new UnityContainer()

            .AddNewExtension<SimpleEventBrokerExtension>()

            .RegisterType<ILogger, TraceLogger>()

            .RegisterType<IStoplightTimer, RealTimeTimer>();
Menedez answered 9/3, 2017 at 20:34 Comment(0)
A
1

check out the following link. This might help you https://visualstudiomagazine.com/articles/2014/09/25/refactor-5.aspx

Ambidextrous answered 10/3, 2017 at 5:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.