taming dependency chaos with inversion of control containers

Post on 23-Feb-2016

36 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

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. Do I suck?. Let me (and the world) know!. http://spkr8.com/t/8097. Who am I?. - PowerPoint PPT Presentation

TRANSCRIPT

St Louis Day of .NET 2011

Taming Dependency Chaoswith Inversion of Control Containers

Steve BohlenSenior Software EngineerSpringSource/VMware

E-Mail: sbohlen@gmail.comBlog: http://blog.unhandled-exceptions.comTwitter: @sbohlen

St Louis Day of .NET 2011

Do I suck?Let me (and the world) know!

http://spkr8.com/t/8097

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

St Louis Day of .NET 2011

Steve BohlenNearly 20 years developing softwareLISP, Delphi, C/C++, VB, VB.NET, C#Senior Engineer Springsource/VMwareCo-Founder, NYC Alt.Net User Group

http://nyalt.netCo-Organizer, NYC DDD User Group

http://dddnyc.orgContributor: various OSS projects

Nhibernate http://www.nhforge.orgNDbUnit http://www.googlecode.com/ndbunitSpring.NET http://www.springframework.net

blog: http://blog.unhandled-exceptions.come-mail: sbohlen@gmail.comtwitter: @sbohlen

CYND D D

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

St Louis Day of .NET 2011

St Louis Day of .NET 2011

St Louis Day of .NET 2011

St Louis Day of .NET 2011

How much can you keep in your Head?

St Louis Day of .NET 2011

Our Application (or class, or method, etc.)

St Louis Day of .NET 2011

First Attempt at Decomposition

Components!

St Louis Day of .NET 2011

Ideal Decomposition Level

Units!

St Louis Day of .NET 2011

The Challenge:Turning this into something useful

Decomposition carries overhead…

…of re-composition for meaningful work!

St Louis Day of .NET 2011

…easily!

The Goal:Units Assembled into Something Useful…

St Louis Day of .NET 2011

Code Demo: Refactoring for Decomposition

St Louis Day of .NET 2011

Reviewing Our Dependency Graph after Decomposition

Logger

ConnectionManager

DataSorter

Logger

Logger

Logger

DataAccessWorker

DataPrinter Logger

St Louis Day of .NET 2011

Code Demo: Refactoring to Ease (Re-)Composition

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 BeforeDataPrinter

St Louis Day of .NET 2011

Aspect-Oriented Programming (AOP)

St Louis Day of .NET 2011

(one of) The Challenges ofOO 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

St Louis Day of .NET 2011

Example: Logging by Inheritance

public abstract class LoggingBase{ protected void Log(string msg) {…}} Public class Service1 : LoggingBase {…}

Public class Service2 : 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

St Louis Day of .NET 2011

Public class Service1{ public Service1 (Logger logger) { _logger = logger; }}

Example: Logging by Dependency Injection

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

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)

St Louis Day of .NET 2011

Understanding AOP Terms

Cross-Cutting Concernsthe ‘problem’ we want to solve

Advicecode that solves the problem

Pointcutwhere to apply the Advice

AspectPointcut + Advice = Aspect

St Louis Day of .NET 2011

Code Demo: Defining and Applying Aspects

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 BeforeDataPrinter

St Louis Day of .NET 2011

Reviewing Our Dependency Graph after AOP

ConnectionManager

DataAccess

DoSomeWork

Container

DataSorter

Logger

Logger

Logger

Logger

DataPrinter Logger

St Louis Day of .NET 2011

Understanding the Mechanics of AOP

Advised Type Advice

Your Code

Type with Advice Applied

IoC

St Louis Day of .NET 2011

Thinking About Re-Assembly

Presto!

St Louis Day of .NET 2011

Dependency Injection Frameworks• StructureMap• Spring.NET• Castle Windsor• NInject• Funq• Unity• More…

St Louis Day of .NET 2011

fini

Steve BohlenSenior Software EngineerSpringSource/VMware

E-Mail: sbohlen@gmail.comBlog: http://blog.unhandled-exceptions.comTwitter: @sbohlen

http://spkr8.com/t/8097

top related