Esempio n. 1
0
        internal static void Scan(this IServiceCollection serviceCollection,
                                  IEnumerable <AssemblyScanSettings> assembliesToScan, IEnumerable <AssemblyScanSettings> scanIncludeList)
        {
            if (assembliesToScan == null || !assembliesToScan.Any())
            {
                throw new ArgumentNullException(nameof(assembliesToScan));
            }
            scanIncludeList = scanIncludeList ?? new List <AssemblyScanSettings>();

            IEnumerable <Type> allCandidateTypes = assembliesToScan.SelectMany(x => x.Assembly.GetTypes())
                                                   .Union(scanIncludeList.SelectMany(x => x.Assembly.GetTypes()))
                                                   .Distinct();
            IEnumerable <Type>     allNonAbstractCandidateTypes = allCandidateTypes.Where(t => !t.IsAbstract);
            IEnumerable <Assembly> allCandidateAssemblies       = assembliesToScan.Select(x => x.Assembly)
                                                                  .Union(scanIncludeList.Select(x => x.Assembly))
                                                                  .Distinct()
                                                                  .ToList();

            IEnumerable <AssemblyScanSettings> scanExcludeList =
                MiddlewareClassesDiscovery.FindMiddlewareLocations(allCandidateAssemblies);

            allCandidateTypes = AssemblyScanSettings.Filter(
                types: allCandidateTypes,
                scanExcludeList: scanExcludeList,
                scanIncludeList: scanIncludeList);


            IEnumerable <DiscoveredReducerClass> discoveredReducerClasses =
                ReducerClassessDiscovery.DiscoverReducerClasses(serviceCollection, allNonAbstractCandidateTypes);

            IEnumerable <DiscoveredReducerMethod> discoveredReducerMethods =
                ReducerMethodsDiscovery.DiscoverReducerMethods(serviceCollection, allCandidateTypes);

            IEnumerable <DiscoveredEffectClass> discoveredEffectClasses =
                EffectClassessDiscovery.DiscoverEffectClasses(serviceCollection, allNonAbstractCandidateTypes);

            IEnumerable <DiscoveredEffectMethod> discoveredEffectMethods =
                EffectMethodsDiscovery.DiscoverEffectMethods(serviceCollection, allCandidateTypes);

            IEnumerable <DiscoveredFeatureClass> discoveredFeatureClasses =
                FeatureClassesDiscovery.DiscoverFeatureClasses(
                    serviceCollection,
                    allNonAbstractCandidateTypes,
                    discoveredReducerClasses,
                    discoveredReducerMethods);

            RegisterStore(
                serviceCollection,
                discoveredFeatureClasses,
                discoveredEffectClasses,
                discoveredEffectMethods);
        }
Esempio n. 2
0
        internal static void Scan(
            this IServiceCollection serviceCollection,
            Options options,
            IEnumerable <AssemblyScanSettings> assembliesToScan,
            IEnumerable <AssemblyScanSettings> scanIncludeList)
        {
            if (assembliesToScan == null || assembliesToScan.Count() == 0)
            {
                throw new ArgumentNullException(nameof(assembliesToScan));
            }

            GetCandidateTypes(
                assembliesToScan: assembliesToScan,
                scanIncludeList: scanIncludeList ?? new List <AssemblyScanSettings>(),
                allCandidateTypes: out Type[] allCandidateTypes,
                allNonAbstractCandidateTypes: out Type[] allNonAbstractCandidateTypes);

            // Classes must not be abstract
            DiscoveredReducerClass[] discoveredReducerClasses =
                ReducerClassessDiscovery.DiscoverReducerClasses(serviceCollection, allNonAbstractCandidateTypes);

            DiscoveredEffectClass[] discoveredEffectClasses =
                EffectClassessDiscovery.DiscoverEffectClasses(serviceCollection, allNonAbstractCandidateTypes);

            // Method reducer/effects may belong to abstract classes
            TypeAndMethodInfo[] allCandidateMethods = AssemblyScanSettings.FilterMethods(allCandidateTypes);

            DiscoveredReducerMethod[] discoveredReducerMethods =
                ReducerMethodsDiscovery.DiscoverReducerMethods(serviceCollection, allCandidateMethods);

            DiscoveredEffectMethod[] discoveredEffectMethods =
                EffectMethodsDiscovery.DiscoverEffectMethods(serviceCollection, allCandidateMethods);

            DiscoveredFeatureClass[] discoveredFeatureClasses =
                FeatureClassesDiscovery.DiscoverFeatureClasses(
                    serviceCollection: serviceCollection,
                    allCandidateTypes: allNonAbstractCandidateTypes,
                    discoveredReducerClasses: discoveredReducerClasses,
                    discoveredReducerMethods: discoveredReducerMethods);

            RegisterStore(
                serviceCollection: serviceCollection,
                options: options,
                discoveredFeatureClasses: discoveredFeatureClasses,
                discoveredEffectClasses: discoveredEffectClasses,
                discoveredEffectMethods: discoveredEffectMethods);
        }