I’d like to instantiate a class by name (a string) without specifying a namespace or assembly. Like this (Unity syntax):
var processor = container.Resolve<IProcessor>("SpecialProcessor");
would instantiate the first IProcessor it finds called SpecialProcessor. Maybe
MyNamespace.SpecialProcessor
I’d like to avoid having to create an entry in a config every time somebody adds a new processor. I’m fine with having an entry for all candidate assemblies though.
Can I use an IoC container for something like this or should I roll my own?
Here’s a function that does something very similar to what you want. You can modify it to filter based on a specific class name pretty easily.
These functions have references to a few utilities we use for logging and exception handling. You’ll need to replace them with whatever you normally do in these situations.