Exemplo n.º 1
0
        public ModuleInstance(
            ModuleDescriptor moduleDescriptor,
            string moduleInstanceId,
            PathString pathBase,
            IServiceCollection sharedServices,
            IServiceProvider appServiceProvider,
            ModuleInstanceOptions options)
        {
            ModuleDescriptor = moduleDescriptor;
            ModuleInstanceId = moduleInstanceId;
            PathBase         = pathBase;

            AddSharedServices(sharedServices, appServiceProvider);
            ModuleServiceCollection.Add(moduleDescriptor.ModuleServiceCollection);
            ModuleServiceCollection.AddSingleton <ModuleInstanceIdProvider>(new ModuleInstanceIdProvider(moduleInstanceId));
            ModuleServiceCollection.AddSingleton <IRootServiceProvider>(new RootServiceProvider(appServiceProvider));
            if (options != null)
            {
                foreach (var configureServices in options.ConfigureServices)
                {
                    configureServices(ModuleServiceCollection);
                }
            }
            ModuleServices = ModuleServiceCollection.BuildServiceProvider();
        }
Exemplo n.º 2
0
 void AddSharedServices(IServiceCollection sharedServices, IServiceProvider appServiceProvider)
 {
     foreach (var sd in sharedServices)
     {
         if (!sd.ServiceType.GetTypeInfo().IsGenericTypeDefinition&& sd.Lifetime != ServiceLifetime.Transient)
         {
             ModuleServiceCollection.Add(ServiceDescriptor.Describe(
                                             sd.ServiceType,
                                             sp => appServiceProvider.GetRequiredService(sd.ServiceType),
                                             sd.Lifetime));
         }
         else
         {
             // TODO: How to preserve lifetime for generic services?
             ModuleServiceCollection.Add(sd);
         }
     }
 }
Exemplo n.º 3
0
        IModuleStartup GetModuleStartup()
        {
            if (typeof(IModuleStartup).GetTypeInfo().IsAssignableFrom(ModuleStartupType))
            {
                ModuleServiceCollection.AddSingleton(typeof(IModuleStartup), ModuleStartupType);
            }
            else
            {
                ModuleServiceCollection.AddSingleton <IModuleStartup>(sp =>
                {
                    var hostingEnvironment = sp.GetRequiredService <IHostingEnvironment>();
                    return(new ConventionBasedModuleStartup(
                               ModuleStartupLoader.LoadMethods(sp, ModuleStartupType, hostingEnvironment.EnvironmentName)));
                });
            }
            var moduleHostingServiceProvider = ModuleServiceCollection.BuildServiceProvider();

            return(moduleHostingServiceProvider.GetRequiredService <IModuleStartup>());
        }
Exemplo n.º 4
0
 void AddHostingServices()
 {
     ModuleServiceCollection.Add(_hostingServices);
     ModuleServiceCollection.AddSingleton(ModuleHostingEnvironment);
 }