Esempio n. 1
0
 public void Add(ClassCreator creator)
 {
     if (creator.Index > 0)
     {
         if (creator.Index > _defaultIndex)
         {
             _default      = creator;
             _defaultIndex = creator.Index;
         }
         foreach (var cc in _all)
         {
             if (cc.Index == creator.Index)
             {
                 throw new IocException("[{0}] and [{1}] have the same index {2}", creator.Type, cc.Type, cc.Index);
             }
         }
     }
     if (!creator.Name.IsNullOrEmpty())
     {
         foreach (var cc in _all)
         {
             if (cc.Name == creator.Name)
             {
                 throw new IocException("[{0}] and [{1}] have the same name {2}", creator.Type, cc.Type, cc.Name);
             }
         }
     }
     _all.Add(creator);
 }
Esempio n. 2
0
 private static void Search(List <Assembly> assemblies, List <Type> entries, List <ClassCreator> impls)
 {
     foreach (var assembly in assemblies)
     {
         try
         {
             foreach (var type in assembly.GetTypes())
             {
                 var entry = type.GetAttribute <DependenceEntryAttribute>(false);
                 if (entry != null)
                 {
                     entries.Add(type);
                 }
                 var impl = type.GetAttribute <ImplementationAttribute>(false);
                 if (impl != null)
                 {
                     impls.Add(ClassCreator.New(type, impl.Index, impl.Name));
                 }
             }
         }
         catch (ReflectionTypeLoadException ex)
         {
             throw new SystemException("Loading assembly error: " + assembly.FullName, ex);
         }
     }
 }
Esempio n. 3
0
 private static void Register(Type entryType, ClassCreator cc)
 {
     if (Container.ContainsKey(entryType))
     {
         var creator = Container[entryType];
         creator.Add(cc);
     }
     else
     {
         Container[entryType] = new ImplementsCreators(cc);
     }
 }
Esempio n. 4
0
        public static void Register(Type entryType, Type implType, int index, string name)
        {
            var cc = ClassCreator.New(implType, index, name);

            Register(entryType, cc);
        }
Esempio n. 5
0
 public ImplementsCreators(ClassCreator creator)
 {
     Add(creator);
 }