IoC demo coding steps: 1. Explain existing code first (what it does) ask what's wrong with it? - Not object oriented. - No separation of concerns. - No encapsulation - Breaks single responsibility principle - We can't use any of this again (violates DRY) 2. Break out ReportRepository (remember to make them class level members) 3. Break out ReportSender 4. Break out Logger - Now we have separation of concerns. - We are obeying the single responsibility principle. - we can reuse a lot of the code. BUT - Reporter is not context independent. It takes it's three dependencies everywhere. - Reporter breaks the Open-Closed Principle. - We can't test reporter HOW DO WE FIX THIS? Dependency Injection 5. Change Reporter to use Dependency Injection. REMOVE LOGGING. Use Linq Where clause to filter Reports - This is Dependency Injection 6. Now we can write a test - DI is the most important pattern in OO - DI is the most important concept to take away from this talk. 7. We can change the way reporter works. Substitute ReportTweeter - Open Closed Principle: we didn't have to change any existing code (including our tests) - We can change the behaviour of our program merely by composing components. BUT WHAT ABOUT THE WIRE-UP CODE? 8. Introduce Windsor to wire up existing components - Show basic fluent configuration. - Show name based configuration and resolution. - Show how easy it is to replace different senders. 9. Lifestyles - demonstrate Transient, Singleton. - explain PerWebRequest, Pooled, PerThread 10. Instance registration. - point out that it can't take part in dependency resolution. 10. Disposal - explain now non-disposable instances have no reference and can be garbage collected. - demonstrate how chains of disposable transient instances are disposed. - demonstrate how singleton instances are disposed when container is disposed. 10. XML Configuration - including passing simple string properties - show mixing XML and fluent config. 10. Show decorators by re-introducing logger. Generics Factories Facilities Suteki Shop ----------- - Show how the windsor instance is only referenced once. - Show multi-tenancy