public static BellightCoreOptions AddBellightConfigurations(this BellightCoreOptions options, bool isDevelopment = false, string environment = null, string[] args = null) { var configuration = new ConfigurationBuilder() .InitialiseBellightConfigurations(isDevelopment, environment, args) .Build(); return(options.AddConfigurations(configuration)); }
public static BellightCoreOptions AddConfigurations(this BellightCoreOptions options, IConfiguration configuration) { return(options .AddStartupServiceAction(startupContainerServices => { startupContainerServices.AddSingleton(configuration); startupContainerServices.AddTypeHandler <AppSettingsTypeHandler>(); }) .AddStartupContainerAction((_, services) => { services.AddSingleton(configuration); services.AddOptions(); })); }
public static BellightCoreOptions AddAutoMapper(this BellightCoreOptions options, Action <IMapperConfigurationExpression> configAction = null) { return(options .AddStartupServiceAction(startupContainerServices => { startupContainerServices.AddTypeHandler <ModelMappingTypeHandler>(); startupContainerServices.AddSingleton <IModelRegistrationService, DefaultModelRegistrationService>(); }) .AddStartupContainerAction((startupServiceProvider, services) => { var modelRegistrationService = startupServiceProvider.GetService <IModelRegistrationService>(); services.AddSingleton <IModelMappingService>(new ModelMappingService(modelRegistrationService, configAction)); })); }
public static BellightCoreOptions AddDependencyHandler(this BellightCoreOptions options) { return(options .AddStartupServiceAction(startupContainerServices => { startupContainerServices.AddSingleton <IKeyedServiceRegistry, DefaultKeyedServiceRegistry>(); startupContainerServices.AddScoped <DependencyTypeHandler>(); startupContainerServices.AddScoped <ITypeHandler, DependencyTypeHandler>(); }) .AddStartupContainerAction((startupServiceProvider, services) => { var keyedServiceRegistry = startupServiceProvider.GetService <IKeyedServiceRegistry>(); var keyedTypeDictionary = keyedServiceRegistry.GetDictionary(); services.AddScoped <IKeyedServiceFactory>(sp => new KeyedServiceFactory(keyedTypeDictionary, sp)); })); }
public static IServiceCollection ScanAndRegisterServices(IServiceCollection services, BellightCoreOptions options) { var startupContainerServices = new ServiceCollection(); startupContainerServices.AddTransient <ISerializer, BellightJsonSerializer>(); startupContainerServices.AddTransient <IAssemblyLoader, DefaultAssemblyLoader>(); startupContainerServices.AddTransient <IAssemblyHandler, DefaultAssemblyHandler>(); startupContainerServices.AddTransient <IAssemblyScanner, DefaultAssemblyScanner>(); startupContainerServices.AddSingleton(options); startupContainerServices.AddScoped <IDependencyCacheService, DefaultDependencyCacheService>(); startupContainerServices.AddScoped <IServiceCollection, ServiceCollection>(); if (options.StartupBuilderActions?.Any() == true) { foreach (var action in options.StartupBuilderActions) { action(startupContainerServices); } } var startupServiceProvider = startupContainerServices.BuildServiceProvider(); IServiceCollection innerServices = null; using (var cacheScope = startupServiceProvider.CreateScope()) { var dependencyCacheService = cacheScope.ServiceProvider.GetService <IDependencyCacheService>(); if (dependencyCacheService.Load()) { innerServices = cacheScope.ServiceProvider.GetService <IServiceCollection>(); } } if (innerServices != null) { MergeServiceCollections(services, innerServices); } else { using (var loadScope = startupServiceProvider.CreateScope()) { var assemblyScanner = loadScope.ServiceProvider.GetService <IAssemblyScanner>(); var dependencyModel = assemblyScanner.Scan(); innerServices = loadScope.ServiceProvider.GetService <IServiceCollection>(); MergeServiceCollections(services, innerServices); Task.Factory.StartNew(() => SaveDependencyCache(dependencyModel, startupServiceProvider)); } } if (options.StartupContainerActions?.Any() == true) { foreach (var action in options.StartupContainerActions) { action(startupServiceProvider, services); } } return(services); }