NetCore (DI)

A: dependence understanding: A class uses to class B, but this relationship has a chance, temporary, very weak, change the class B affects A, (check blog suggestions Park, take a look at what is dependency injection, but said is popular)

II: explicit and implicit dependency dependency:

  Explicit: clearly understood that the use of, eg: in use EF, be dependent on the use of the constructor;

private Customer _context;
public CustomerController()
{
    _context=new CustomerContext(new DbContextOptions<CustomerContext>{});     
}

 

 

Three: Dependency Inversion principle :( dependent on high-level business, does not rely on the underlying implementation)

eg: late replacement in the maintenance of the data access layer, in favor of the kind of underlying database SQLserver when replacement is MySQL, a lot of will to change things a bit, before following the Dependency Inversion Principle, just change EF implementation class.

 

Guess you like

Origin www.cnblogs.com/Arainzhe/p/11707870.html