c# - MEF Generic Imports -


i have following example code 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>();    //bar.foo null } 

this doesn't seem work - foo field null. because type isn't seen mef ifoo<string> ?

foo null because creating instance yourself. need have container create instance.

additionally, want check out genericcatalog if plan on working importing/exporting generics.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -