Inversion of Control (IoC)
in
ASP.NET MVC
C# Corner-Delhi ChapterNOV 7, 2015
IoC
?
DI
?
MVC
?
What we are going to talk about:
• How to Invert the Control of Dependencies
…in ASP.NET MVC
What we are going to talk about:
• “How to Invert the Control of Dependencies in
ASP.NET MVC”
SOLID Principles
S : Single Responsibility Principle
O : Open/Closed Principle
L : Liskov Substitution Principle
I : Interface Segregation Principle
D : Dependency Injection
D : Dependency Injection
“Depend upon Abstractions. DO NOT depend on
Concrete Implementations”
Dependency Injection
• Constructor Injection
• Setter Injection
• Interface Injection
IoC (Inversion of Control)
- Isn’t a design pattern
- Is a process of inverting the control
- Helps implementing Dependency Injection
Inversion of Control
• Interface Inversion
• Flow Inversion
• Creation Inversion
IoC Container
Dependency A
IoC Container
Dependency B
IDependency
MyClass
IoC Container
MasterCard
IoC Container
Visa
ICreditCard
Shopper
without IoC
Battery
Wall Outlet
Solar Cell
Power Source
Laptop
IoC
Container
Laptop
Mapping
IPowerSource ->Battery
…..
…..
With IoC
Battery
Route Handler
ASP.NET MVC Request
View
Request
Controller
Model
MvcHandler
How Controllers are created
Controller
Request
ControllerFactory
IControllerFactory
DefaultControllerFactory
Let’s build a Custom Controller Factory!
So many flavors… which one to choose?
< me />
Sunny Sharma
• Trainer / Author / Speaker
• corp.sunnykumar@gmail.com
• Twitter: @sunny_delhi
Thank You!

Inversion of Control in MVC