Please someone help me clarify an issue I'm having with dependency inversion principle. If I have a repository in my DAL that looks like this and an corresponding interface in the DAL. I'm essentially saying to someone that will use my DAL, "here is an interface to use called 'FindEvents', this is my contract via interface. SO the developer knows not to use the object directly but to use my interface. I could even make the object private and only expose the interface as public
DAL -
public class YogaSpaceEventRepository : IYogaSpaceEventRepository
{
public IQueryable<YogaSpaceEvent> FindEvents(DateTime start, DateTime end)
{
// Retrieve Data from Database
}
}
public interface IYogaSpaceEventRepository : IDisposable
{
// here my repo (data access layer) is referencing my business layer to return YogaSpaceEvent
IQueryable<YogaSpaceEvent> FindEvents(DateTime start, DateTime end);
}
But if I take out this interface and stick it in the BLL (DDD method), so that I can avoid circular references (DAL needs to reference BLL to understand the object 'YogaSpaceEvent' that it's returning and somewhere in my BLL I need to call FindEvents - now it's circular). This totally breaks the rule of interfaces!? Because now if the DAL developer hands over the DAL assembly, you as a developer using that DAL assembly won't know what can be changed or not (no contract - no interfaces in the DAL)!
By putting
public interface IYogaSpaceEventRepository : IDisposable
{
// here my repo (data access layer) is referencing my business layer to return YogaSpaceEvent
IQueryable<YogaSpaceEvent> FindEvents(DateTime start, DateTime end);
}
aren't you breaking the one rule of an interface?? Which is a contract - the dev of the DAL can't say here is my library and I'm only guaranteeing what's in this interface. NOW there is no interface, hence no contract.
Please someone give me some feedback here!