Top Banner
Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver
19

Strengths and weaknesses of dependency injection

Jan 21, 2018

Download

Technology

Dennis Doomen
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: Strengths and weaknesses of dependency injection

Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver

Page 3: Strengths and weaknesses of dependency injection
Page 4: Strengths and weaknesses of dependency injection

Order Processing

IOrderRepository

NhibernateOrderRepository

Storage

RavenDBOrderRepository

Storage Storage

In-memory Repository

Bookkeeping

Diagnostics Decorator

Diagnostics Decorator

Strategy Selection

Allow Test-time dependencies

Inject dependencies from different

modules

Control lifecycle (e.g. per http request,

singleton, etc)

Inject Cross-cutting Concerns

Promote depending on abstractions

Page 5: Strengths and weaknesses of dependency injection
Page 6: Strengths and weaknesses of dependency injection
Page 7: Strengths and weaknesses of dependency injection
Page 8: Strengths and weaknesses of dependency injection
Page 9: Strengths and weaknesses of dependency injection
Page 10: Strengths and weaknesses of dependency injection
Page 11: Strengths and weaknesses of dependency injection
Page 12: Strengths and weaknesses of dependency injection
Page 13: Strengths and weaknesses of dependency injection
Page 14: Strengths and weaknesses of dependency injection

Order Processing

IStoreOrders<T>+ CreateQuery<T>();+ Add<T>();+ Delete<T>();

NHibernateRepository

Order Processing

IStoreOrders+ GetIncompletedOrders(minValue);+ StoreOrder();+ CompleteOrder();

OrderRepository

VS

Page 15: Strengths and weaknesses of dependency injection
Page 16: Strengths and weaknesses of dependency injection

• Don’t use the Service Locator pattern

• Use container only at the root…

• …so don’t use the container as a dependency

• Constructor injection only

• Pass local dependencies to methods

• Avoid container-specific dependencies

• Use delegates for factories, indexes, etc.

• Include registrations in at least one test

• Use types explicitly in registrations

• Let the container handle the life cycle

• Access date & time through delegate

• Avoid configuration-based setup (e.g. XML).

Page 17: Strengths and weaknesses of dependency injection
Page 18: Strengths and weaknesses of dependency injection

System

Package

Package

Package

PackagePackage

Package

Maybe

Probably not

Probably yes

TinyIoc

Autofac