0

This is pulled from a stackoverflow link

"The DAL should have no knowledge at all about the Business Logic Layer. It should, in theory, be able to be called from any client. For example, what if you wanted to seperate the DAL from the application and deploy it as a seperate service exposing itself via WCF?"

That is what I want to do with my dal but I currently have a repository that looks like this..

public class YogaSpaceEventRepository : IYogaSpaceEventRepository
{
    public IQueryable<YogaSpaceEvent> FindEvents(DateTime start, DateTime end)
    {
    // Retrieve Data from Database
    }
}

The 'YogaSpaceEvent' entity is being referenced from the business logic layer. What pattern/architecture do I use to remove this to achieve decoupling so that I can use the data access layer by another service (ex. WCF) without needing to reference anything from the business layer?

Community
  • 1
  • 1
chuckd
  • 13,460
  • 29
  • 152
  • 331
  • Is the The 'YogaSpaceEvent' entity defined in your DAL? Then it is decoupled because the Business Layer consumes the DAL service and the DAL can be re-used by any other consumers without referencing the BL. –  Mar 23 '15 at 06:20
  • I'm not sure I understand your logic here. The 'YogaSpaceEvent' is defined in the business layer and the DAL references the business layer. In order to use the DAL you have to reference the business layer so that it recognizes the 'YogaSpaceEvent' entity, therefor making the business layer and the DAL coupled. Am I missing something here? – chuckd Mar 23 '15 at 06:28
  • I couldn't go and use the DAL somewhere else in some other solution without the business layer...so it's coupled! – chuckd Mar 23 '15 at 06:30
  • Yes that is wrong that the DAL is dependent on the BL. You must either place your entities in a separate project or make it part of your DAL implementation. What you also can do is to make use of interfaces. Thus the DAL only works on interface contracts but that will be extra work because each consumer would need to implement the entities individually. –  Mar 23 '15 at 06:32
  • Currently my entities are in the BLL, not the DAL. But based on what you say I thought the correct approach would be to create a DAL that isn't dependent on anything! That way you can use it in another project that might use it in a WCF service or something without the need to copy the entities over as well. – chuckd Mar 23 '15 at 06:37
  • The DAL needs to expose some kind of entity or interface for entities, that is if you use some ORM implementation. Since the DAL expose this as part of its service, the DAL is the owner of the entities and not the BL. Unless you want the DAL to make use of DataTables/DataSets which is not utilizing the ORM implementation. –  Mar 23 '15 at 06:41
  • I'm using EF as my ORM, but can't you create some generic repo that returns objects or something generic? so that the repo (DAL) never is dependent on the BL objects? – chuckd Mar 23 '15 at 07:00

0 Answers0