Example #1
0
        /// <summary>
        /// Configures a fabric construction using the provided configuration
        /// </summary>
        /// <param name="construction">The fabric construction</param>
        /// <param name="configuration">The configuration from dependency injection</param>
        /// <returns>The fabric construction</returns>
        public static FabricConstruction AddConfiguration(this FabricConstruction construction,
                                                          IConfiguration configuration)
        {
            // Add specific configuration
            construction.UseConfiguration(configuration);

            // Add configuration to services
            construction.ServiceCollection.AddSingleton(configuration);

            // Chain the construction
            return(construction);
        }
Example #2
0
        /// <summary>
        /// Configures the fabric construction in the default way
        /// </summary>
        /// <param name="construction">The construction to configure</param>
        /// <param name="configure">The custom configuration action</param>
        /// <returns>Fabric construction for chaining</returns>
        public static FabricConstruction AddLocalConfiguration(this FabricConstruction construction,
                                                               Action <IConfigurationBuilder> configure = null)
        {
            // Create configuration source
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()

                                                         // Add environment variables
                                                         .AddEnvironmentVariables();

            // If we are not on a mobile platform...
            if (!construction.Environment.IsMobile)
            {
                // Add file based configuration.

                // Set base path for JSON files as the startup location of the application
                configurationBuilder.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

                // Add application settings json files
                configurationBuilder.AddJsonFile("appsettings.json", true, true);
                configurationBuilder.AddJsonFile($"appsettings.{construction.Environment.Configuration}.json", true, true);
            }

            // Let custom configuration happen
            configure?.Invoke(configurationBuilder);

            // Inject configuration into services
            IConfiguration configuration = configurationBuilder.Build();

            construction.ServiceCollection.AddSingleton(configuration);

            // Set the construction configuration
            construction.UseConfiguration(configuration);

            // Chain the construction
            return(construction);
        }