private static IHost CreateWebJobsHost <T>(string path)
            where T : FunctionsStartup, new()
        {
            string contentRoot = GetProjectPath(path, typeof(T));

            return(new HostBuilder()
                   .UseContentRoot(contentRoot)
                   .ConfigureLogging(b => b.AddConsole())
                   .ConfigureAppConfiguration(b => b
                                              .Add(AzureFunctionsConfiguration.CreateRoot())
                                              .Add(new HostJsonFileConfigurationSource(contentRoot))
                                              .Add(EnvironmentConfig.FromLocalSettings(contentRoot)))
                   .ConfigureWebJobs((c, b) => b
                                     .UseWebJobsStartup(typeof(T), new WebJobsBuilderContext {
                Configuration = c.Configuration
            }, NullLoggerFactory.Instance)
                                     .AddDurableTask())
                   .Build());
        }
        public static IServiceCollection AddLogging(this IServiceCollection services, AzureFunctionsConfiguration azureFunctionsConfiguration)
        {
            services.AddLogging(logging =>
            {
                logging.AddConfiguration(azureFunctionsConfiguration.Configuration.GetSection("Logging"));

                if (azureFunctionsConfiguration.IsLocal())
                {
                    logging.AddConsole();
                    logging.AddDebug();
                }
                else
                {
                    logging.AddApplicationInsights();
                    logging.AddAzureWebAppDiagnostics();
                }
            });

            return(services);
        }
        public static IServiceCollection AddAzureFunctionsFramework <TDbContext>(this IServiceCollection services, AzureFunctionsConfiguration azureFunctionsConfiguration) where TDbContext : DbContext
        {
            services = AddAzureFunctionsFramework(services, azureFunctionsConfiguration);

            services.AddDbContextUtilities <TDbContext>(azureFunctionsConfiguration);

            return(services);
        }
        public static IServiceCollection AddAzureFunctionsFramework(this IServiceCollection services, AzureFunctionsConfiguration azureFunctionsConfiguration)
        {
            // Add Web Framework
            services.AddWebFramework(azureFunctionsConfiguration);

            // Add Logging
            services.AddLogging(azureFunctionsConfiguration);

            // Add AzureFunctionsConfiguration
            services.AddSingleton(azureFunctionsConfiguration);

            // Add Functions
            if (azureFunctionsConfiguration.FunctionTypes.Any())
            {
                services.AddTypes(azureFunctionsConfiguration.FunctionTypes);
            }

            // Add Event Handler framework
            if (azureFunctionsConfiguration.IsEventHandler)
            {
                services.AddSingletonUsernameProvider(azureFunctionsConfiguration.ApplicationName);
            }

            // Add types needed for Azure Functions
            services.Add <IAzureFunctionsCommandExecutor, AzureFunctionsCommandExecutor>(azureFunctionsConfiguration.ServiceLifetime);

            return(services);
        }
Beispiel #5
0
 public Startup()
 {
     _azureFunctionsConfiguration = BuildAzureFunctionsConfiguration();
 }