Q:

Is it possible to create a Singleton factory class maintaining a dictionary for instances?

I have multiple classes that inherit from IPrint. I want to instantiate these classes using a factory but I want to maintain a single instance of each type.
Is this possible? 
Please find my sample code below.
 public interface IPrint
    {
        void DoPrint();
    }
    public class DigitalPrint : IPrint
    {
        public void DoPrint()
        {
            // logic
        }
    }
    public class InkPrint : IPrint
    {
        public void DoPrint()
        {
            // logic
        }
    }
    public class PrintFactory
    {
        private static IDictionary<IPrint, object> prints = new 
   Dictionary<IPrint, object>();
        private PrintFactory()
        {

        }
        public static IPrint GetPrint(PrintType type)
        {
            // return instance depending on type. Instantiate only once 
             //like singleton
            // How to write so that it returns a single instance depending 
            //on type
            return null;
        }
    }

    public enum PrintType
    {
        DigitalPrint,
        InkPrint
    }

Can someone give me some idea if this is possible?
Thanks.

A:

You can create IPrint instances when initializing Dictionary<PrintType, IPrint>:
private static IDictionary<PrintType, IPrint> prints = 
  new Dictionary<PrintType, IPrint> {
      { PrintType.DigitalPrint, new DigitalPrint() },
      { PrintType.InkPrint, new InkPrint() }
  };

Getting print (thus print is a class, the same instance will be returned for each request):
public static IPrint GetPrint(PrintType type)
{
    IPrint print;
    if (!prints.TryGetValue(type, out print))
       return null;

    return print;
}

If you don't want to create IPrint instances until the client asks for them, you can use Dictionary<PrintType, Lazy<IPrint>>:
private static IDictionary<string, Lazy<IPrint>> prints =
    new Dictionary<string, Lazy<IPrint>> {
        { PrintType.DigitalPrint, new Lazy<IPrint>(() => new DigitalPrint()) },
        { PrintType.InkPrint, new Lazy<IPrint>(() => new InkPrint()) }
    };

Getting print (in this case only one instance of each IPrint type will be created, but not before someone tries to get the instance of that type):
public static IPrint GetPrint(PrintType type)
{
    Lazy<IPrint> factory;
    if (!prints.TryGetValue(type, out factory))
       return null;

    return factory.Value;
}

Though I would consider using dependency injection framework instead of implementing such functionality manually.
Further reading: Ninject or Autofac

