예제 #1
0
        public static void AddWebJobsScriptHost(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddWebJobsScriptHostRouting();
            services.AddMvc()
            .AddXmlDataContractSerializerFormatters();

            // Standby services
            services.AddStandbyServices();

            services.AddSingleton <IScriptHostManager>(s => s.GetRequiredService <WebJobsScriptHostService>());
            services.AddSingleton <IScriptWebHostEnvironment, ScriptWebHostEnvironment>();
            services.AddSingleton <IStandbyManager, StandbyManager>();
            services.TryAddSingleton <IScriptHostBuilder, DefaultScriptHostBuilder>();

            // Linux container services
            services.AddLinuxContainerServices();

            // ScriptSettingsManager should be replaced. We're setting this here as a temporary step until
            // broader configuaration changes are made:
            services.AddSingleton <ScriptSettingsManager>();
            services.AddSingleton <IEventGenerator>(p =>
            {
                var environment = p.GetService <IEnvironment>();
                if (environment.IsLinuxContainerEnvironment())
                {
                    return(new LinuxContainerEventGenerator());
                }
                else if (SystemEnvironment.Instance.IsLinuxAppServiceEnvironment())
                {
                    return(new LinuxAppServiceEventGenerator(new LinuxAppServiceFileLoggerFactory()));
                }
                else
                {
                    return(new EtwEventGenerator());
                }
            });

            // Management services
            services.AddSingleton <IWebFunctionsManager, WebFunctionsManager>();
            services.AddSingleton <IInstanceManager, InstanceManager>();
            services.AddSingleton(_ => new HttpClient());
            services.AddSingleton <IFileSystem>(_ => FileUtility.Instance);
            services.AddTransient <VirtualFileSystem>();
            services.AddTransient <VirtualFileSystemMiddleware>();

            // Secret management
            services.TryAddSingleton <ISecretManagerProvider, DefaultSecretManagerProvider>();

            // Register common services with the WebHost
            // Language Worker Hosted Services need to be intialized before WebJobsScriptHostService
            ScriptHostBuilderExtensions.AddCommonServices(services);

            // Core script host services
            services.AddSingleton <WebJobsScriptHostService>();
            services.AddSingleton <IHostedService>(s => s.GetRequiredService <WebJobsScriptHostService>());

            // Configuration
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IConfigureOptions <ScriptApplicationHostOptions>, ScriptApplicationHostOptionsSetup>());
            services.ConfigureOptions <LanguageWorkerOptionsSetup>();
        }
