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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:32:43+00:00 2026-06-04T01:32:43+00:00

For a given repository interface IRepository<T> where T: Base and a bunch of classes

  • 0

For a given repository interface IRepository<T> where T: Base and a bunch of classes that inherit Base (for instance, Text) how do you create instances of a provider that implements IRepository, for instance JsonRepository<T> with Text as T (JsonRepository<Text>) and run methods on it?

I’d like to use reflection with a for or foreach to create instances of repositories for all the classes inheriting Base and perform some data management functions on them.

What I want to avoid – if you had 100 classes inheriting Base class you obviously wouldn’t go creating instances manually in code and then running it?

  • 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-04T01:32:44+00:00Added an answer on June 4, 2026 at 1:32 am

    You can use Activator.CreateInstance

    See an example here:

    Modified to your example:

    var d1 = typeof(JsonRepository<>);
    Type[] typeArgs = { typeof(Text) };
    var makeme = d1.MakeGenericType(typeArgs);
    object o = Activator.CreateInstance(makeme);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a basic repository interface: public interface IPersonRepository { void AddPerson(Person person); List<Person> GetAllPeople();
Given this code public interface IRepository<T> { IQueryable<T> GetAll(); } and this public class
Given the following generic interface and implementing class: public interface IRepository<T> { // U
Here is my repository class: public interface IMyRepository : IRepository<IMyEntity>{} public class MyRepository :
Considering this code : interface IRepository<T> { void Save(); } class Repository<T> { public
Given these base classes and interfaces public abstract class Statistic : Entity, IStatistic {
Given the following repository URL from my pom.xml how can I determine what the
Given this class public partial class Default : Page { private IRepository repo; ...
Given an interface or interfaces, what is the best way to generate an class
Given Java's write once, run anywhere paradigm and the fact that the Java tutorials

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.