This project has moved and is read-only. For the latest updates, please go here.

Microsoft.Composition and open generics...

Aug 7, 2012 at 2:47 AM

I'm using Microsoft.Composition 1.0.13-rc with the MVC Microsoft.Composition demo code and I've also tried with .NET 4.5 rc also; this simply doesn't work as expected.

    public interface IRepository<TEntity>
        where TEntity : class
        TEntity Retrieve(params object[] key);
        IQueryable<TEntity> Retrieve();
        void Create(TEntity entity);
        void Delete(TEntity entity);
        void Update(TEntity entity);
        void SaveChanges();

    public class Repository<TEntity>
        : IRepository<TEntity>
        where TEntity : class

Microsoft.Composition under MVC 4 with the demo provider complains that Open generic part 'Repository`1' cannot export non-generic contract 'IRepository`1'." When in the "Parts" namespace. When outside the Parts namespace with Export it says "No export was found for the contract 'IRepository<Address>'

A second problem I've come across is having open generic imports with closed generic imports resolving as expected. I would like to keep IRepository<Address> then have it resolve to Repository<T> : IRepository<T> generic export if a AddressRepository : IRepository<Address> specific export wasn't available. I would expect the generic used most of the time, while the specific class allows behavior to be "overridden" for certain repositories. The comporting class shouldn't care if its AddressRepository or Repository<T> as long as it has a IRepository<Address>.



Aug 7, 2012 at 3:10 AM

OK, I solved the first problem with Microsoft.Composition; my bad; I inadvertently still had references to System.ComponentModel.Composition.

I still feel the second problem would be a worthwhile addition!



Aug 7, 2012 at 9:36 PM

Hi Jay - that's awesome, thanks for following up and sharing your thoughts.


// No longer at Microsoft, but still lurking on the MEF forum  :)