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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:11:43+00:00 2026-06-17T09:11:43+00:00

I am attempting to use the following Generic Repository Interface for DI and constructor

  • 0

I am attempting to use the following Generic Repository Interface for DI and constructor injection:

public interface IRepository<TEntity> : IDisposable where TEntity : class

The problem is in order to define an instance of the Interface, I must provide the class type like this:

private IRepository<Person> _personRepository;

The issue with this is if I’m using DI (and I’m using Unity for IoC framework), then I have to define multiple instances in my constructor to get all repository interfaces I need to work with like this:

public MyClass(IRepository<Person> personRepository,
               IRepository<Orders> ordersRepository,
               IRepository<Items> itemsRepository,
               IRepository<Locations> locationsRepository)
{
  _personRepository = personRepository;
  _OrdersRepository = ordersRepository; 
  _itemsRepository = itemsRepository;
  _locationsRepository = locationsRepository;
}

Questions:

  1. Is this OK?
  2. If not where am I lost on this concept?
  3. Even if this is proper, what’s the point of Unity to register Interface to concrete type? I’ve already done it because the generic repository forced me on declaration.

Please help clear this up for me, and I appreciate all your help!

  • 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-17T09:11:43+00:00Added an answer on June 17, 2026 at 9:11 am

    Is this OK?

    Sure. There’s personal preference on whether to use constructor injection like you have or property injection. Constructor injection is cleaner since you don’t have to have lot of parameters to your constructor, but it’s safer as well.

    what’s the point of Unity to register Interface to concrete type

    One reason is so that you can unit test MyClass without having to use your actual repository that hits a database. You can “fake” out the repository to return hard-coded values to test against.

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

Sidebar

Related Questions

I am attempting to use the following PHP class: <?php class Service { public
Running into the following problem specifically in Safari 5.1.2 when attempting to use the
I am attempting to use the following code to search a database using words
I'm attempting to use the following sql to retrieve the total amount received, and
I get the following error when attempting to use django-openid-auth OpenID discovery error: No
I am attempting to use java scanner with the following set of delimiters &
I am attempting to use a jquery drowndown checklist control. Following some simple examples,
I'm attempting to learn how to use Cucumber and creating steps using the following
I am attempting to use a custom font for a TextView on Android, following
I'm attempting to use the following to get the height & width of the

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.