예제 #2
0
        public void ServicesDisabled_InPlaceholderMode()
        {
            IHost host;

            using (new TestScopedEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1"))
            {
                host = new HostBuilder()
                       .ConfigureLogging((context, builder) =>
                {
                    ScriptHostBuilderExtensions.ConfigureApplicationInsights(context, builder);
                })
                       .ConfigureServices(s =>
                {
                    s.AddSingleton <IEnvironment>(SystemEnvironment.Instance);
                })
                       .Build();
            }

            // No DependencyTrackingTelemetryModule should be registered
            var modules = host.Services.GetService <IEnumerable <ITelemetryModule> >();

            Assert.Empty(modules.Where(m => m.GetType() == typeof(DependencyTrackingTelemetryModule)));

            var appInsightsOptions = host.Services.GetService <IOptions <ApplicationInsightsLoggerOptions> >();

            Assert.False(appInsightsOptions.Value.HttpAutoCollectionOptions.EnableHttpTriggerExtendedInfoCollection);
        }
예제 #3
0
        public static void AddWebJobsScriptHost(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddHttpContextAccessor();
            services.AddWebJobsScriptHostRouting();

            services.AddMvc(o =>
            {
                o.EnableEndpointRouting = false;
                o.Filters.Add(new ArmExtensionResourceFilter());
            })
            .AddNewtonsoftJson()
            .AddXmlDataContractSerializerFormatters();

            // Standby services
            services.AddStandbyServices();

            services.AddSingleton <IScriptHostManager>(s => s.GetRequiredService <WebJobsScriptHostService>());
            services.AddSingleton <IScriptWebHostEnvironment, ScriptWebHostEnvironment>();
            services.TryAddSingleton <IStandbyManager, StandbyManager>();
            services.TryAddSingleton <IScriptHostBuilder, DefaultScriptHostBuilder>();

            // Linux container services
            services.AddLinuxContainerServices();

            // ScriptSettingsManager should be replaced. We're setting this here as a temporary step until
            // broader configuaration changes are made:
            services.AddSingleton <ScriptSettingsManager>();
            services.AddSingleton <IEventGenerator>(p =>
            {
                var environment = p.GetService <IEnvironment>();
                if (environment.IsLinuxConsumption())
                {
                    return(new LinuxContainerEventGenerator(environment));
                }
                else if (SystemEnvironment.Instance.IsLinuxAppService())
                {
                    var hostNameProvider = p.GetService <HostNameProvider>();
                    return(new LinuxAppServiceEventGenerator(new LinuxAppServiceFileLoggerFactory(), hostNameProvider));
                }
                else
                {
                    return(new EtwEventGenerator());
                }
            });

            // Management services
            services.AddSingleton <IFunctionsSyncManager, FunctionsSyncManager>();
            services.AddSingleton <IFunctionMetadataManager, FunctionMetadataManager>();
            services.AddSingleton <IFunctionMetadataProvider, FunctionMetadataProvider>();
            services.AddSingleton <IWebFunctionsManager, WebFunctionsManager>();
            services.AddSingleton <IInstanceManager, InstanceManager>();
            services.AddSingleton(_ => new HttpClient());
            services.AddSingleton <StartupContextProvider>();
            services.AddSingleton <HostNameProvider>();
            services.AddSingleton <IFileSystem>(_ => FileUtility.Instance);
            services.AddTransient <VirtualFileSystem>();
            services.AddTransient <VirtualFileSystemMiddleware>();

            // Logging and diagnostics
            services.AddSingleton <IMetricsLogger, WebHostMetricsLogger>();

            // Secret management
            services.TryAddSingleton <ISecretManagerProvider, DefaultSecretManagerProvider>();

            // Register common services with the WebHost
            // Language Worker Hosted Services need to be intialized before WebJobsScriptHostService
            ScriptHostBuilderExtensions.AddCommonServices(services);

            // Core script host services
            services.AddSingleton <WebJobsScriptHostService>();
            services.AddSingleton <IHostedService>(s => s.GetRequiredService <WebJobsScriptHostService>());

            // Handles shutdown of services that need to happen after StopAsync() of all services of type IHostedService are complete.
            // Order is important.
            // All other IHostedService injections need to go before this.
            services.AddSingleton <IHostedService, HostedServiceManager>();

            // Configuration
            services.ConfigureOptions <ScriptApplicationHostOptionsSetup>();
            services.ConfigureOptions <StandbyOptionsSetup>();
            services.ConfigureOptions <LanguageWorkerOptionsSetup>();
            services.ConfigureOptionsWithChangeTokenSource <AppServiceOptions, AppServiceOptionsSetup, SpecializationChangeTokenSource <AppServiceOptions> >();
            services.ConfigureOptionsWithChangeTokenSource <HttpBodyControlOptions, HttpBodyControlOptionsSetup, SpecializationChangeTokenSource <HttpBodyControlOptions> >();

            services.TryAddSingleton <IDependencyValidator, DependencyValidator>();
            services.TryAddSingleton <IJobHostMiddlewarePipeline>(s => DefaultMiddlewarePipeline.Empty);
        }
예제 #4
0
        public static void AddWebJobsScriptHost(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddHttpContextAccessor();
            services.AddWebJobsScriptHostRouting();

            services.AddMvc(o =>
            {
                o.EnableEndpointRouting = false;
                o.Filters.Add(new ArmExtensionResourceFilter());
            })
            .AddNewtonsoftJson()
            .AddXmlDataContractSerializerFormatters();

            // Standby services
            services.AddStandbyServices();

            services.AddSingleton <IScriptHostManager>(s => s.GetRequiredService <WebJobsScriptHostService>());
            services.AddSingleton <IScriptWebHostEnvironment, ScriptWebHostEnvironment>();
            services.TryAddSingleton <IStandbyManager, StandbyManager>();
            services.TryAddSingleton <IScriptHostBuilder, DefaultScriptHostBuilder>();

            // Linux container services
            services.AddLinuxContainerServices();

            // ScriptSettingsManager should be replaced. We're setting this here as a temporary step until
            // broader configuration changes are made:
            services.AddSingleton <ScriptSettingsManager>();
            services.AddSingleton <IEventGenerator>(p =>
            {
                var environment = p.GetService <IEnvironment>();
                if (environment.IsLinuxConsumption())
                {
                    return(new LinuxContainerEventGenerator(environment));
                }
                else if (SystemEnvironment.Instance.IsLinuxAppService())
                {
                    var hostNameProvider = p.GetService <HostNameProvider>();
                    return(new LinuxAppServiceEventGenerator(new LinuxAppServiceFileLoggerFactory(), hostNameProvider));
                }
                else if (environment.IsKubernetesManagedHosting())
                {
                    return(new KubernetesEventGenerator());
                }
                else
                {
                    return(new EtwEventGenerator());
                }
            });

            // Management services
            services.AddSingleton <IFunctionsSyncManager, FunctionsSyncManager>();
            services.AddSingleton <IFunctionMetadataManager, FunctionMetadataManager>();
            services.AddSingleton <IFunctionMetadataProvider, HostFunctionMetadataProvider>();
            services.AddSingleton <IWebFunctionsManager, WebFunctionsManager>();
            services.AddSingleton <IInstanceManager, InstanceManager>();
            services.AddHttpClient();
            services.AddSingleton <StartupContextProvider>();
            services.AddSingleton <IFileSystem>(_ => FileUtility.Instance);
            services.AddTransient <VirtualFileSystem>();
            services.AddTransient <VirtualFileSystemMiddleware>();

            // Logging and diagnostics
            services.AddSingleton <IMetricsLogger, WebHostMetricsLogger>();

            // Secret management
            services.TryAddSingleton <ISecretManagerProvider, DefaultSecretManagerProvider>();

            // Shared memory data transfer and function data cache
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                services.AddSingleton <IMemoryMappedFileAccessor, MemoryMappedFileAccessorWindows>();
            }
            else
            {
                services.AddSingleton <IMemoryMappedFileAccessor, MemoryMappedFileAccessorUnix>();
            }
            services.AddSingleton <ISharedMemoryManager, SharedMemoryManager>();
            services.AddSingleton <IFunctionDataCache, FunctionDataCache>();

            // Grpc
            services.AddScriptGrpc();

            // Register common services with the WebHost
            // Language Worker Hosted Services need to be intialized before WebJobsScriptHostService
            ScriptHostBuilderExtensions.AddCommonServices(services);

            // Core script host services
            services.AddSingleton <WebJobsScriptHostService>();
            services.AddSingleton <IHostedService>(s => s.GetRequiredService <WebJobsScriptHostService>());

            // Performs function assembly analysis to generete log use of unoptimized assemblies.
            services.AddSingleton <IHostedService, AssemblyAnalyzer.AssemblyAnalysisService>();

            // Handles shutdown of services that need to happen after StopAsync() of all services of type IHostedService are complete.
            // Order is important.
            // All other IHostedService injections need to go before this.
            services.AddSingleton <IHostedService, HostedServiceManager>();

            // Configuration

            // ScriptApplicationHostOptions are special in that they need to be reset on specialization, but the reset
            // must happen after the StandbyOptions have reset. For this reason, we have a special ChangeTokenSource that
            // will reset the ScriptApplicationHostOptions only after StandbyOptions have been reset.
            services.ConfigureOptions <ScriptApplicationHostOptionsSetup>();
            services.AddSingleton <IOptionsChangeTokenSource <ScriptApplicationHostOptions>, ScriptApplicationHostOptionsChangeTokenSource>();

            services.ConfigureOptions <StandbyOptionsSetup>();
            services.ConfigureOptions <LanguageWorkerOptionsSetup>();
            services.ConfigureOptionsWithChangeTokenSource <AppServiceOptions, AppServiceOptionsSetup, SpecializationChangeTokenSource <AppServiceOptions> >();
            services.ConfigureOptionsWithChangeTokenSource <HttpBodyControlOptions, HttpBodyControlOptionsSetup, SpecializationChangeTokenSource <HttpBodyControlOptions> >();

            services.TryAddSingleton <IDependencyValidator, DependencyValidator>();
            services.TryAddSingleton <IJobHostMiddlewarePipeline>(s => DefaultMiddlewarePipeline.Empty);

            // Add AzureBlobStorageProvider to WebHost (also needed for ScriptHost)
            services.AddAzureBlobStorageProvider();
        }