Download presentation
Presentation is loading. Please wait.
Published byBonnie Daniels Modified over 9 years ago
1
St Louis Day of.NET 2011 Taming Dependency Chaos with Inversion of Control Containers Steve Bohlen Senior Software Engineer SpringSource/VMware E-Mail: sbohlen@gmail.com Blog: http://blog.unhandled-exceptions.com Twitter: @sbohlen
3
St Louis Day of.NET 2011 Do I suck? Let me (and the world) know! http://spkr8.com/t/8097
4
St Louis Day of.NET 2011 Who am I? …and why should you care? Steve Bohlen I Read Books + Write Software vs. “Read Software + Write Books” Blog, Screencast, Speak, Share, Learn
5
St Louis Day of.NET 2011 Steve Bohlen Nearly 20 years developing software LISP, Delphi, C/C++, VB, VB.NET, C# Senior Engineer Springsource/VMware Co-Founder, NYC Alt.Net User Group http://nyalt.net Co-Organizer, NYC DDD User Group http://dddnyc.org Contributor: various OSS projects Nhibernate http://www.nhforge.org NDbUnit http://www.googlecode.com/ndbunit Spring.NET http://www.springframework.net blog: http://blog.unhandled-exceptions.com e-mail: sbohlen@gmail.com twitter: @sbohlen
6
St Louis Day of.NET 2011 RAD Controls for ASP.NET AJAX RAD Controls for Silverlight RAD Controls for Windows Phone RAD Controls for Winforms RAD Controls for WPF Telerik Reporting Telerik OpenAccess ORM Telerik JustCode Telerik JustMock Telerik Extensions for ASP.NET MVC Test Studio Express Telerik TeamPulse Telerik Test Studio Sitefinity CMS Telerik JustDecompile C#/VB.NET Converter ASPX to Razor Converter
7
St Louis Day of.NET 2011
10
How much can you keep in your Head?
11
St Louis Day of.NET 2011 Our Application (or class, or method, etc.)
12
St Louis Day of.NET 2011 First Attempt at Decomposition Components!
13
St Louis Day of.NET 2011 Ideal Decomposition Level Units!
14
St Louis Day of.NET 2011 The Challenge: Turning this into something useful Decomposition carries overhead… …of re-composition for meaningful work!
15
St Louis Day of.NET 2011 …easily! The Goal: Units Assembled into Something Useful…
16
St Louis Day of.NET 2011 Code Demo: Refactoring for Decomposition
17
St Louis Day of.NET 2011 Reviewing Our Dependency Graph after Decomposition Logger ConnectionManager DataSorter Logger DataAccess Worker DataPrinter Logger
18
St Louis Day of.NET 2011 Code Demo: Refactoring to Ease (Re-)Composition
19
St Louis Day of.NET 2011 Reviewing Our Dependency Graph after IoC ConnectionManager DataSorter Logger DataAccess Worker Container Construction Dependency Graph Functional Dependencies Remain as Before DataPrinter
20
St Louis Day of.NET 2011 Aspect-Oriented Programming (AOP)
21
St Louis Day of.NET 2011 (one of) The Challenges of OO Software Design Not all common behaviors can be efficiently modeled by OO paradigms – Inheritance, Dependency Injection / Inversion of Control Simple Examples – Logging, Authorization, Transactions, Exceptions …more… We call these concerns of our application – They are all things our objects must ‘concern’ themselves with doing Because they cut across many objects in our application… – …we call them cross-cutting concerns
22
St Louis Day of.NET 2011 Example: Logging by Inheritance public abstract class LoggingBase { protected void Log(string msg) {…} } public abstract class LoggingBase { protected void Log(string msg) {…} } Public class Service1 : LoggingBase {…} Public class Service1 : LoggingBase {…} Public class Service2 : LoggingBase {…} Public class Service2 : LoggingBase {…} Public class Service3 : LoggingBase {…} Public class Service3 : LoggingBase {…} Common Abstract Base Class … … Awkward! Rigid hierarchy! How do you add logging after you design your application??? Inherit from Common Base
23
St Louis Day of.NET 2011 Public class Service1 { public Service1 (Logger logger) { _logger = logger; } Public class Service1 { public Service1 (Logger logger) { _logger = logger; } } Example: Logging by Dependency Injection Public class Logger { public void Log(string msg) {…} } Public class Logger { public void Log(string msg) {…} } Dependency Awkward! Inject Logger Everywhere! How do you add logging after you design your application??? Constructor Injection
24
St Louis Day of.NET 2011 The Promise of Aspect-Oriented Programming All (most) applications have these cross-cutting concerns – For fun (and because it’s a common convention) let’s call them Aspects Aspects can be applied to objects in our solution using AOP tools – Broadly applied to many classes in our solution – Minimally-invasive – Non-Manual introduction of Aspects Not by literal coding (directly)
25
St Louis Day of.NET 2011 Understanding AOP Terms Cross-Cutting Concerns the ‘problem’ we want to solve Advice code that solves the problem Pointcut where to apply the Advice Aspect Pointcut + Advice = Aspect
26
St Louis Day of.NET 2011 Code Demo: Defining and Applying Aspects
27
St Louis Day of.NET 2011 Reviewing Our Dependency Graph after IoC ConnectionManager DataSorter Logger DataAccess DoSomeWork Container Construction Dependency Graph Functional Dependencies Remain as Before DataPrinter
28
St Louis Day of.NET 2011 Reviewing Our Dependency Graph after AOP ConnectionManager DataAccess DoSomeWork Container DataSorter Logger DataPrinter Logger
29
St Louis Day of.NET 2011 Understanding the Mechanics of AOP Advised Type Advice Your Code Type with Advice Applied IoC
30
St Louis Day of.NET 2011 Thinking About Re-Assembly Presto!
31
St Louis Day of.NET 2011 Dependency Injection Frameworks StructureMap Spring.NET Castle Windsor NInject Funq Unity More…
32
St Louis Day of.NET 2011 fini Steve Bohlen Senior Software Engineer SpringSource/VMware E-Mail: sbohlen@gmail.com Blog: http://blog.unhandled-exceptions.com Twitter: @sbohlen http://spkr8.com/t/8097
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.