示例#1
0
        /// Collect all Compoent-Types in current domain
        private static Dictionary <string, List <Type> > CollectAllComponents()
        {
            var compType = typeof(IComponent);
            var types    = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(s => s.GetTypes())
                           .Where(p => p.IsClass && p.IsPublic && !p.IsAbstract &&
                                  compType.IsAssignableFrom(p));

            Dictionary <string, List <Type> > comps = new Dictionary <string, List <Type> >();

            comps[DefaultContext.Name] = new List <Type>();

            var scopeType = typeof(ContextScope);

            foreach (var t in types)
            {
                var scopes = t.GetCustomAttributes(scopeType, false);

                if (scopes == null || scopes.Length <= 0)
                {
                    CollectComponent(comps, DefaultContext.Name, t);
                }
                else
                {
                    foreach (var scope in scopes)
                    {
                        string name = ContextScopeHelper.GetName(scope.GetType());
                        CollectComponent(comps, name, t);
                    }
                }
            }

            return(comps);
        }
示例#2
0
 public static Context Get <S>() where S : ContextScope
 {
     return(sharedInstance._contextLookup[ContextScopeHelper.GetName <S>()]);
 }
示例#3
0
 public Context GetContext <S>() where S : ContextScope
 {
     return(_contextLookup[ContextScopeHelper.GetName <S>()]);
 }
示例#4
0
 static DefaultContext()
 {
     Name = ContextScopeHelper.GetName <DefaultContext>();
 }