Is there a framework for dependency injection for poor / lazy designs?

I am new to the DI concept, but I used it to some extent in my projects - mainly by "blowing" interfaces into constructors and creating factories of my specific classes. Well, this is not configuration based, but it never needs to be.

I started learning DI structures like Spring.NET and Castle Windsor, and came across this blog from Ayende.

What I got from this

A) The DI structures are awesome, but B) This means we don’t have to worry about how our system is designed in terms of dependencies.

For me, I'm used to thinking a lot about how to freely connect my system, but at the same time have some control over dependencies.

I'm a little afraid to lose this control, and it's just free for everyone. ClassA requires ClassB = no problem, just ask and you will get! Hmmm.

Or is this just the point, and this is the future, and I should just go with it?

Thoughts?

+3
source share
8 answers

I would not say that you do not need to think about dependencies, but using the IoC structure allows you to change types that satisfy dependencies with little or no hassle, since all postings are made in a central place,

You still need to think about which interfaces you need and what is right for them is not always trivial.

, . , IoC, , , .

+7

OO , , , , DI - , . , :

  • , "":

    IMyClass myclass= new MyClass();

  • , :

    IMyClass myclass= MyClass.Create();

  • , , factory:

    IMyClass myclass= MyClassFactory.Create();

  • factory, - MyClass , :

    IMyClass myclass= (IMyClass) Context.Find( "MyClass" );

  • , . , ? . , setter , . , , .

+9

, , .., , , , .

, , , , , . , .

, .. , , .

.

+3

, , , , , , -, , , , .

, , - ? ! - - ; , , , , . , .

: .

+1

- , , , , , , .

, OO. , , , , .

, , , , , . IOC .

+1

, . , . IOC , app.s

, . , IOC.

+1

. Castle Windsor . , .

Castle Windsor , . , . Castle Windsor XML . , . , , . Castle Windsor , , . , .

, Castle Windsor , , . , .

... . . , , , DI, .

0

DI, , , , . , . . CUD BO.

We are still reviewing the rules, and some of them change every week, while the rest remain unchanged.

0
source

Source: https://habr.com/ru/post/1702782/


All Articles