Ejemplo n.º 1
0
        public static void RegisterNamespace(this ITStore store, string namespacePattern)
        {
            // Create our RegexMatch function
            var regexPattern = namespacePattern.WildCardToRegex();

            bool NamespaceMatch(string nSpace) => Regex.IsMatch(nSpace, regexPattern);

            // Get all public non-abstract classes that match namespace
            var targetClasses = Assembly.GetCallingAssembly().ExportedTypes
                                .Where(type => type.IsClass && !type.IsAbstract && NamespaceMatch(type.Namespace))
                                .ToArray();

            // Iterate over each class in these namespaces
            foreach (var target in targetClasses)
            {
                // Direct register
                store.Register(target);

                // Also register any inheritted public interfaces on that class to it
                foreach (var interfaceType in target.GetInterfaces().Where(i => i.IsPublic))
                {
                    store.Register(interfaceType, target);
                }
            }
        }
Ejemplo n.º 2
0
 public static void Register <TKey, TValue>(this ITStore store)
     where TValue : class, TKey
 => store.Register(typeof(TKey), typeof(TValue));
Ejemplo n.º 3
0
 public static void Register <T>(this ITStore store)
     where T : class
 => store.Register <T, T>();
Ejemplo n.º 4
0
 public static void Register(this ITStore store, Type type) => store.Register(type, type);