1 / 23

Alternative Architectures: Inversion of Control

Alternative Architectures: Inversion of Control. Mike Hadlow mikehadlow@yahoo.com mikehadlow.blogspot.com. What am I going to talk about?. The problem: Application Architecture. What is Inversion of Control? Inversion of Control Containers. A Real Application: Suteki Shop.

khalil
Télécharger la présentation

Alternative Architectures: Inversion of Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Alternative Architectures: Inversion of Control Mike Hadlow mikehadlow@yahoo.com mikehadlow.blogspot.com

  2. What am I going to talk about? • The problem: Application Architecture. • What is Inversion of Control? • Inversion of Control Containers. • A Real Application: Suteki Shop.

  3. Comonent size vs. complexity is not linear Complexity Features

  4. Break large pieces into smaller pieces

  5. The goal of good architecture • Don’t repeat yourself (DRY) • Decreased coupling • Separation of concerns • Reduced cost of change • Greater flexibility • Do more for less ££££

  6. What is a component Wikipedia says: • Multiple use • Non context specific • Composable with other components • Encapsulated • A unit of independent deployment and versioning

  7. What is inversion of control? • A way of designing reusable components • A way of decoupling services • A design pattern not a framework • ‘Inject’ dependencies through constructor or parameters (Dependency Injection) • It’s easy!

  8. Show me the code <Demo>

  9. Problems with typical coding techniques • Difficult or impossible to test • Tightly coupled • Violates the single responsibility principle • Violates the open closed principle

  10. Vocabulary Service = Interface (IEmailSender) Component = Class (EmailSender) BUT Not all classes are components

  11. IoC design style • Systems are composed of small specialised services • Represented by interfaces • Components declare • The services they provide (by implementation) • The services they require (by DI) • Components do not dictate their own lifestyle • Do not implement singleton yourself • Let TDD drive your design

  12. 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

  13. Castle MicroKernel / Windsor • Part of the Castle Project castleproject.org • Started by Hamilton Verissimo • Also includes: • MonoRailMVC framework for ASP.NET • ActiveRecordbased on NHibernate

  14. IoC container example <demo>

  15. How dependencies are resolved Reporter IReportBuilder IReportSender

  16. Flexibility <demo>

  17. Lifestyles • Singleton (the default) • Transient • Per Thread • Pooled • Per Web Request • Custom

  18. A Real Application http://code.google.com/p/sutekishop/ http://sutekishop.co.uk/ <suteki shop demo>

  19. Pros? • Simpler component architecture • Reduced cost of change • Easy to unit test • Easily move between application configurations • Ready made configuration (IoC containers)

  20. Cons? • Not another thing to learn? • Higher level of abstraction • Performance? • Lifestyle mistakes can be hard to diagnose • Can’t do obfuscation and configuration • Maybe it’s time we looked at dynamically typed languages?

  21. Should I use it? • Already familiar with OO principles and patterns? • Already writing unit tests? • Using a statically typed language? If not, learn how to do these first Don’t impose an IoC container on a team which can’t see its benefit

  22. Resources • Castle Project castleproject.org • Oren Einiayende.com/blog • Alex Henderson bittercoder.com • ALT NET http://tech.groups.yahoo.com/group/altdotnet/

  23. Questions? Mike Hadlow mikehadlow@yahoo.com mikehadlow.blogspot.com

More Related