问题
Yesterday I was reading some articles in this site while I stumbled on an article about this two new IoC tools. Which one should I learn first? Is there some specification about which one should be used when?
回答1:
Neither Castle.Windsor or Spring.NET are new.
- Castle Windsor have been around since late 2004
- Spring.NET have been around since early 2006
They are two comparable DI Containers that essentially aim at providing the same services, so you don't need to learn one before the other, and neither do you need to consult any kind of specification on when to use which one.
I've been using Castle Windsor for about half a year and am generally happy with it. Spring.NET I have yet to look at, but it looks like it is very closely tied to the configuration system and doesn't support programmatic registration, and if this is true, that would be a major drawback in my eyes.
Castle Windsor and Spring.NET are not the only DI Containers available for .NET. Here's a larger list:
- Castle Windsor
- Spring.NET
- StructureMap
- Unity
- Ninject
- autofac
回答2:
I'm one of the committers to Castle project (which includes Windsor) so I may be biased, but.
Windsor is very extensible, allows you to tune and bend it to your needs. It provides nice fluent registration API so that you don't have to write ton of XML. There are also tons of extensions that you can use to integrate Windsor with other frameworks, like ORMs communication frameworks (WCF, NServiceBus) etc.
Plus it has a very active and responsive community, so if you have any questions, they'll get answered fairly quickly most of the time.
回答3:
I guess both are better in terms of configuration. No much difference but both are better than Unity framework. Why the hell you need marshalbyrefobject association in dependency control. But if we compare spring.net and Castle Windsor both are good. But question comes which one is complete container framework. Like we need Aspects for validation on Dependency. So winsor utility fail. I guess it’s stupid to compare String.net with Castle Windsor or anything like such because all are utilities and spring is complete container framework. And all folks who say it’s heavy please check memory leak issues with all. It’s not spring or Castle Windsor , it’s stupid way of writing code. So finally answer is if you need just DI use Windsor but if you need complete framework for any solution use spring.net.
来源:https://stackoverflow.com/questions/2033004/castle-windsor-or-spring-net-advantages-and-disadvantages