From what I have read and seen clean architecture assumes that you have some entities which know nothing about persistence though at the same layer as they reside there might be an interface which has a purpose to be a contract on how the entity should be read/updated/deleted.
// project Core
public class CarModel
{
public string Name { get; set; }
public void SomeImportantBehavior {}
}
public interface ICarModelRepository
{
CarModel FindByName(string name);
CarModel Add(CarModel carModel);
}
Meanwhile another layer will hold the implementation of the interface:
// project Infrastructure or Persistence
public class CarModelRepository : ICarModelRepository
{
public CarModel FindByName(string name)
{
return new CarModel { Name = name }; // the implementation is not really important here
}
public CarModel Add(CarModel carModel) {
// somehow persist it here
return carModel;
}
}
So I've got a question: doesn't repository implementation violate the DiP principle? Since it not only depends on abstraction but also on concrete implementation (CarModel
in this case)?
Another example of this is here.
P.S. CarModel is a domain model with behavior
CarModel
class. That is just a choice you made.