Esempio n. 1
0
        public static void RegisterIntefaceBasedTypes <Dependency, Transient, Singleton, Scoped>(Action[] action, string baseDir)
        {
            var assemblies = AppDomain.GetAllAssemblies(baseDir);

            var allTypes = assemblies.SelectMany(x => x.ExportedTypes).
                           Where(x => !x.GetTypeInfo().IsAbstract&& typeof(Dependency).IsAssignableFrom(x) && x.GetTypeInfo().IsClass).ToList();

            var transientTypes = allTypes.Where(x => !x.GetTypeInfo().IsAbstract&& typeof(Transient).IsAssignableFrom(x) && x.GetTypeInfo().IsClass);
            var singletonTypes = allTypes.Where(x => !x.GetTypeInfo().IsAbstract&& typeof(Singleton).IsAssignableFrom(x) && x.GetTypeInfo().IsClass);
            var scopedTypes    = allTypes.Where(x => !x.GetTypeInfo().IsAbstract&& typeof(Scoped).IsAssignableFrom(x) && x.GetTypeInfo().IsClass);

            RegisterTypes <Dependency, Transient, Singleton, Scoped>(transientTypes, IocLifeTime.Transient, action);
            RegisterTypes <Dependency, Transient, Singleton, Scoped>(singletonTypes, IocLifeTime.Singleton, action);
            RegisterTypes <Dependency, Transient, Singleton, Scoped>(scopedTypes, IocLifeTime.Scoped, action);
        }