private void RegisterComponent(IServiceCollection services, IMvcBuilder builder,
                                       Assembly assembly,
                                       List <HisarCacheAttribute> cacheItems)
        {
            var assemblyName = assembly.GetName().Name;
            var componentId  = assembly.GetComponentId();

            ComponentAssemblyLookup.Add(componentId, assembly);

            AssemblyLoadContext.Default.Resolving += DefaultResolving;

            if (cacheItems != null)
            {
                cacheItems.AddRange(assembly.GetTypesAttributes <HisarCacheAttribute>());
            }

            try
            {
                var startupType = StartupLoader.FindStartupType(assemblyName, _env.EnvironmentName);
                if (startupType != null)
                {
                    var startup = StartupTypeLoader.CreateHisarConventionBasedStartup(startupType, ServiceProvider, _env);
                    StartupLookup.Add(componentId, startup);
                    startup.ConfigureServices(services);

                    services.AddMenuBuilders(startupType);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                AssemblyLoadContext.Default.Resolving -= null;
            }

            var manager      = builder.PartManager;
            var assemblyPart = new AssemblyPart(assembly);

            if (!manager.ApplicationParts.Contains(assemblyPart))
            {
                manager.ApplicationParts.Add(assemblyPart);
            }
        }
Exemple #2
0
        private void RegisterComponent(IServiceCollection services, IMvcBuilder builder,
                                       Assembly assembly,
                                       List <HisarCacheAttribute> cacheItems)
        {
            var assemblyName = assembly.GetName().Name;
            var componentId  = assembly.GetComponentId();

            ComponentAssemblyLookup.Add(componentId, assembly);

            if (cacheItems != null)
            {
                cacheItems.AddRange(assembly.GetTypesAttributes <HisarCacheAttribute>());
            }

            try
            {
                var startupType = StartupLoader.FindStartupType(assemblyName, _env.EnvironmentName);
                if (startupType != null)
                {
                    var startup = StartupTypeLoader.CreateHisarConventionBasedStartup(startupType, ServiceProvider, _env);
                    StartupLookup.Add(componentId, startup);
                    startup.ConfigureServices(services);

                    services.AddMenuBuilders(startupType);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var components  = assembly.GetTypes().ToArray();
            var controllers = components.Where(c => IsController(c.GetTypeInfo())).ToList();

            builder.PartManager.ApplicationParts.Add(new TypesPart(components));
        }