I have implemented a 'plugin' system where my application creates classes that implement an interface at runtime to allow pluggable functionality.
I am achieving this by using Activator.CreateInstance on all classes that implement the specified interface within the plugin assembly.
At the current time I am only using one implementation of the class, and for it I have two constructor arguments, and have included those in the Activator.CreateInstance call:
instanceList.Add((Foo)Activator.CreateInstance(_TypeList[typeKey], new object[] { arg1, arg2 }));
I realise this may cause problems later if an implementation is added that does not use this constructor signature. What is the best situation to handle this.
Explicitly say via documentation that constructors need to use this signature, and then surround it in a try/catch?
Or would there be a way to invoke whatever constructor a class has? bearing in mind I would have to match up constructor arguments somehow.
Or... avoiding constructor arguments by putting the arguments in a static class as static propertys?