/// <summary>
        /// Adds environment variables to the application
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <param name="configureOptions"></param>
        /// <returns></returns>
        public static IServiceCollection AddEnvironment(this IServiceCollection serviceCollection, Action <EnvironmentOptions> configureOptions = null)
        {
            // configure environment variable options
            var options = new EnvironmentOptions();

            configureOptions?.Invoke(options);
            serviceCollection.AddSingleton(options);

            // add environment to the
            serviceCollection.TryAdd(ServiceDescriptor.Scoped <IEnvironment, Environment>());

            return(serviceCollection);
        }
예제 #2
0
        /// <summary>
        /// Instantiates an <see cref="Environment"/>
        /// </summary>
        /// <param name="options"></param>
        public Environment(EnvironmentOptions options)
        {
            Options = options;

            VariableProviders = Options.VariableProviders.Concat(Options.VariableProviderFactories.Select(f => f(this))).ToList();
        }