ioc and mapper in c#
TRANSCRIPT
AgendaSOLID Principles
Dependency Inversion, IoC, Dependency InjectionPros and cons of Dependency InjectionApply DI frameworks into MVC project
AutoMapper – What, Why and How
SOLID Principles• Single Responsibility• Open/Closed• Liskov Substitution• Interface Segregation• Dependency Inversion
Database
Data Access LayerWhich Depends On
Business Logic Layer
Which Depends On
User InterfaceDepends on
DependenciesLower application layers
External servicesOther components
Example Code
Dependencies Inversion (Principle)
Inversion of Control (Pattern)
Service Locator Event Delegate Dependency
Injection
Example Code
Why Dependency Injection
• Loose coupling code• Testability• Clear dependency• Separate of concern• Easy to change
Why NOT Dependency Injection
• Hard to learn• Hard to debug• Object created before needed• More layer => More complexity
Simple DI Container
IoC in ActionUnity
NinjectStructure Map
WhatAn “object to object”
mapper
WhyRemove the boring
mapping code
WhenEntity to DTO
Entity to Data ContactEntity to View Model
Before and after
Mapper in Action