/// <summary> /// Initialises a new instance of <see cref="TenantResolver"/>. /// </summary> /// <param name="featureStateProvider">The feature state provider.</param> /// <param name="configuration">The configuration.</param> public TenantResolver(IFeatureStateProvider featureStateProvider) { _featureStateProvider = Ensure.IsNotNull(featureStateProvider, nameof(featureStateProvider)); _tenancyFeatureState = featureStateProvider.GetFeatureState(CoreInfo.TenancyFeatureId); _configThunk = new Lazy <TenantsConfiguration>(() => ResolveConfiguration(_tenancyFeatureState.ConfigurationSection)); }
/// <inheritdoc /> public IFeature <TService> CreateFeature(IServiceProvider serviceProvider, FeatureId featureId) { Ensure.IsNotNull(serviceProvider, nameof(serviceProvider)); var state = (!_workContext.TenantId.Equals(TenantId.Empty) && !_workContext.TenantId.Equals(TenantId.Default)) ? _featureStateProvider.GetFeatureState(featureId, _workContext.TenantId) : _featureStateProvider.GetFeatureState(featureId); var service = serviceProvider.GetService <TService>(); bool missing = Equals(default(TService), service); return(new Feature <TService>( featureId, state.Enabled, missing, service, state.ConfigurationSection)); }
/// <inheritdoc /> public Action <IApplicationBuilder> Configure(Action <IApplicationBuilder> next) { Ensure.IsNotNull(next, nameof(next)); var context = new FeatureInitialisationContext(_serviceProvider); foreach (var feature in _featureProvider.Features) { var state = _featureStateProvider.GetFeatureState(feature.Id); if (state != null && state.Enabled) { feature.Initialise(context); } } return(next); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IModuleProvider moduleProvider, IFeatureProvider featureProvider, IFeatureStateProvider featureStateProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } foreach (var module in moduleProvider.Modules) { Console.WriteLine($"Module: {module.Id}"); } foreach (var feature in featureProvider.Features) { if ((featureStateProvider.GetFeatureState(feature.Id)?.Enabled).GetValueOrDefault(false)) { Console.WriteLine($"Feature: {feature.Id}"); } } app.Run(async(context) => { Console.WriteLine($"Executing for {context.Request.Path}"); var feature1 = context.RequestServices.GetRequiredService <IFeature <IAppService> >(); var feature2 = context.RequestServices.GetRequiredService <IFeature <IAppService, AppFeatureConfiguration> >(); if (feature1.Enabled) { feature1.Service.DoAction(); } if (feature2.Enabled) { feature2.Service.DoAction(feature2.Configuration); } var tenantService = context.RequestServices.GetRequiredService <ITenantService>(); tenantService.DoAction(); }); }
/// <summary> /// Extends the application configuration. /// </summary> /// <param name="context">The web host builder context.</param> /// <param name="builder">The configuration builder.</param> public void ExtendConfiguration(WebHostBuilderContext context, IConfigurationBuilder builder) { Ensure.IsNotNull(context, nameof(context)); Ensure.IsNotNull(builder, nameof(builder)); foreach (var module in _moduleProvider.Modules) { if (module is IAppConfigurationExtender extender) { extender.BuildConfiguration(context, builder); } } foreach (var feature in _featureProvider.Features) { var state = _featureStateProvider.GetFeatureState(feature.Id); if (state != null && state.Enabled && feature is IAppConfigurationExtender extender) { extender.BuildConfiguration(context, builder); } } }