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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:25:28+00:00 2026-05-10T20:25:28+00:00

I have just started to look at .NET 3.5 so please forgive me if

  • 0

I have just started to look at .NET 3.5 so please forgive me if this type of question have been asked before. I am struggling with a decent usage for extension methods, in that I have just downloaded suteki shop an MVC ecommerce offering. In this project there is a pretty standard Repository pattern that extends IRepository.

In order to extend the basic functionality exposed by this interface, extention methods are used i.e.:

public static class CategoryRepositoryExtensions {     public static Category GetRootCategory(this IRepository<Category> categoryRepository)     {      return categoryRepository.GetById(1);     } } 

Now this is all well and good, but Interfaces, as far as I am concerned act as contracts to the objects that implement them.

The fact that the repository has been interfaced out suggests an attempt at a data layer agnostic approach. That said, if I were to create my own data layer I would be confused as to what extension methods I would have to create to ensure I have fulfilled the contractual requirement I have to the classes that implement my repository classes.

It seems that the older way of creating an IRepository and then extending that allows a much better visibility of what is required e.g.

ICategoryRepoitory : IRepository<Category> {      Category GetRootCategory(); } 

So I guess my question is does this use of Extention methods seem wrong to anyone else? If not, why? Should I not be moaning about this?

EDIT:

The above example does seem to be a good example of why extention methods can be very helpful.

I suppose my issue is if data access specific implementations were stuck in the extention method in the data access mechanisms assembly.

That way if I were to swap it out for another mechanism I would have to create a similar extention method in that assembly.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T20:25:29+00:00Added an answer on May 10, 2026 at 8:25 pm

    The point is that if you’ve implemented all of IRepository<T> appropriately, you (as the data layer implementor) don’t have to know about root categories at all. For the scope of this extension method, it is assumed that any repository of categories will have a root category of ID 1. That may well be a perfectly reasonable assumption, and a useful one: no-one has to build a derived class (which may well be impractical – the data layer may have factories etc which make it tricky to derive from the implementations).

    Now, the extension method is only applicable if its scope is appropriate – if it’s in a namespace (or closely related one) where that assumption about root categories will be valid.

    I don’t think the ‘older’ way would really be an interface extending IRepository<Category> – it would be a normal static method taking IRepository<Category>. That’s where extension methods just make life more pleasant. If you really would have used inheritance instead, it may well be appropriate to do so now as well. Unfortunately we don’t know enough about the architecture of your system to say that for sure.

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

Sidebar

Related Questions

I'm using Asp.net and have just started to look for a tab solution and
I just started ASP.NET MVC (coming from WebForms) and I'm struggling with some really
We have just started our new assignment - web-based project. Before I get directly
I just started learning .NET so chances are this is a big n00b mistake:
I have just started to look at the Scala collections library re-implementation which is
Please forgive me if I am somewhat unclear, I am just getting started with
Have just started out with EF for Oracle in targeting .Net 4.0. Have added
I just started working with VB.NET. In my application I will need to have
I have just started to look into the phone gap.I have created one basic
I have just started learning C# and would have one question that I cannot

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.