Beispiel #1
0
 public CompositionContext()
 {
     //foreach (var mut in Mutators.Get(t)) mut(val);
     Singletons = new Dictionary <Type, object>();
     Factories  = new TypedFactory();
     Factories.Mutate((t, o) => {
         foreach (var mut in Mutators.Get(t))
         {
             mut(o);
         }
     });
     TaggedFactories = new FactoryDictionary <Type, TypedFactory>();
     TaggedFactories.Loader((t) => {
         var fac = new TypedFactory();
         fac.Mutate((t2, o) => {
             foreach (var mut in TaggedMutators.Get(t).Get(t2))
             {
                 mut(o);
             }
         });
         return(fac);
     });
     Mutators = new FactoryDictionary <Type, IList <Action <object> > >();
     Mutators.Loader((t) => new List <Action <object> >());
     TaggedMutators = new FactoryDictionary <Type, FactoryDictionary <Type, IList <Action <object> > > >();
     TaggedMutators.Loader((t) => {
         var muts = new FactoryDictionary <Type, IList <Action <object> > >();
         muts.Loader((t2) => new List <Action <object> >());
         return(muts);
     });
 }
Beispiel #2
0
 public TypedFactory()
 {
     Factories = new Dictionary <Type, Func <object> >();
     Cached    = new FactoryDictionary <Type, object>();
     Cached.Loader(t => {
         if (Factories.ContainsKey(t))
         {
             var fac = Factories[t]();
             if (_mutator != null)
             {
                 _mutator(t, fac);
             }
             return(fac);
         }
         return(null);
     });
 }