concept ProductRepository in category dependency injection

appears as: ProductRepository, ProductRepository
Dependency Injection

This is an excerpt from Manning's book Dependency Injection.

The ASP.NET Core MVC framework then invokes the Index method on the HomeController instance, causing it to invoke the GetFeaturedProducts method on the ProductRepository instance. This in turn calls the GetFeaturedProducts method on the SqlProductRepository instance. Finally, the ViewResult with the populated FeaturedProductsViewModel is returned, and MVC finds and renders the correct view.

Listing 5.2 Newing up a ProductRepository
private readonly IProductRepository repository;

public ProductService()
{
    this.repository = new SqlProductRepository();    #1  
}

#1   An example of the Control Freak anti-pattern, this directly creates a new instance in the constructor, causing tightly coupled code.
Dependency Injection in .NET

This is an excerpt from Manning's book Dependency Injection in .NET.

A common abstraction over data access is provided by the Repository pattern,[8] so I’ll define a ProductRepository abstract class in the Domain Model library:

If told that she could only deal with the abstract ProductRepository class, Mary Rowan (from chapter 2) would introduce a ProductRepositoryFactory that would produce the instances she needs to get the job done. Let’s listen in as she discusses the approach with her colleague Jens—I predict that their discussion conveniently will cover the factory options I listed:

MARY: We need an instance of ProductRepository in this ProductService class. However, ProductRepository is abstract, so we can’t just create new instances of it, and our consultant says that we shouldn’t just create new instances of SqlProductRepository either.
JENS: What about some sort of factory?
MARY: Yes, I was thinking the same thing, but I’m not sure how to proceed. I don’t understand how it solves our problem. Look here...
Figure 5.2. Dependency graph for the proposed solution: a static ProductRepositoryFactory is used to create ProductRepository instances