Hi, I need to use reflection to call some methods from plugin2 to plugin1. Plugin 1 is always installed but I can't reference it in plugin2. How can I resolve IRepository<MyData> ?
using (var scope = iocResolver.CreateScope()) { var coreAssembly= AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.Contains("MyPlugin.Core")); var pluginRepositoryType = coreAssembly.GetType("MyPlugin.Core.IPluginRepository"); var pluginRepository= scope.Resolve(pluginRepositoryType ); //... do some method on pluginRepository works.
var genericRepository = scope.Resolve("IRepository<MyData>"); <--- How do this ?
}
Thank you
3 Answer(s)
-
0
Hi,
Is MyData entity is defined in plugin1 or plugin2 ?
Thanks.
-
0
MyData is defined in Plugin2. Plugin1 doesn't any reference to Plugin2.
-
0
Hi,
You can resolve it like this.
IocManager.Instance.Resolve(typeof(IRepository<>).MakeGenericType(typeof(MyData)));
Instead of using typeof(MyData), you can create MyData's type by reflection.
Thanks.