/// <summary>
        /// Generates and returns the <see cref="DeliveryOptions"/> instance.
        /// </summary>
        /// <returns>The <see cref="DeliveryOptions"/> instance.</returns>
        public DeliveryOptions GetDeliveryOptions()
        {
            var configuration = new ConfigurationBuilder().Add(this).Build();
            var result        = new DeliveryOptions();

            configuration.Bind(result);
            return(result);
        }
Example #2
0
        public static ServiceProvider BuildConfiguration(Action <ServiceCollection> servicesToAdd = null)
        {
            var environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");

            var configuration = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", false)
                                .AddJsonFile($"appsettings.{environmentName}.json", true)
                                .AddEnvironmentVariables()
                                .Build();

            var services = new ServiceCollection();

            services.AddOptions();

            var config = new AppSettings();

            configuration.Bind(AppSettings.Section, config);
            services.AddSingleton(config);

            servicesToAdd?.Invoke(services);

            return(services.BuildServiceProvider());
        }