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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:11:28+00:00 2026-05-16T15:11:28+00:00

I have a bunch of Repository classes which all look a bit like the

  • 0

I have a bunch of Repository classes which all look a bit like the following. Note that I have omitted certain methods; I just want you to get a flavour.

public class SuggestionRepository : ISuggestionRepository
{
    private IUnitOfWork _unitOfWork;

    public SuggestionRepository(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public Suggestion Load(int id)
    {
        Suggestion suggestion;
        suggestion = _unitOfWork.Load<Suggestion>(id);
        return suggestion;
    }

    public IQueryable<Suggestion> All
    {
        get { return _unitOfWork.GetList<Suggestion>(); }
    }
}

You’ll imagine the amount of repeated code I have between my repositories.

I would like to create a Repository<T> class which is extended by my repositories so that hopefully I don’t have to write boilerplate code for each one. This class might look something like the following:

internal class Repository<T> where T : Entity
{
    private IUnitOfWork _unitOfWork;

    internal Repository<T>(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public T Load(int id)
    {
        T t;
        t = _unitOfWork.Load<T>(id);
        return t;
    }

    public IQueryable<T> All
    {
        get { return _unitOfWork.GetList<T>(); }
    }
}

But Visual Studio isn’t showing that constructor any love at all. It’s saying ‘unexpected token’ around the parameter list brackets, saying it can’t access the non-static field _unitOfWork in a static context, and pretending it doesn’t know what the parameter unitOfWork is.

Clearly generic classes can have constructors as it’s possible to new up a List<T> for example. So what’s going on?

  • 1 1 Answer
  • 2 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-16T15:11:28+00:00Added an answer on May 16, 2026 at 3:11 pm

    The constructor for a generic class should not have the type arguments in the method name. Simply say

    internal Repository(IUnitOfWork unitOfWork)
    

    and see how you get on.

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

Sidebar

Related Questions

I have a bunch of code in a routine that looks a bit like
I have a bunch of repository classes which I want to unit-test using Visual
I have bunch of strings, some of which are fairly long, like so: movie.titles
I have a git repository set up that looks something like this: PROD /
I have a Git repository that contains a bunch of top-level maven projects (each
I have a WCF service that exposes a bunch of methods that return business
We have bunch of autogenerated classes which are mostly Axis2 stubs, skeletons etc. For
I have a following question. Suppose I have a bunch of repositories hosted that
I have a bunch of files in a folder checked out from a repository.
I have bunch of lists like this: out[3] [[3]] [1] forum=28&mid=11883 [2] forum=29&mid=11884 out[4]

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.