Given a .net application that supports different logic providers, how to instantiate one instance of each class in a solution folder? What is the way to iterate through all of the classes in the folder?
For example I have a folder in my solution called MailClientProviders
It contains Outlook and The Bat! provider classes that implement a IMailProvider interface.
In my App.xaml I call a Ninject container to initialize all the dependencies. Then I need to write a method that I would call, and would get an instance of each class returned.
heartbeatService.Providers = CreateOneInstanceOfAllClassesInProvidresDir(MailClientProviders);
What would be in the CreateOneInstanceOfAllClassesInProvidresDir method?
I used these functions to retrieve all classes in a folder implementing my custom interface:
So you can run
GetDirectoryPlugins<IMailProvider>and useActivator.CreateInstancewith every class found…