How far to go with IoC

I was wondering how far I have to implement my IoC implementation in terms of weak connection of my application. I use the constructor installation in my MVC controller, but I wonder if I should also resolve all my other dependencies in the controller instead of new objects. For example, if I were to create a new User object in a controller method, would I use?

var user = new User();
var user = myContainer.Resolve<IUser>();

I like the idea of ​​breaking my user dependency, but is it too far and can make my code more difficult to read?

+3
source share
1 answer

This is a very good question when you read and hear about DI, it makes sense, and this is the next natural conclusion.

, . IUser " ", , Factory.

.

, .

:

, , , , :

?

Application Configuration
System Resources (Clock)
Third Party Libraries
Database
WCF/Network Services
External Systems (File/Email)

. , (/) DI.

, DI?

List
MemoryStream
Strings/Primitives
Leaf Objects/Dto's

, , , IUser , . , , .

, , User(), , - , IoC.

:

Dependency graph

. , , .

dto, , IoC, , .

+5

All Articles