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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:44:23+00:00 2026-05-18T08:44:23+00:00

Here is my repository class: public interface IMyRepository : IRepository<IMyEntity>{} public class MyRepository :

  • 0

Here is my repository class:

public interface IMyRepository : IRepository<IMyEntity>{}

public class MyRepository : IMyRepository
{
...
}

Here is way to register it:

container.Register<IMyRepository, MyRepository >();

Here is the way how I want to get repository resolved:

IRepository<IMyEntity> repository = container.Resolve<IRepository<IMyEntity>>();

Attempt to resolve repository in this ways give an error:

Resolution of the dependency failed, type = “CMCore.Repository.IRepository`1[CMCore.Data.ICmCoreLog]”, name = “(none)”.
Exception occurred while: while resolving.

Exception is: InvalidOperationException – The current type, IRepository`1[IMyEntity], is an interface and cannot be constructed. Are you missing a type mapping?

At the time of the exception, the container was:

Resolving IRepository`1[IMyEntity],(none)

What is wrong in my approach? What is a proper way to achieve mentioned functionality?

Thanks a lot!

P.S. Sometime I want to resolve my class through the IMyRepository, sometime through IRepository. Should I register class twice?

  • 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-18T08:44:24+00:00Added an answer on May 18, 2026 at 8:44 am

    Do:

    container.RegisterType<IRepository<IMyEntity>, MyRepository>();
    

    instead. Unity, by design, only does one level of type mapping. It’s only going to look for a mapping from the type you ask, it doesn’t chase down inheritance trees.

    If you want it to be available both a IRepository or as IMyRepository, then just register it twice:

    container.RegisterType<IRepository<IMyEntity>, MyRepository>()
        .RegisterType<IMyRepository, MyRepository>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the simple snippet: public interface IRepository<T> { T Get(int id); } public
Here's the generic class I'm working with: public interface IRepository<T> where T : EntityObject
Say, I have such classes hierarchy: public interface IRepository { } public class SomeSimpleRepository
Given the following generic interface and implementing class: public interface IRepository<T> { // U
So i have a class name repository which is just a simple array.Here is
public interface IRepository<T>// : IDisposable where T : IEntity { IQueryable<T> GetAll(); void Save(T
I'm trying to create a mock for my IRepository interface: public interface IRepository<T> :
I have some Repository. Work with them is realized through an interface IRepository .
Here is the deal: I created an SVN repository, say, foo. It is at
Here is what i am trying to achieve: We have a SVN repository, but

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.