I have the following
public interface IImportProcess
{
Task Process(int id);
}
public class Sally:IImportProcess
{
public async Task Process(int id)
{...}
}
public class Bob:IImportProcess
{
public async Task Process(int id)
{...}
}
say I have "Sally" in my db, and I want to instantiate an object Sally
but i dont want a concrete object, I simply want to get the interface version of it so I can just call .Process()
on it and it would call the .Process()
of Sally
because the string/class it was created from is Sally
Same would be if I pass "Bob" then it would instantiate based on Bob
class
Assuming all these classes are in the same assembly so I can use reflection and if possible Activator so I can do the following
var cls = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("Sally") as IImportProcess;
await cls.Process(1);
cls
seems to always return null when it should not be null