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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:54:22+00:00 2026-06-07T14:54:22+00:00

I am using ASP.NET MVC 3 . I’m still confused as to how much

  • 0

I am using ASP.NET MVC 3.

I’m still confused as to how much can happen in a repository layer. I’ve always been under the assumption that it must just do what is needed and nothing more.

I have always worked with a service layer that in turn calls my repository layer. I always had a corresponding service layer for a repository layer, and a corresponding service layer method for a repository method, even if it just to get a list of items. So I would have the following service layer:

public class UnitService : IUnitService
{
     private readonly IUnitRepository unitRepository;

     public UnitService(IUnitRepository unitRepository)
     {
          this.unitRepository = unitRepository;
     }

     public IEnumerable<Unit> GetAll()
     {
          return unitRepository.GetAll();
     }
}

This is what my repository layer could look like:

public class UnitRepository : IUnitRepository
{
     // Partial code

     public IEnumerable<Unit> GetAll()
     {
          return DbContext.Units
               .Include("Department")
               .OrderBy(x => x.Name);
     }
}

I am trying to reduce my service layer classes if it isn’t really needed. So would it be ok just to call the repository from my controller instead of the service layer? Does it really matter if I do it my way or not? I mean it still brings back all my data.

Where would I do caching and logging? Service layer or in the repository? Let say that the GetAll methods brings back alot of records that needs to be cached. Would I cache this in the repository or would I need a service layer for this?

The same goes for logging. Where would I log stuff like:

Log.Info("Adding category: {0}, {1}", entity.Id, entity.Name);
// adding code
Log.Info("Category added: {0}, {1}", entity.Id, entity.Name);
  • 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-07T14:54:24+00:00Added an answer on June 7, 2026 at 2:54 pm

    If all that your service layer methods do is to delegate the call to the underlying repository method then yes, it is perfectly fine to remove this service layer as it has no added value and directly use the repository from your controller.

    Where would I do caching and logging? Service layer or in the
    repository? Let say that the GetAll methods brings back alot of
    records that needs to be cached. Would I cache this in the repository
    or would I need a service layer for this?

    Caching should be done at the data layer. Depending on how you are doing your data access, ORMs such as NHibernate already include second level cache, so all you have to do is to activate it.

    As far as logging is concerned, you could do that in absolutely every layer of your application that might require logging something.

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

Sidebar

Related Questions

When using ASP.NET MVC plus Entity Framework, and trying to implement a generic repository
Using ASP.NET MVC can be used the view engine Razor. Razor let you use
I have been using ASP.NET MVC 3 for a while to implement a testing
I've been using ASP.NET MVC for personal projects since before it hit RTM. I
I have been using ASP.NET MVC for six months or so and have been
Using ASP.NET MVC's default view engine, you can declare a server-side comment like this:
I am using asp.net mvc and have a section where a user can upload
Using ASP.NET MVC 3, I have been struggling to set the selected value for
Im using asp.net mvc. c# How can i get the existing url (may have
me using asp.net mvc as technology behind. how can i use JavaScript for saving

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.