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
Post a Comment