I am working on a component that executes a preliminary method of any interface registered in ioc, and the execution time depends on different triggers. It should be able to save the actions that should be performed in the database, so I save the method name, type and parameter list (with serialization in BLOB) to the database until it is needed.
When the trigger starts, I need to execute the method on the type instance. Since I use dependency injection, I have an interface name stored in the database (in the format "Namespace.IInterface, AssemblyName" )
To run the Resolve<IInterface>() method in the ioc container, I need an instance of its Type :
Assembly assembly = System.Reflection.Assembly.Load(assemblyName); Type service = assembly.GetType(typeName); object instance = IOCContainer.Resolve(service);
My questions:
- Is there a better way to get an instance of a type on its behalf if I'm sure that the containing assembly is already loaded into the application domain? (I tried just
Type.Load(typeName) but got zero) - If the assembly is already loaded, will the CLR optimize this process (use the already loaded one), or do I need to manually cache the list of assemblies to prevent the performance impact on reloading the same assembly again and again?
source share