private static OrderedModuleRegistration CreateModuleInstance( IModuleRegistration moduleRegistration, IKeyValueConfiguration keyValueConfiguration) { if (!moduleRegistration.ModuleType.IsPublicClassWithDefaultConstructor()) { if (moduleRegistration.ModuleType.TakesTypeInPublicCtor <IKeyValueConfiguration>()) { if (Activator.CreateInstance(moduleRegistration.ModuleType, keyValueConfiguration) is IModule moduleWithArgs) { return(new OrderedModuleRegistration(moduleRegistration, moduleWithArgs)); } } throw new DeployerAppException( $"Could not instantiate module type {moduleRegistration.ModuleType.FullName} with custom constructor"); } if (Activator.CreateInstance(moduleRegistration.ModuleType) is IModule module) { return(new OrderedModuleRegistration(moduleRegistration, module)); } throw new DeployerAppException( $"Could not instantiate module type {moduleRegistration.ModuleType.FullName} with default constructor"); }
public static IServiceCollection AddConfigurationInstancesFromAssemblies( [NotNull] this IServiceCollection services, [NotNull] IKeyValueConfiguration keyValueConfiguration, Action <Exception>?exceptionHandler, params Assembly[] assemblies) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } if (assemblies.Length == 0) { assemblies = new[] { Assembly.GetCallingAssembly() }; } var configurationRegistrations = keyValueConfiguration.ScanRegistrations(exceptionHandler, assemblies); var configurationInstanceHolder = configurationRegistrations.CreateHolder(); services.AddSingleton(configurationInstanceHolder); return(services.AddConfigurationInstanceHolder(configurationInstanceHolder)); }
public static Scope Start( IKeyValueConfiguration configuration, [NotNull] IReadOnlyList <IModule> modulesToRegister, [NotNull] ILogger logger, ImmutableArray <Assembly> assembliesToScan, [NotNull] IReadOnlyList <Type> excludedModuleTypes, [NotNull] IReadOnlyCollection <object> singletons) { GuardArgs(modulesToRegister, logger, assembliesToScan, excludedModuleTypes, singletons); var builder = new ContainerBuilder(); RegisterSingletons(singletons, builder); RegisterModules(modulesToRegister, logger, builder); Scope rootScope = CreateRootScope(builder); ILifetimeScope appRootScope = rootScope.Lifetime.BeginLifetimeScope(Scope.AppRootScopeName, appScopeBuilder => RegisterScannedModules( configuration, modulesToRegister, logger, assembliesToScan, excludedModuleTypes, Scope.AppRootScopeName, appScopeBuilder)); rootScope.SubScope = new Scope(Scope.AppRootScopeName, appRootScope); return(rootScope); }
public DefaultAuthorizationHandler( IKeyValueConfiguration keyValueConfiguration, ILogger logger, IEnumerable <AllowedEmail> allowedEmails, IEnumerable <AllowedEmailDomain> allowedEmailDomains) { _logger = logger; _allowedEmailDomains = allowedEmailDomains.SafeToImmutableArray(); _allowedEmails = allowedEmails.SafeToImmutableArray(); IPAddress[] ipAddressesFromConfig = keyValueConfiguration[DeployerAppConstants.AllowedIPs] .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(IPAddress.Parse) .ToArray(); IPNetwork[] ipNetworksFromConfig = keyValueConfiguration[DeployerAppConstants.AllowedIpNetworks] .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(network => (HasValue: IpNetworkParser.TryParse(network, out var ipNetwork), ipNetwork)) .Where(network => network.HasValue) .Select(network => network.ipNetwork !) .ToArray(); _allowedNetworks = ipNetworksFromConfig.ToImmutableHashSet(); _allowed = new HashSet <IPAddress> { IPAddress.Parse("::1"), IPAddress.Parse("127.0.0.1") }; foreach (IPAddress address in ipAddressesFromConfig) { _allowed.Add(address); } }
public static ImmutableArray <KeyValueConfigurationItem> GetKeyValueConfigurationItems( [NotNull] this IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } if (keyValueConfiguration is IKeyValueConfigurationWithMetadata keyValueConfigurationWithMetadata) { return(keyValueConfigurationWithMetadata.GetKeyValueConfigurationItems()); } var keyValueConfigurationItems = keyValueConfiguration .AllWithMultipleValues.Select(item => { var configurationItems = new List <KeyValueConfigurationItem>(); foreach (string value in item.Values) { configurationItems.Add( new KeyValueConfigurationItem(item.Key, value, null)); } return(configurationItems); }) .SelectMany(_ => _) .ToImmutableArray(); return(keyValueConfigurationItems); }
public void Register(ServiceProviderHolder serviceProviderHolder) { IServiceCollection services = serviceProviderHolder.ServiceCollection; CustomOpenIdConnectConfiguration?openIdConnectConfiguration = serviceProviderHolder.ServiceProvider.GetService <CustomOpenIdConnectConfiguration>(); var applicationAssemblyResolver = serviceProviderHolder.ServiceProvider.GetRequiredService <IApplicationAssemblyResolver>(); HttpLoggingConfiguration httpLoggingConfiguration = serviceProviderHolder.ServiceProvider.GetRequiredService <HttpLoggingConfiguration>(); MilouAuthenticationConfiguration?milouAuthenticationConfiguration = serviceProviderHolder.ServiceProvider.GetService <MilouAuthenticationConfiguration>(); ILogger logger = serviceProviderHolder.ServiceProvider.GetRequiredService <ILogger>(); EnvironmentConfiguration environmentConfiguration = serviceProviderHolder.ServiceProvider.GetRequiredService <EnvironmentConfiguration>(); IKeyValueConfiguration configuration = serviceProviderHolder.ServiceProvider.GetRequiredService <IKeyValueConfiguration>(); services.AddDeploymentAuthentication( logger, environmentConfiguration, milouAuthenticationConfiguration, openIdConnectConfiguration) .AddDeploymentAuthorization(environmentConfiguration) .AddHttpClientsWithConfiguration(httpLoggingConfiguration) .AddDeploymentSignalR() .AddServerFeatures() .AddDeploymentMvc(environmentConfiguration, configuration, logger, applicationAssemblyResolver); }
public SettingsViewModel( string targetReadService, ImmutableArray <ControllerRouteInfo> routes, ConfigurationInfo configurationInfo, ImmutableArray <ServiceRegistrationInfo> serviceRegistrations, IEnumerable <KeyValuePair <string, string> > aspNetConfigurationValues, IEnumerable <ServiceInstance> registrationInstances, LogEventLevel logEventLevel, ApplicationVersionInfo?applicationVersionInfo, IKeyValueConfiguration applicationMetadata, ImmutableArray <DeploymentTargetWorker> deploymentTargetWorkers, ApplicationSettings applicationSettings) { AspNetConfigurationValues = aspNetConfigurationValues.OrderBy(x => x.Key).ToImmutableArray(); TargetReadService = targetReadService; ConfigurationInfo = configurationInfo; RegistrationInstances = registrationInstances .OrderBy(serviceInstance => serviceInstance.RegistrationType).ToImmutableArray(); ServiceRegistrations = serviceRegistrations.OrderBy(serviceRegistrationInfo => serviceRegistrationInfo.ServiceDescriptorServiceType.FullName) .ToImmutableArray(); LogEventLevel = logEventLevel; ApplicationVersionInfo = applicationVersionInfo; ApplicationMetadata = applicationMetadata; DeploymentTargetWorkers = deploymentTargetWorkers; ApplicationSettings = applicationSettings; Routes = routes.OrderBy(route => route.Route.Value).ToImmutableArray(); ConfigurationValues = ImmutableArray <(object, string)> .Empty; }
public static ImmutableArray <OrderedModuleRegistration> GetModules( [NotNull] IReadOnlyCollection <Assembly> assemblies, [NotNull] IReadOnlyCollection <Type> excludedTypes, [NotNull] IKeyValueConfiguration configuration) { if (assemblies == null) { throw new ArgumentNullException(nameof(assemblies)); } if (excludedTypes == null) { throw new ArgumentNullException(nameof(excludedTypes)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } Type[] moduleTypes = assemblies .FindPublicConcreteTypesImplementing <IModule>() .Except(excludedTypes) .ToArray(); ImmutableArray <OrderedModuleRegistration> modules = moduleTypes .Select(moduleType => new ModuleRegistration(moduleType)) .Select(item => CreateModuleInstance(item, configuration)) .OrderBy(item => item.ModuleRegistration.Order) .ToImmutableArray(); return(modules); }
public BenchmarkGetItemByKey() { var keys = new NameValueCollection { { "urn:a:complex:immutable:type:instance1:id", "myId1" } }; _configuration = new InMemoryKeyValueConfiguration(keys); }
public void AllCollectionsShouldBeEmpty() { IKeyValueConfiguration configuration = NoConfiguration.Empty; configuration.AllKeys.IsEmpty.ShouldBeTrue(); configuration.AllValues.IsEmpty.ShouldBeTrue(); configuration.AllWithMultipleValues.IsEmpty.ShouldBeTrue(); }
public AppSettingsBuilder( [NotNull] IKeyValueConfiguration keyValueConfiguration, AppSettingsBuilder?previous) { KeyValueConfiguration = keyValueConfiguration ?? throw new ArgumentNullException(nameof(keyValueConfiguration)); Previous = previous; }
public PackageInstaller( ILogger logger, DeployerConfiguration deployerConfiguration, IKeyValueConfiguration keyValueConfiguration) { _logger = logger; _deployerConfiguration = deployerConfiguration; _keyValueConfiguration = keyValueConfiguration; }
public ConfigurationCredentialReadService( [NotNull] IKeyValueConfiguration keyValueConfiguration, [NotNull] ILogger logger) { _keyValueConfiguration = keyValueConfiguration ?? throw new ArgumentNullException(nameof(keyValueConfiguration)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public ImmutableArray <string> GetAllKeys([NotNull] IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } return(keyValueConfiguration.AllKeys); }
public static ConfigurationRegistrations GetRegistrations( this IKeyValueConfiguration keyValueConfiguration, Type type) { IEnumerable <UrnTypeRegistration> configurationInstanceHolders = GetInstancesForType(keyValueConfiguration, type); return(new ConfigurationRegistrations(configurationInstanceHolders.ToImmutableArray())); }
/// <summary> /// Add new configuration, last one wins /// </summary> /// <param name="keyValueConfiguration"></param> /// <returns></returns> public static AppSettingsBuilder Add([NotNull] IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } return(new AppSettingsBuilder(keyValueConfiguration, null)); }
public UrnConfigurationModule( [NotNull] IKeyValueConfiguration keyValueConfiguration, [NotNull] ILogger logger, ImmutableArray <Assembly> assemblies) { _keyValueConfiguration = keyValueConfiguration ?? throw new ArgumentNullException(nameof(keyValueConfiguration)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _assemblies = assemblies.ThrowIfDefault(); }
public ImmutableArray <StringPair> GetAllValues(IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } return(keyValueConfiguration.AllValues.Select(item => new StringPair(item.Key, GetValue(item.Value))) .ToImmutableArray()); }
public static IConfigurationBuilder AddKeyValueConfigurationSource( this IConfigurationBuilder builder, IKeyValueConfiguration keyValueConfiguration) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return(builder.Add(new KeyValueConfigurationSourceAdapter(keyValueConfiguration))); }
public void MultiSourceAllValues() { IKeyValueConfiguration configuration = KeyValueConfigurationManager.Add(NoConfiguration.Empty).Build(); if (configuration is IDisposable disposable) { disposable.Dispose(); } Assert.Throws <ObjectDisposedException>(() => configuration.AllValues.ToString()); }
public AppVersion( [NotNull] DeploymentTarget target, [NotNull] IKeyValueConfiguration manifestProperties, IReadOnlyCollection <PackageVersion> availablePackageVersions) { Properties = manifestProperties ?? throw new ArgumentNullException(nameof(manifestProperties)); AvailablePackageVersions = availablePackageVersions.SafeToImmutableArray(); Target = target ?? throw new ArgumentNullException(nameof(target)); Status = GetStatus(); }
public void NoConfigurationDispose() { IKeyValueConfiguration configuration = NoConfiguration.Empty; if (configuration is IDisposable disposable) { disposable.Dispose(); } configuration.AllKeys.IsEmpty.ShouldBeTrue(); }
public static string?GetApplicationName([NotNull] this IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration == null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } string name = keyValueConfiguration[ApplicationConstants.ApplicationNameKey]; return(string.IsNullOrWhiteSpace(name) ? Assembly.GetEntryAssembly()?.GetName().Name : name); }
public NuGetDownloadStartupTask(ILogger logger, IKeyValueConfiguration configuration, IHttpClientFactory httpClientFactory, TimeoutHelper timeoutHelper, NuGetConfiguration?nugetConfiguration = null) { _logger = logger; _configuration = configuration; _nugetConfiguration = nugetConfiguration; _httpClientFactory = httpClientFactory; _timeoutHelper = timeoutHelper; }
public ImmutableArray <MultipleValuesStringPair> GetAllWithMultipleValues( IKeyValueConfiguration keyValueConfiguration) { if (keyValueConfiguration == null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } return(keyValueConfiguration.AllWithMultipleValues.Select(item => new MultipleValuesStringPair(item.Key, item.Values.Select(ExpandValue).ToImmutableArray())) .ToImmutableArray()); }
public void MultiSourceShouldDisposeNested() { IKeyValueConfiguration inMemoryKeyValueConfiguration = new Core.InMemoryKeyValueConfiguration(new NameValueCollection()); IKeyValueConfiguration configuration = KeyValueConfigurationManager.Add(inMemoryKeyValueConfiguration).Build(); if (configuration is IDisposable disposable) { disposable.Dispose(); } Assert.Throws <ObjectDisposedException>(() => inMemoryKeyValueConfiguration.AllKeys.ToString()); }
public UserJsonConfiguration(string?basePath = null) { string?fileFullPath = TryGetConfigUser(basePath); if (!string.IsNullOrWhiteSpace(fileFullPath) && File.Exists(fileFullPath)) { var jsonConfiguration = new JsonKeyValueConfiguration(fileFullPath); _configuration = jsonConfiguration !; } _configuration ??= NoConfiguration.Empty !; _fileFullPath = fileFullPath; }
public static IServiceCollection AddDeploymentMvc(this IServiceCollection services, EnvironmentConfiguration environmentConfiguration, IKeyValueConfiguration configuration, ILogger logger, IApplicationAssemblyResolver applicationAssemblyResolver) { ViewAssemblyLoader.LoadViewAssemblies(logger); var filteredAssemblies = applicationAssemblyResolver.GetAssemblies(); IMvcBuilder mvcBuilder = services.AddMvc( options => { options.InputFormatters.Insert(0, new XWwwFormUrlEncodedFormatter()); options.Filters.Add <ModelValidatorFilterAttribute>(); }) .AddNewtonsoftJson( options => { options.SerializerSettings.Converters.Add(new DateConverter()); options.SerializerSettings.Formatting = Formatting.Indented; }); foreach (Assembly filteredAssembly in filteredAssemblies) { logger.Debug("Adding assembly {Assembly} to MVC application parts", filteredAssembly.FullName); mvcBuilder.AddApplicationPart(filteredAssembly); } var viewAssemblies = AssemblyLoadContext.Default.Assemblies .Where(assembly => !assembly.IsDynamic && (assembly.GetName().Name?.Contains("View") ?? false)) .ToArray(); foreach (var item in viewAssemblies) { mvcBuilder.AddApplicationPart(item); } if (environmentConfiguration.ToHostEnvironment().IsDevelopment() || configuration.ValueOrDefault(StartupConstants.RuntimeCompilationEnabled)) { mvcBuilder.AddRazorRuntimeCompilation(); } mvcBuilder .AddControllersAsServices(); services.AddAntiforgery(); return(services); }
public DeployerApp( [NotNull] ILogger logger, [NotNull] DeploymentService deploymentService, [NotNull] IKeyValueConfiguration appSettings, [NotNull] LoggingLevelSwitch levelSwitch, [NotNull] CancellationTokenSource cancellationTokenSource) { LevelSwitch = levelSwitch ?? throw new ArgumentNullException(nameof(levelSwitch)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); _deploymentService = deploymentService ?? throw new ArgumentNullException(nameof(deploymentService)); _appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings)); _cancellationTokenSource = cancellationTokenSource ?? throw new ArgumentNullException(nameof(cancellationTokenSource)); _appExit = new AppExit(Logger); }
public PackageService( [NotNull] NuGetListConfiguration deploymentConfiguration, [NotNull] IKeyValueConfiguration keyValueConfiguration, [NotNull] ILogger logger, [NotNull] NuGetConfiguration nuGetConfiguration, [NotNull] NuGetPackageInstaller packageInstaller) { _deploymentConfiguration = deploymentConfiguration ?? throw new ArgumentNullException(nameof(deploymentConfiguration)); _keyValueConfiguration = keyValueConfiguration ?? throw new ArgumentNullException(nameof(keyValueConfiguration)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _nuGetConfiguration = nuGetConfiguration ?? throw new ArgumentNullException(nameof(nuGetConfiguration)); _packageInstaller = packageInstaller ?? throw new ArgumentNullException(nameof(packageInstaller)); }