Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:21:51+00:00 2026-06-10T19:21:51+00:00

Take the scenario where you have the following application: An MVC 4 Web App

  • 0

Take the scenario where you have the following application:

  • An MVC 4 Web App
  • The application talks to an existing database via Entity Framework 5
    (with no plans to change to another ORM or database platform).
  • The application talks to an external SOAP Web Service (the webservice
    may change to WCF).

Would you:

  1. Create a generic repository for all the EF entities (e.g.
    MyDBRepository), and a repository for the SOAP Web Services calls
    (E.g. MyWSRepository). Then create a service class that contains the
    business logic uses the two repositories to access data and
    implements CRUD methods for all the controller’s needs
    (MyApplicationService). Then have the repositories injected into
    the service class, and finally the service class injected into the
    MVC controller.

  2. Or would you have one service class that handles the db queries and
    business logic using the EF generated DBContext and the generated
    table entities (e.g. MyDBService), and another service class that
    handles the business logic and SOAP web service calls (e.g.
    MySOAPWebService). Then have both services injected into the MVC
    Controllers.

  3. Or something else.

In the past I’ve worked with option 1. But I’m wondering if that is just adding unnecessary layers of abstraction. If the Entity Framework generates a DBContext, having a service class that uses the DBContext entities directly seems to be less complex.

Having read through several articles and other questions in StackOverflow, it seems like there is a grey line differentiating the Service Locator pattern and Repository Pattern.

Which structure would you use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:21:52+00:00Added an answer on June 10, 2026 at 7:21 pm

    I recommend a repository or DAO for each aggregate. make these classes receive the dbContext on the constructor (or unit of work if you prefer).

    Then make your service implement the business logic and use the DAOs. The service is responsible for instantiating the DBContext (and a transaction if you require one). Services then call different DAOs with the same context.

    For a more strong decoupling I strongly recommend that you make impossible for the service layer to touch the DBContext. Force yourself to go through the DAOs every time.

    The service layer should also deal with exceptions. In my applications the service layer only throws 2 types of exception: user and system. On the controllers i use them to tell apart a recoverable error or something else. ( that’s why you sometimes see specif errors like “invalid order number” or something else like “An error occurred in the system, try again later”)

    Btw, never forget to work with disconnected entities. when you call your repositories for add/update always assume the POCO’s are disconnected and work with them accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a scenario, I have a ASP.NET MVC application with URLs that look like
I have the following scenario: I have a database with a particular MyISAM table
I am developing a web application where i have database backend with geo located
I have the following scenario: User X logs in to the application from location
I have a problem getting the following scenario to work. A student can take
I have the following scenario: Program P (can take upto 30 minutes to complete)
Present Scenario : I have a set of classes that all take a common
I have a generic question about scope and encapsulation. Take two scenarios: Scenario 1:
Take the following scenario: Public Class Store Public Overridable Property Areas As List(Of Area)
We are using TFS for team builds and have a scenario where our application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.