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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:22:44+00:00 2026-05-16T00:22:44+00:00

I have a class similar to the following: public abstract class Manager<T, TInterface> :

  • 0

I have a class similar to the following:

public abstract class Manager<T, TInterface> : IManager<T> where TInterface : IRepository<T>
{
    protected abstract TInterface Repository { get; }

    public virtual List<T> GetAll()
    {
        return Repository.GetAll();
    }
}

This works perfectly fine, however, is there a way to get away from having the TInterface in the abstract class declaration and in the resulting class that extends my generic abstract class:

public class TestManager : Manager<TestObject, ITestRepository>, ITestManager

I am forced to use ITestRepository and make the Repository property abstract due to the fact that it can contain custom methods that I need to know about and be able to call.

As I continue to build layers, I will have to keep doing this process the whole way up the stack. Examples would be if I had a generic abstract controller or service layer:

public class TestService : Service<TestObject, ITestManager>, ITestService

Is there a better way to do this or is this the best practice to allow a generic class to call another generic class?

  • 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-16T00:22:45+00:00Added an answer on May 16, 2026 at 12:22 am

    It seems that all you want to do is to make Manager<T> testable, and use a mock as a repository that you can query for special members.

    If that’s the case, maybe you can change your design to this:

    public class Manager<T> : IManager<T> {
      protected IRepository<T> Repository { get; set; }
      // ...
      public virtual List<T> GetAll() {
        return Repository.GetAll();
      }
    }
    

    Now, all the specifics of testing are in a testing subclass:

    public class TestingManager<T> : Manager<T> {
      public new ITestRepository<T> Repository {
        get {
          return (ITestRepository<T>)base.Repository;
        }
        set {
          base.Repository = value;
        }
      }
    }
    

    When you write your unit tests, you create TestingManager<T> instances (referenced through TestingManager<T> declared variables and fields), and you provide them with a test repository. Whenever you query their Repository, you’ll always get a strongly-typed test repository.

    UPDATE:

    There’s another way to solve this, without a subclass. You declare your repository objects as test repositories that you pass to Manager<T>s and you query them directly, without going through the Manager<T>.

    [Test]
    public void GetAll_Should_Call_GetAll_On_Repository_Test() {
      var testRepository = new TestRepository();
      var orderManager = new Manager<Order>(testRepository);
      // test an orderManager method
      orderManager.GetAll();
      // use testRepository to verify (sense) that the orderManager method worked
      Assert.IsTrue(testRepository.GetAllCalled);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class similar to the following that uses an internal List: public
Ok I have a class similar to the following... public class Order { private
I have a base class with the following (trimmed for brevity) declaration: public abstract
I have the following class structure: public abstract class Generic<T extends SuperClass> public class
I have a class similar to the following: public class MyProxy : ClientBase<IService>, IService
Say I have the following: public class MyContainer { public string ContainerName { get;
I have a Class similar to the following: public delegate void FanChangedEventHandler(Fan sender, EventArgs
I have an interface class similar to: class IInterface { public: virtual ~IInterface() {}
I have the following business objects: public abstract class Product { public int Id
I have a class similar to the following one: [Bindable] public class BindableClass {

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.