c# in 20 minutes: dependency injection

10
C# in 20 Minutes Dependency Injection Thomas Mentzel blog.softwarekueche.de

Upload: thomas-mentzel

Post on 24-Apr-2015

155 views

Category:

Technology


2 download

DESCRIPTION

A brief introduction into dependency injection with C#. Due to the complexity the 20 minute talk just scratches at the surface.

TRANSCRIPT

Page 1: C# in 20 Minutes: Dependency Injection

C# in 20 MinutesDependency Injection

Thomas Mentzelblog.softwarekueche.de

Page 2: C# in 20 Minutes: Dependency Injection

How to explain dependency injection to a 5-year old?

• When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn't want you to have. You might even be looking for something we don't even have or which has expired.

• What you should be doing is stating a need, "I need something to drink with lunch," and then we will make sure you have something [proper] when you sit down to eat.

StackOverflow (http://bit.ly/1mBlD78)

Page 3: C# in 20 Minutes: Dependency Injection

TemplateEditor right now…

Page 4: C# in 20 Minutes: Dependency Injection

…refactors to Interfaces…

Page 5: C# in 20 Minutes: Dependency Injection

… and ends up withDependency Injection

Page 6: C# in 20 Minutes: Dependency Injection

Dependency Injection Container

Page 7: C# in 20 Minutes: Dependency Injection

Injection Methods

• Constructor Injection– constructor parameter– required dependencies

• Property Injection– properties/setter– optional parameter– null-object pattern

Page 8: C# in 20 Minutes: Dependency Injection

Supportive Frameworks

• Caliburn Micro for WPF

• ASP.NET MVC Built-In

• Prism for Silverlight• …and many many more

Page 9: C# in 20 Minutes: Dependency Injection

You should know …

• … what Dependency Injection is

• … what a DI Container is• … what the difference between

Constructor Injection and Property Injection is

• … what inversion of control means• … when to use Dependency Injection

Page 10: C# in 20 Minutes: Dependency Injection

Fragen?!

• Thomas Mentzel• blog.softwarekueche.de• [email protected]

• @ThomasMentzel

• Google: Thomas Mentzel, Hennef