public static IServiceCollection AddModules(this IServiceCollection services, Action <ModulesOptions> optionsSetup)
        {
            var modulesOptions = new ModulesOptions();

            optionsSetup?.Invoke(modulesOptions);
            var moduleManager = new ModuleManager(services, modulesOptions);

            services.AddSingleton <IModuleManager>(moduleManager);
            return(services.Add(moduleManager.SharedServices));
        }
 public static void UseConfiguration(this ModulesOptions options, IConfiguration config)
 {
     foreach (var moduleConfig in config.GetSection("Modules").GetChildren())
     {
         ModuleInstanceOptions moduleInstanceOptions;
         if (!options.ModuleInstanceOptions.TryGetValue(moduleConfig.Key, out moduleInstanceOptions))
         {
             options.ModuleInstanceOptions[moduleConfig.Key] = new ModuleInstanceOptions();
         }
         options.ModuleInstanceOptions[moduleConfig.Key].PathBase = moduleConfig["PathBase"];
     }
 }
Exemplo n.º 3
0
        public ModuleManager(IServiceCollection services, ModulesOptions options)
        {
            _options = options;

            _hostingServices = CreateHostingServices(services);
            var moduleLoadContext = new ModuleLoadContext()
            {
                HostingEnvironment = services.GetServiceFromCollection <IHostingEnvironment>(),
                HostingServices    = _hostingServices,
                ModuleOptions      = options.ModuleOptions
            };
            var moduleDescriptors = _options.ModuleLoaders
                                    .SelectMany(moduleLoader => moduleLoader.GetModuleDescriptors(moduleLoadContext));

            foreach (var moduleDescriptor in moduleDescriptors)
            {
                var moduleStartup = moduleDescriptor.ModuleServiceCollection.BuildServiceProvider().GetRequiredService <IModuleStartup>();
                moduleStartup.ConfigureSharedServices(SharedServices);
                _modulesDescriptors[moduleDescriptor.Name] = moduleDescriptor;
            }
        }