I have the following code example using MEF:
public interface IFoo<T> {} public class Foo<T> : IFoo<T> {} [Export(typeof(IFoo<String>))] public class Foo : Foo<String> {} public class Bar<T> { [Import] private readonly IFoo<T> foo; } static void Main() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); var container = new CompositionContainer(catalog); container.ComposeParts(); var bar = new Bar<String>();
This does not work - the field is foo null . Is it because its type is not considered by MEF as IFoo<String> ?
source share