Hi all!
Could You please help. In main program, i do import my plug-in in this way
- public static void LoadContainer(Unity.IUnityContainer container, string path, string pattern)
- {
- var dirCat = new DirectoryCatalog(path, pattern);
- var importDef = BuildImportDefinition();
-
- try
- {
- using (var aggregateCatalog = new AggregateCatalog())
- {
- aggregateCatalog.Catalogs.Add(dirCat);
- using (var componsitionContainer = new CompositionContainer(aggregateCatalog))
- {
- IEnumerable exports = componsitionContainer.GetExports(importDef);
-
- IEnumerable modules = exports.Select(export => export.Value as IComponent).Where(m => m != null);
-
-
-
-
-
- try
- {
- var v0 = exports.Select(export => export.Value).ToArray()[0];
- var v1 = (IComponent)v0;
- }
- catch (Exception ex) { ex.ToString(); }
-
- var registerComponent = new RegisterComponent(container);
- foreach (IComponent module in modules)
- {
- module.SetUp(registerComponent);
- }
- }
- }
- }
where IComponent is
- public interface IComponent
- {
- void SetUp(IRegisterComponent registerComponent);
- String Test();
- }
and exported function is
- class DependencyResolver : IComponent
- {
- [System.ComponentModel.Composition.Export(typeof(IComponent))]
- public void SetUp(IRegisterComponent registerComponent)
- {
- registerComponent.RegisterType();
- }
-
- [System.ComponentModel.Composition.Export("mimi")]
- public string Test()
- {
- return "test)";
- }
- }
The problem is in line
- IEnumerable modules = exports.Select(export => export.Value as IComponent).Where(m => m != null);
i got always empty list, because export.Value is type {System.ComponentModel.Composition.Primitives.ExportedDelegate} and it can't be converted to type IComponent. Could You please advise me way to execute export.Value delegate?
Thanks!
PS I use VS2017 and full example is available at
https://www.codeproject.com/Articles/997216/RESTful-Day-sharp-Resolve-dependency-of-dependenci