public void Add <BaseT, SubT>(Func <SubT> factory) where SubT : BaseT { Func <object> f = () => factory(); var baseType = typeof(BaseT); var realType = typeof(SubT); TypeRefs.AddIfNotExist(baseType, realType); TypeRefs.AddIfNotExist(realType, realType); var funcRef = Factories.GetFuncRef(realType); if (funcRef == null) { Factories.AddFuncRef(realType, f); } }