Dependency Injection in .NET Remigiusz Koczapski http://blog.koczapski.com
Dependency Injection
in .NETRemigiusz Koczapski
http://blog.koczapski.com
Java and Spring Container
Dependency injection
• Dependency Injection
• Poor Man's DI
• Inversion of Control
Props of DI
• Loose coupling
• Setup problem solving
• Lifetime management
• Interception and cross-cutting concerns
Dependencies
• What to inject
• Seams
• Volatile and Stable Dependencies
• Where to inject
• Composition Root
• How to inject
• Register Resolve Release (3-call Pattern)
DI Container Configuration
Code: ManualXML
Code: Auto-wiring
DI Patterns
Method InjectionConstructor Injection
Property Injection Ambient Context
DI Patterns - which to choose
© Mark Seeman – Dependency Injection in .NET
DI Anti-Patterns
Bastard InjectionControl Freak
Constrained Construction Service Locator
DI in ASP.NET MVC
• Custom Controller Factory – Ideal composition root
• Dependency Resolver - Service Locator Anti-Pattern
(with no Release method)
Lifetime Management
• Transient
• Singleton
• Thread
• Request
Interception
• Surrounding invoked method
• Cross-cutting Concerns
• Decorator Pattern
• SRP & OCP
• Aspect Oriented Programming
• Dynamic Interception
© Mark Seeman – Dependency Injection in .NET
DI Containers
• Castle Windsor
• Sprint.NET
• StructureMap
• Autofac
• Ninject
• Mef
• Unity
• Differences
• Registration order
• Lifetime Management names and
options
• Configuration support
• Implementation Binding
• Sequence Binding
• Named Instances