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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:22:42+00:00 2026-06-13T08:22:42+00:00

First i am reading this article .He uses a custom in memory repository for

  • 0

First i am reading this article.He uses a custom in memory repository for testing and proof of concept reason. RepositoryEntityStore .
Then in order to avoid the use of new he implements this which isnt included in article but in sample.

namespace eDirectory.Naive.Repository
{
    /// <remarks>
    /// version 0.2 Chapter II: Repository
    /// </remarks>
    public class RepositoryLocatorEntityStore
        : RepositoryLocatorBase
    {
        protected Dictionary<Type, object> RepositoryMap = new Dictionary<Type, object>();

        public override IRepository<T> GetRepository<T>()
        {
            var type = typeof(T);
            if (RepositoryMap.Keys.Contains(type)) return RepositoryMap[type] as IRepository<T>;
            var repository = new RepositoryEntityStore<T>();
            RepositoryMap.Add(type, repository);
            return repository;
        }
    }
}

Later i think that he uses DI to not even create instance of RepositoryEntityStore .
The question is how can i modify this in order to work with classes that extend RepositoryEntityStore ? Like CustomerRepositoryEntityStore ?

  • 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-13T08:22:43+00:00Added an answer on June 13, 2026 at 8:22 am

    If you don’t really know in advance (or don’t want to know, as part of DI) the exact type, you could use Activator.CreateInstance(typeof(T))

    You will still have to make sure your type provide a default constructor new()

    In order to provide that kind of flexibility, you will need to use an IoC (Inversion of Control) container, that will contain either the mapping or some logic to determine which dependency to use when instantiating your object.

    This can be achieved through some external component such as ninject or it can be as simple as a config files that generates a mapping between types and assemblies.

    Then, since you are using generic classes, you will need to Make the right (computed) type. This command takes care of this : MakeGenericType(type)

    You will then be able to create the instance of this generated type.

    So your code would look like :

    namespace eDirectory.Naive.Repository
    {
        /// <remarks>
        /// version 0.2 Chapter II: Repository
        /// </remarks>
        public class RepositoryLocatorEntityStore
            : RepositoryLocatorBase
        {
            protected Dictionary<Type, object> RepositoryMap = new Dictionary<Type, object>();
    
            public override IRepository<T> GetRepository<T>()
            {
                var type = typeof(T);
                if (RepositoryMap.Keys.Contains(type)) return RepositoryMap[type] as IRepository<T>;
                Type DIRepository = IoCContainer.getType()// get the right type from your mapping (IoC container)
                var repository = Activator.CreateInstance(DIRepository.MakeGenericType(type));
                RepositoryMap.Add(type, repository);
                return repository;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading this article: Managing Oracle Synonyms Regarding the order of preference, when
I was reading this article Build Your First Cloud Application Using Visual Studio 2010
I am reading this asp.net article on building your first asp.net mvc 2 website
After reading this article about validating with service layer I have some doubts. First:
I was just reading this line: The first thing the format() method does is
First, thank you for reading this. I am just starting php and I am
First and foremost, thank you all for reading this and helping, I'm very grateful.
This is the first Python script I've tried to create. I'm reading a xml
Reading through the Wikipedia article on First-Class functions, there is a nice table of
I was reading this Ars article on password security and it mentioned there are

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.