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

  • Home
  • SEARCH
  • 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 1023011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:33:02+00:00 2026-05-16T11:33:02+00:00

most of the time in the service code I would have something like this:

  • 0

most of the time in the service code I would have something like this:

public SomeService : ISomeService
{
    ISomeRepository someRepository;
    public Do(int id)
    {
        someRepository.Do(id);
    }
}

so it’s kinda redundant

so I started to use the repositories directly in the controller

is this ok ? is there some architecture that is doing like this ?

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

    You lose the ability to have business logic in between.

    I disagree with this one.

    If business logic is where it should be – in domain model, then calling repo in controller (or better – use model binder for that) to get aggregate root and call method on it seems perfectly fine to me.

    Application services should be used when there’s too much technical details involved what would mess up controllers.


    I’ve seen several people mention using model binders to call into a repo lately. Where is this crazy idea coming from?

    I believe we are talking about 2 different things here. I suspect that Your ‘model binder’ means using model simultaneously as a view model too and binding changed values from UI directly right back to it (which is not a bad thing per se and in some cases I would go that road).

    My ‘model binder’ is a class that implements ‘IModelBinder‘, that takes repository in constructor (which is injected and therefore – can be extended if we need caching with some basic composition) and uses it before action is called to retrieve aggregate root and replace int id or Guid id or string slug or whatever action argument with real domain object. Combining that with input view model argument lets us to write less code. Something like this:

    public ActionResult ChangeCustomerAddress
     (Customer c, ChangeCustomerAddressInput inp){
      c.ChangeCustomerAddress(inp.NewAddress);
      return RedirectToAction("Details", new{inp.Id});
    }
    

    In my actual code it’s a bit more complex cause it includes ModelState validation and some exception handling that might be thrown from inside of domain model (extracted into Controller extension method for reuse). But not much more. So far – longest controller action is ~10 lines long.

    You can see working implementation (quite sophisticated and (for me) unnecessary complex) here.

    Are you just doing CRUD apps with Linq To Sql or trying something with real domain logic?

    As You can (hopefully) see, this kind of approach actually almost forces us to move towards task based app instead of CRUD based one.

    By doing all data access in your service layer and using IOC you can gain lots of benefits of AOP like invisible caching, transaction management, and easy composition of components that I can’t imagine you get with model binders.

    …and having new abstraction layer that invites us to mix infrastructure with domain logic and lose isolation of domain model.

    Please enlighten me.

    I’m not sure if I did. I don’t think that I’m enlightened myself. 🙂


    Here is my current model binder base class. Here’s one of controller actions from my current project. And here’s “lack” of business logic.

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

Sidebar

Related Questions

For a particular segment of Java code, I'd like to measure: Execution time (most
I would like to hide the UISearchBar most of the time and only call
I have a Windows Service and I would like to see what it's doing
Most of time we represent concepts which can never be less than 0. For
Most of the time, I've seen release management handled as a defined process with
Spending most of my time in Visual Studio and using all the IDE tools,
As I put together each asp.net page It's clear that most of the time
I've got 2 monitors, and most of the time I've got some reference material
I've got a php script. Most of the time the script returns html, which
When running PHP in CLI mode, most of the time (not always), the script

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.