What is the difference between testing, how is the intensity of dependencies different from static classes / methods?

Besides checking, what is the big advantage of using DI (and I'm not talking about the structure of DI or IoC) over static classes? In particular, for an application in which you know that the service will not be replaced.

In one of our C # applications, our team uses Injection Dependency in the web GUI, service level, and repository layer instead of using static methods. Previously, we would have POCOs (entity objects of business objects) that were created, modified, transferred, and stored by static classes.

For example, in the past we could write:

CreditEntity creditObj = CreditEntityManager.GetCredit(customerId);
Decimal creditScore = CreditEntityManager.CalculateScore(creditObj);
return creditScore;

Now, with DI, the same code will be:

//not shown, _creditService instantiation/injection in c-tors
CreditEntity creditObj = _creditService.GetCredit(customerId);
Decimal creditScore = _creditService.CalculateScore(creditObj);
return creditScore;

, , , , , ( , ). , - ( /-/etc), concurrency, using(...) .

+5
4

D.I. : CreditEntityManager , , a CreditEntity CalculateScore?

, .. , , X, , Y, X Y.

, . , , D.I. , , , ..

, . D.I. , . D.I. , , , , .

+5

. , IDataService, . Oracle nHibernate. , db4o, . Presto! db4o .

+1

There is a Guice video that gives a good example for using DI. If you use a lot of 3 party services that you need to connect to a dynamic DI, it will be a big help.

0
source

All Articles