0

so, I have this:

  1. Web App
  2. Business Logic
  3. Data Access Logic

I created in the data access logic, the entities, the context, the initializer.

SO usually the higher layers, call the lower layer functionality, right?

If I want to save a customer, I want to create a Customer entity from the web app. What I dont like is having a direct reference from the web app layer to the data access logic layer (class library)

any idea?

Luis Valencia
  • 32,619
  • 93
  • 286
  • 506

2 Answers2

1

I know this probably isn't very constructive but if I was you I would just add the reference. There no point making things harder on your self to find a more complicated way to do something which should be easy. plus if you skip it now and come across a better solution later you can just modify your code.

MDL
  • 261
  • 2
  • 12
  • 23
0

This is how i did it on a previous project

4 Projects under my Solution

1) UI ( my ASP.NET MVC Application)

2) Business Entities ( My POCOS's for Entities like Customer, Order etc..)

3) Business Logic ( My Inermediate Service Layer which stays in between UI and DataAccess layer. I would do my business specific validations here.

4) The Data Access Layer. Talks to my database. Can be EF / pure ADO.NET Stored Proc etc..

  • DataAccessLayer Project has references of Business Entities Project
  • Business Logic Project has refereces of Business Entities Project
  • UI Project has refereces of Business Entities Project and BusinessLogic.

From UI, I call methods of Middle Layer (Business Logic) and from there after doing custom validations / business rules, i would call Data Access Layer methods.

Shyju
  • 214,206
  • 104
  • 411
  • 497
  • what is the pros and cons when you expose your Business Entities to all layers instead of write customized data transfer objects in your service layer ? does your UI layer have ability to access the DB access object ? – Timeless May 07 '12 at 16:15
  • @null: In the above approach, The Data Acces Layer returns the loaded Business objects. ex : for a GetUser method, it returns a User Entity object defined in Business Entity project, like an ORM. These objects represents almost same as the db entities. For Customized UI entities, I would use ViewModels. – Shyju May 07 '12 at 16:56
  • My solution is a generatlized version which supports non -Entity framework scenario as well. If im using EF, i dont create the POCO in my business objects. I use those and map those to my ViewModel in mapping layer – Shyju May 07 '12 at 17:39