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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:00:10+00:00 2026-05-16T07:00:10+00:00

My controllers are getting large and out of hand. A typical controller does the

  • 0

My controllers are getting large and out of hand.

A typical controller does the following:

  • It determines whether a given user has access to a given resource.
  • It validates the ViewModel.
  • It translates the ViewModel into the DTOModel for persistence.
  • It calls repositories to update/create new objects and associated other new objects.
  • It accesses data in multiple repository helper classes
  • It checks whether users get notifiied.
  • It calls helpers to send emails
  • It logs data to the database via other repository objects
  • etc…

In short, they ORCHESTRATE a lot of things. I’d like to move everything into a Services layer, but haven’t really seen any implemented patterns in code samples that I like. I’ve looked at some of the open source projects like KiGG, Oxite, codecampserver, etc…but none of them are really solving the problem of shrinking my Controllers. I’d like to avoid passing around a lot of the HTTPContext stuff, but maybe this isn’t possible.

Are there some other projects, best-practices I could be looking at? I’m building a large workflow/data input application.

Thanks for some links and suggestions

  • 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-16T07:00:11+00:00Added an answer on May 16, 2026 at 7:00 am

    I don’t know of any real examples to show off the top of my head, because I think I came up with my MVC apps’s controller -> service -> repository layering scheme based on random questions and answers I found by browsing SO.

    However, what I can give you is an example of how to organize the bullets you listed into how it would fit in the way I’ve structured my service layer. This may not be the best way, but this is how I’m doing my large-scale mvc app. This should give you an idea how to structure it in your own application

    My service layer combines one service class per business unit. So if my application has projects, and each project has a person I would have a ProjectService class and a PersonService class.

    Based upon your description of how your controllers work, my controller’s actions work in the following way.

    1) Get the current user’s information and call the appropriate service class’s authorization method. So if the user is trying to modify a project’s details, I would pass the user ID and project ID to the ProjectService’s AuthorizeUser method. This means if I change the way I authorize users for projects I only have to change the authorization method and not every controller.

    2) Viewmodels are created, saved, and destroyed in the service layer. The service layer takes the viewmodel, validates it (raises an exception or validation result if it fails), and then converts it into a data object, which it will then pass to the repository for saving. It also requests the data object from the repository, converts it into a viewmodel and returns it down to the controller.

    3) Logging of all actions occurs in the service layer. This can be automatic based on the action being presented (attempting to save an object to the db) or your controller can explicitly call the service layer to log the action.

    The whole point of this is to consolidate common functionality into an easily maintainable layer. If you change how your viewmodel converts into a DTO, it is VERY easy to know where to make the change and to make it once. If you need to change your logging, user access, or even if you want to change how you retrieve certain data from the repositories it is one simple area to change rather than having to hunt down all your controllers and modify them directly.

    Edit: This keeps controllers small as they only really contain a few calls to the service layer and that’s it (Authorize, perform action, Show View). End Edit

    Finally, the asp.net website has a tutorial for performing validation in a service layer. That tutorial can be found here.

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

Sidebar

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.