160 likes | 289 Vues
This article explores the concept of Inversion of Control (IoC), specifically using the Castle Windsor container. It highlights the advantages of IoC, such as simpler component architecture and easier unit testing, while also discussing potential drawbacks like the learning curve and higher abstraction levels. With insights into how dependencies are resolved and best practices for implementation, this guide is ideal for developers already familiar with object-oriented principles. Learn to effectively utilize IoC containers for your application needs.
E N D
The Castle Windsor Inversion of Control Container Mike Hadlow mikehadlow@yahoo.com mikehadlow.blogspot.com
IoC == Component Oriented Dev Wikipedia says: • Multiple use • Non context specific • Composable with other components • Encapsulated • A unit of independent deployment and versioning
What is an IoC container? • A (very) smart factory • Automatically resolves dependencies • Automatically injects concrete instances • All services are registered in the container • Single point of access for services • Transparent • Various implementations for .NET
Castle MicroKernel / Windsor • Part of the Castle Project castleproject.org • Started by Hamilton Verissimo • Also includes: • MonoRailMVC framework for ASP.NET • ActiveRecordbased on NHibernate
How dependencies are resolved Reporter IReportBuilder IReportSender
Pros? • Simpler component architecture • Reduced cost of change • Easy to unit test • Easily move between application configurations • Ready made configuration (IoC containers)
Cons? • Not another thing to learn? • Higher level of abstraction • Can’t do obfuscation and configuration
Should I use it? • Already familiar with OO principles and patterns? • Already writing unit tests? If not, learn how to do these first Don’t impose an IoC container on a team which can’t see its benefit
A Real Application http://code.google.com/p/sutekishop/ http://sutekishop.co.uk/
Resources • Castle Project castleproject.org • Oren Einiayende.com/blog • Alex Henderson bittercoder.com
Questions? Mike Hadlow mikehadlow@yahoo.com mikehadlow.blogspot.com