Top Banner
Inversion of Control (IoC) in ASP.NET MVC C# Corner-Delhi Chapter NOV 7, 2015
21

Inversion of Control in MVC

Jan 19, 2017

Download

Education

Sunny Sharma
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Inversion of Control in MVC

Inversion of Control (IoC)in

ASP.NET MVC

C# Corner-Delhi ChapterNOV 7, 2015

Page 2: Inversion of Control in MVC

IoC?

Page 3: Inversion of Control in MVC

DI?

Page 4: Inversion of Control in MVC

MVC?

Page 5: Inversion of Control in MVC

What we are going to talk about:

• How to Invert the Control of Dependencies

…in ASP.NET MVC

Page 6: Inversion of Control in MVC

What we are going to talk about:

• “How to Invert the Control of Dependencies in ASP.NET MVC”

Page 7: Inversion of Control in MVC

SOLID PrinciplesS : Single Responsibility PrincipleO : Open/Closed PrincipleL : Liskov Substitution PrincipleI : Interface Segregation PrincipleD : Dependency Injection

Page 8: Inversion of Control in MVC

D : Dependency Injection“Depend upon Abstractions. DO NOT depend on Concrete Implementations”

Page 9: Inversion of Control in MVC

Dependency Injection• Constructor Injection• Setter Injection• Interface Injection

Page 10: Inversion of Control in MVC

IoC (Inversion of Control)- Isn’t a design pattern- Is a process of inverting the

control- Helps implementing Dependency

Injection

Page 11: Inversion of Control in MVC

Inversion of Control• Interface Inversion• Flow Inversion• Creation Inversion

Page 12: Inversion of Control in MVC

IoC ContainerDependency A

IoC Container

Dependency B

IDependency

MyClass

Page 13: Inversion of Control in MVC

IoC ContainerMasterCard

IoC Container

Visa

ICreditCard

Shopper

Page 14: Inversion of Control in MVC

without IoC

Battery

Wall Outlet

Solar Cell

Power Source

Laptop

Page 15: Inversion of Control in MVC

IoC Container

Laptop

Mapping

IPowerSource ->Battery…..…..

With IoC

Battery

Page 16: Inversion of Control in MVC

Route Handler

ASP.NET MVC Request

View

Request

Controller

Model

Page 17: Inversion of Control in MVC

MvcHandler

How Controllers are created

Controller

Request

ControllerFactory

IControllerFactory

DefaultControllerFactory

Page 18: Inversion of Control in MVC

Let’s build a Custom Controller Factory!

Page 19: Inversion of Control in MVC

So many flavors… which one to choose?

Ninject

Unity

AutoFac Funq

LinFu

Spring.Net Windsor

StructureMapMany more…

Page 20: Inversion of Control in MVC

< me />Sunny Sharma• Trainer / Author / Speaker

[email protected]

• Twitter : @sunny_delhi

Page 21: Inversion of Control in MVC

Thank You!