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 6074919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:26:10+00:00 2026-05-23T10:26:10+00:00

From inside to outside, these are our MVC app layers: MS SQL / Tables

  • 0

From inside to outside, these are our MVC app layers:

  1. MS SQL / Tables / Views / Stored Procs
  2. Entity Framework 4.1 (ORM) with POCO generation
  3. Repository
  4. Service (retrieve) and Control Functions (Save)
  5. Routing -> Controller -> Razor View
  6. (client) JQuery Ajax with Knockout.js (MVVM)

Everything is fine until I need to create a single ViewModel for step 5 to feed both the Razor view as well as the JSON/Knockout ViewModel:

  • Header that includes all Drop down list options and choices for the fields below
  • Items – an array of whatever we send to the client that becomes the ViewModel

Since the Controller won’t have access to the Repository directly, does this mean I create a service for each and every view that allows editing content? I’ll need to get the POCO from the repository plus all options for each field type as needed.

It just seems redundant to create separate services for each view. For example, a viewModel to edit an address and a separate viewModel to edit a real estate property that also has an address. We could have a dozen forms that edit the same address POCO.

To make this question easier to answer, is allowing the Controller direct access to the repositories a leaky abstraction?

  • 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-05-23T10:26:11+00:00Added an answer on May 23, 2026 at 10:26 am

    Well, so are your controllers going to have code that translates POCOs from Entity Framework into separate view model objects?

    If so, then you should move that code to a separate class, and follow the single-responsibility principle. Whether that class is in the “service layer” or not is up to you. And whether you use AutoMapper or not is up to you. But these kind of data mappers should not be part of the controller logic; controllers should be as dumb as possible.


    OK, now let’s ignore the data mapping problem, and pretend you could always use your POCOs directly as view models. Then you would still want a service layer, because it would translate between

    userService.GetByUserName("bob")
    

    in your dumb controller, and implement that in a specific manner by returning

    userRepository.Users.Single(u => u.UserName == "bob")
    

    Putting these together, your UserController ends up taking in IUserService and IUserDataMapper dependencies, and the code is super-dumb, as desired:

    public ActionResult ShowUserPage(string userName)
    {
        var user = userService.GetByUserName(userName);
        var viewModel = userDataMapper.MakeViewModel(user);
    
        return View(viewModel);
    }
    

    You can now test the controller with stubs for both dependencies, or stub out IUserDataMapper while you mock IUserService, or vice-versa. Your controller has very little logic, and has only one axis of change. The same can be said for the user data-mapper class and the user service class.


    I was reading an article this morning that you might find somewhat illuminating on these architectural matters. It is, somewhat condescendingly, titled “Software Development Fundamentals, Part 2: Layered Architecture.” You probably won’t be able to switch from a database application model to the persistent-ignorant model the article describes and suggests. But it might point you in the right direction.

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

Sidebar

Related Questions

If you throw an exception from inside an MFC dialog, the app hangs, even
In my SWT Java app I often want to return information from inside a
The goal: To create a .NET dll i can reference from inside SQL Server
How do I call shell commands from inside of a Ruby program? How do
I'm firing off a Java application from inside of a C# .NET console application.
Given the following code snippet from inside a method; NSBezierPath * tempPath = [NSBezierPath
Is it possible to write a GUI from inside a function? The problem is
Is it possible to gather performance statistics programmatically from inside a WCF application? For
I need a way of calling a web page from inside my .net appliction.
How do you call a client codes methods from inside a class defined in

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.