ioc and mapper in c#

15

Upload: huy-hoang-pham

Post on 14-Jan-2017

24.649 views

Category:

Software


2 download

TRANSCRIPT

Page 1: IoC and Mapper in C#
Page 2: IoC and Mapper in C#

AgendaSOLID Principles

Dependency Inversion, IoC, Dependency InjectionPros and cons of Dependency InjectionApply DI frameworks into MVC project

AutoMapper – What, Why and How

Page 3: IoC and Mapper in C#

SOLID Principles• Single Responsibility• Open/Closed• Liskov Substitution• Interface Segregation• Dependency Inversion

Page 4: IoC and Mapper in C#

Database

Data Access LayerWhich Depends On

Business Logic Layer

Which Depends On

User InterfaceDepends on

DependenciesLower application layers

External servicesOther components

Page 5: IoC and Mapper in C#

Example Code

Page 6: IoC and Mapper in C#

Dependencies Inversion (Principle)

Inversion of Control (Pattern)

Service Locator Event Delegate Dependency

Injection

Page 7: IoC and Mapper in C#

Example Code

Page 8: IoC and Mapper in C#
Page 9: IoC and Mapper in C#

Why Dependency Injection

• Loose coupling code• Testability• Clear dependency• Separate of concern• Easy to change

Page 10: IoC and Mapper in C#

Why NOT Dependency Injection

• Hard to learn• Hard to debug• Object created before needed• More layer => More complexity

Page 11: IoC and Mapper in C#

Simple DI Container

Page 12: IoC and Mapper in C#

IoC in ActionUnity

NinjectStructure Map

Page 13: IoC and Mapper in C#

WhatAn “object to object”

mapper

WhyRemove the boring

mapping code

WhenEntity to DTO

Entity to Data ContactEntity to View Model

Page 14: IoC and Mapper in C#

Before and after

Page 15: IoC and Mapper in C#

Mapper in Action