I'm looking for solution to create factory that will be Open/Closed compliant. We can achieve it really simple by reflection (instantiate all classes implementing specific interface, that exists in ex. current assembly, store them in some dictionary with key based on static property and return specific instance based on parameter passed to CreateInstance method).
I wonder if this is possible using Ninject. I bought book "Mastering Ninject for Dependency Injection" there is a chapter "Meeting real-world requirements" with Telcom Switch example. Unfortunately, the IStatusCollectorFactory and all factories that implement this interface violate Open/Close principle- you have to alter interface if you want to add support for new class.
Any help?:)
/// Interface for classes that define factory able to create currency defaltion instances.
public interface ICurrencyDeflationFactory
{
ICurrencyDeflation CreateInstance(string currencyCode);
}
/// <summary>
/// Interface for classes that define deflation table in specific currency.
/// </summary>
public interface ICurrencyDeflation
{
/// <summary>
/// Current currency code as defined in ISO 4217
/// </summary>
string CurrencyCode { get; }
/// <summary>
/// Deflation table used during conversion.
/// </summary>
string[,] GetDeflationTable { get; }
}