Example #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            #region YellowCounter.AzureFunctions.AspNetConfiguration
            //builder.UseAspNetConfiguration();
            //var configuration = builder.GetConfiguration();
            #endregion

            #region Stef
            var configBuilder = new ConfigurationBuilder();

            string scriptRoot = AzureFunctionUtils.GetAzureWebJobsScriptRoot();
            if (!string.IsNullOrEmpty(scriptRoot))
            {
                configBuilder.SetBasePath(scriptRoot).AddJsonFile("local.settings.json", optional: false, reloadOnChange: false);
            }
            configBuilder.AddEnvironmentVariables();

            var configuration = configBuilder.Build();
            #endregion

            // Add Services
            builder.Services.AddScoped <ISmartContractService, SmartContractService>();

            // Add 3rdParty Services
            builder.Services.AddAzureTableStorage();

            // Configure
            builder.Services.Configure <FunctionAppOptions>(configuration.GetSection("FunctionAppOptions"));
            builder.Services.Configure <AzureTableStorageOptions>(configuration.GetSection("AzureTableStorageOptions"));
        }
Example #2
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var configBuilder = new ConfigurationBuilder();

            string scriptRoot = AzureFunctionUtils.GetAzureWebJobsScriptRoot();

            // By default, only the "Values" section from local.settings.json is read.
            // In order to read more custom configuration sections, we need to use AddJsonFile(...)
            if (!string.IsNullOrEmpty(scriptRoot))
            {
                configBuilder.SetBasePath(scriptRoot).AddJsonFile("local.settings.json", optional: false, reloadOnChange: false);

                if (!AzureFunctionUtils.IsAzureEnvironment())
                {
                    // In case we are running locally, also add the development file.
                    configBuilder.SetBasePath(scriptRoot).AddJsonFile("local.settings.development.json", optional: true, reloadOnChange: false);
                }
            }

            configBuilder.AddEnvironmentVariables();

            var configuration = configBuilder.Build();

            // Add Services
            builder.Services.AddSingleton(configuration);
            builder.Services.AddSingleton <INameResolver, CustomNameResolver>();

            // Logging
            builder.Services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddApplicationInsights();
                loggingBuilder.AddConsole();
            });

            // Options
            builder.Services.Configure <MyOptions>(configuration.GetSection("MyOptions"));
        }