Repositories collection
===

Is short:

How come that adding a derived type to collection passes but when trying to add a generic of the derived type it fails?

The "short" code:

    //a generic repository
            public class EfRepository<T> : IRepository<T> where T: BaseCatalogModel{...}


            public CatalogRepository(IRepository<Product> productRepository, IRepository<Category> categoryRepository)
        {
            //This passes
            Dictionary<int, BaseCatalogModel> dic1 = new Dictionary<int, BaseCatalogModel>();
            dic1.Add(1, new Product());
            dic1.Add(2, new Category());
            dic1.Add(3, new BaseCatalogModel());


            //This not. 
            //The error: cannot convert from 'YoYo.Core.Data.Repositories.EfRepository<YoYo.Commerce.Common.Domain.Catalog.Product>' 
            //to 'YoYo.Core.Data.Repositories.EfRepository<YoYo.Commerce.Common.Domain.Catalog.BaseCatalogModel>'
            Dictionary<int, EfRepository<BaseCatalogModel>> dic2 = new Dictionary<int, EfRepository<BaseCatalogModel>>();
            dic2.Add(1, new EfRepository<Product>());
            dic2.Add(2, new EfRepository<Category>());
        }


The long deal:
Working on an on-line store, I would like to hold in a catalog repository a collection of all repositories relevant to managing the catalog. 

The idea is to manage the entire catalog from one repository.

The repositories collection is of type Dictionary<Type, IRepository<BaseCatalogModel>)

I fail to add any BaseCatalogModel derived type repository to the collection.


I will  be happy to get any assistance on the above or suggestions for better implementations.

    public class BaseCatalogModel:BaseModel
    {
        public int Id { get; set; }
        ...
    }
    public class Category:BaseCatalogModel
    {
        ...
    }
    public class Product : BaseCatalogModel
    {
        ...
    }
       

    public class CatalogRepository : ICatalogRepository 
    {
        private readonly Dictionary<Type, IRepository<BaseEntity>> _repositoriesCollection= new Dictionary<Type, IRepository<BaseEntity>>();
        public CatalogRepository(IRepository<Product> productRepository, IRepository<Category> categoryRepository)
        {
            _repositoriesCollection.Add(typeof(Category), categoryRepository); //==> this fails 
            _repositoriesCollection.Add(typeof(Product), productRepository);    //==> this fails
        }


        public T GetCatalogItem<T>(int id) where T : BaseCatalogModel
        {
            //returns a catalog item using type and id
        }

        public IEnumerable<T> GetCatalogItem<T>() where T : BaseCatalogModel
        {
            //returns the entire collection of catalog item
        }
    }