Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to resolve IRepository with IocResolve #3603


User avatar
0
ivanosw1 created

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&lt;MyData&gt;"); <---  How do this ?  

}

Thank you


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is MyData entity is defined in plugin1 or plugin2 ?

    Thanks.

  • User Avatar
    0
    ivanosw1 created

    MyData is defined in Plugin2. Plugin1 doesn't any reference to Plugin2.

  • User Avatar
    0
    ismcagdas created
    Support Team

    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.