/// <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);
        }
Exemplo n.º 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();
        }