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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:03:55+00:00 2026-05-23T19:03:55+00:00

I’m working on a model for an ASP.NET MVC app with DI and an

  • 0

I’m working on a model for an ASP.NET MVC app with DI and an ORM.

Lately, I’ve been looking into the pros and cons of writing all my business logic in a service layer vs placing logic specific to an entity in the entity class itself. Methods declared in the entity classes are obviously called on a specific instance of the entity and can therefore only be called when that instance has been instantiated from a query to the ORM.

Let’s say I have a Product entity and I declare an ApplyDiscount method on it. Given an ID of a product passed in from a controller’s action method, I must first query for an instance of the product using this ID and then call the ApplyDiscount method. But where should the querying code take place? Is it a valid practice to declare a method in my service layer which takes an ID, queries for the Product instance, and then calls ApplyDiscount on that instance? Or should that code go somewhere else?

Ultimately, I’d like to know if having querying code in the service layer and having modification- code of the resulting entities in the entity classes themselves is the common / correct implementation when attempting to avoid a fat service layer & anemic domain model.

Does having the querying code in the service layer defeat the purpose altogether?

  • 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-23T19:03:56+00:00Added an answer on May 23, 2026 at 7:03 pm

    It doesn’t defeat the purpose, but you’re ending up migrating functionality (specifically, validation) into the service layer where it shouldn’t necessarily be.

    Generally, you’d want for the validation to occur at the earliest possible point; that is, if you’ve been given an invalid ID, you want to make sure that you’ve caught that invalid condition before starting an execution chain all through your logic. Typically, this means performing the query in the controller and passing the resultant object through your service layer; this isolates the functionality of querying up to a high level in your execution chain, and prevents you from having to implement high-level exclusion logic in your service layer (for example, if an entire set of IDs is invalidated, you can perform that validation outside of your service layer, thereby isolating that associated logic and keeping you from needing to do that inside your service layer.

    In general, consider the approach to be this: perform object-level validation and deserialization at the earliest point of reference, to migrate your logic as far up out of your service layer as possible, and thereby “thin up” your service layer. There’s a certain amount of flexibility involved here, of course, but as a general rule, it’s a good one.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am writing an app with both english and french support. The app requests
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am currently running into a problem where an element is coming back from

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.