Пример #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();
        }
Пример #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);
         }
     }
 }
Пример #3
0
 void AddHostingServices()
 {
     ModuleServiceCollection.Add(_hostingServices);
     ModuleServiceCollection.AddSingleton(ModuleHostingEnvironment);
 }