public DefaultHisarStartup(IServiceProvider serviceProvider,
                            IHostingEnvironment hostingEnvironment,
                            IConfiguration configuration)
 {
     _hostingEnvironment = hostingEnvironment;
     Configuration       = Configuration;
     _componentStartup   = StartupTypeLoader.CreateHisarConventionBasedStartup(typeof(TStartup), serviceProvider, _hostingEnvironment);
 }
Exemple #2
0
        public DefaultHisarStartup(IServiceProvider sp, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration     = builder.Build();
            _env              = env;
            _loggerFactory    = loggerFactory;
            _componentStartup = StartupTypeLoader.CreateHisarConventionBasedStartup(typeof(TStartup), sp, _env);
        }
        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 #4
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));
        }