Exemplo n.º 1
0
        public static IServiceProvider AddWebJobsScriptHost(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddWebJobsScriptHostRouting();
            services.AddMvc()
            .AddXmlDataContractSerializerFormatters();

            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, WebJobsScriptHostService>());

            // TODO: This is a direct port from the current model.
            // Some of those services (or the way we register them) may need to change
            var builder = new ContainerBuilder();

            // ScriptSettingsManager should be replaced. We're setting this here as a temporary step until
            // broader configuaration changes are made:
            ScriptSettingsManager.Instance.SetConfigurationFactory(() => configuration);
            builder.RegisterInstance(ScriptSettingsManager.Instance);

            builder.RegisterType <DefaultSecretManagerFactory>().As <ISecretManagerFactory>().SingleInstance();
            builder.RegisterType <ScriptEventManager>().As <IScriptEventManager>().SingleInstance();
            builder.RegisterType <EventGenerator>().As <IEventGenerator>().SingleInstance();
            builder.Register(c => WebHostSettings.CreateDefault(c.Resolve <ScriptSettingsManager>()));

            // Pass a specially-constructed LoggerFactory to the WebHostResolver. This LoggerFactory is only used
            // when there is no host available.
            // Only use this LoggerFactory for this constructor; use the registered ILoggerFactory below everywhere else.
            builder.RegisterType <WebHostResolver>().SingleInstance()
            .WithParameter(new ResolvedParameter(
                               (pi, ctx) => pi.ParameterType == typeof(ILoggerFactory),
                               (pi, ctx) => CreateLoggerFactory(string.Empty, ctx.Resolve <ScriptSettingsManager>(), ctx.Resolve <IEventGenerator>(), ctx.Resolve <WebHostSettings>())));

            // Register the LoggerProviderFactory, which defines the ILoggerProviders for the host.
            builder.RegisterType <WebHostLoggerProviderFactory>().As <ILoggerProviderFactory>().SingleInstance();

            // Temporary - This should be replaced with a simple type registration.
            builder.Register <IExtensionsManager>(c =>
            {
                var hostInstance = c.Resolve <WebScriptHostManager>().Instance;
                return(new ExtensionsManager(hostInstance.ScriptConfig.RootScriptPath, hostInstance.Logger, hostInstance.ScriptConfig.NugetFallBackPath));
            });

            // The services below need to be scoped to a pseudo-tenant (warm/specialized environment)
            builder.Register <WebScriptHostManager>(c => c.Resolve <WebHostResolver>().GetWebScriptHostManager()).ExternallyOwned();
            builder.Register <ISecretManager>(c => c.Resolve <WebHostResolver>().GetSecretManager()).ExternallyOwned();
            builder.RegisterType <WebFunctionsManager>().As <IWebFunctionsManager>().SingleInstance();
            builder.RegisterType <VirtualFileSystem>();
            builder.RegisterType <VirtualFileSystemMiddleware>();

            // Populate the container builder with registered services.
            // Doing this here will cause any services registered in the service collection to
            // override the registrations above
            builder.Populate(services);

            builder.Register(ct => ct.Resolve <WebHostResolver>().GetLoggerFactory(ct.Resolve <WebHostSettings>())).As <ILoggerFactory>().ExternallyOwned();

            var applicationContainer = builder.Build();

            return(new AutofacServiceProvider(applicationContainer));
        }
Exemplo n.º 2
0
        public static void Register(HttpConfiguration config, ScriptSettingsManager settingsManager = null,
                                    WebHostSettings settings = null, Action <ContainerBuilder, WebHostSettings> dependencyCallback = null)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            settingsManager = settingsManager ?? ScriptSettingsManager.Instance;
            settings        = settings ?? WebHostSettings.CreateDefault(settingsManager);

            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(typeof(FunctionsController).Assembly);
            AutofacBootstrap.Initialize(settingsManager, builder, settings);

            // Invoke registration callback
            dependencyCallback?.Invoke(builder, settings);

            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            config.Formatters.Add(new PlaintextMediaTypeFormatter());
            config.Services.Replace(typeof(IExceptionHandler), new ExceptionProcessingHandler(config));
            AddMessageHandlers(config);

            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "Home",
                routeTemplate: string.Empty,
                defaults: new { controller = "Home" });

            config.Routes.MapHttpRoute(
                name: "Functions",
                routeTemplate: "{*uri}",
                defaults: new { controller = "Functions" });

            // Initialize WebHook Receivers
            config.InitializeReceiveGenericJsonWebHooks();
            config.InitializeReceiveAzureAlertWebHooks();
            config.InitializeReceiveKuduWebHooks();
            config.InitializeReceivePusherWebHooks();
            config.InitializeReceiveStripeWebHooks();
            config.InitializeReceiveTrelloWebHooks();
            config.InitializeReceiveDynamicsCrmWebHooks();
            config.InitializeReceiveMailChimpWebHooks();
            config.InitializeReceiveSlackWebHooks();
            config.InitializeReceiveBitbucketWebHooks();
            config.InitializeReceiveDropboxWebHooks();
            config.InitializeReceiveWordPressWebHooks();
            config.InitializeReceiveGitHubWebHooks();
            config.InitializeReceiveSalesforceWebHooks();
        }
Exemplo n.º 3
0
        protected void Application_Start()
        {
            var settingsManager = ScriptSettingsManager.Instance;
            var webHostSettings = WebHostSettings.CreateDefault(settingsManager);

            VerifyAndEnableShadowCopy(webHostSettings);

            using (var metricsLogger = new WebHostMetricsLogger())
                using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
                {
                    GlobalConfiguration.Configure(c => WebApiConfig.Initialize(c, settingsManager, webHostSettings));
                }
        }
        protected void Application_Start()
        {
            var settingsManager = ScriptSettingsManager.Instance;
            var webHostSettings = WebHostSettings.CreateDefault(settingsManager);

            if (settingsManager.IsDynamicSku)
            {
                ServicePointManager.DefaultConnectionLimit = ScriptConstants.DynamicSkuConnectionLimit;
            }

            ConfigureMinimumThreads(settingsManager.IsDynamicSku);
            VerifyAndEnableShadowCopy(webHostSettings);

            using (var metricsLogger = new WebHostMetricsLogger())
                using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
                {
                    GlobalConfiguration.Configure(c => WebApiConfig.Initialize(c, settingsManager, webHostSettings));
                }
        }
Exemplo n.º 5
0
        public static IServiceProvider AddWebJobsScriptHost(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddWebJobsScriptHostRouting();
            services.AddMvc()
            .AddXmlDataContractSerializerFormatters();

            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, WebJobsScriptHostService>());

            // TODO: This is a direct port from the current model.
            // Some of those services (or the way we register them) may need to change
            var builder = new ContainerBuilder();

            // ScriptSettingsManager should be replaced. We're setting this here as a temporary step until
            // broader configuaration changes are made:
            ScriptSettingsManager.Instance.SetConfigurationFactory(() => configuration);
            builder.RegisterInstance(ScriptSettingsManager.Instance);

            builder.RegisterType <DefaultSecretManagerFactory>().As <ISecretManagerFactory>().SingleInstance();
            builder.RegisterType <ScriptEventManager>().As <IScriptEventManager>().SingleInstance();
            builder.RegisterType <DefaultLoggerFactoryBuilder>().As <ILoggerFactoryBuilder>().SingleInstance();
            builder.Register(c => WebHostSettings.CreateDefault(c.Resolve <ScriptSettingsManager>()));
            builder.RegisterType <WebHostResolver>().SingleInstance();

            // Temporary - This should be replaced with a simple type registration.
            builder.Register <IExtensionsManager>(c =>
            {
                var hostInstance = c.Resolve <WebScriptHostManager>().Instance;
                return(new ExtensionsManager(hostInstance.ScriptConfig.RootScriptPath, hostInstance.TraceWriter, hostInstance.Logger));
            });

            // The services below need to be scoped to a pseudo-tenant (warm/specialized environment)
            builder.Register <WebScriptHostManager>(c => c.Resolve <WebHostResolver>().GetWebScriptHostManager()).ExternallyOwned();
            builder.Register <ISecretManager>(c => c.Resolve <WebHostResolver>().GetSecretManager()).ExternallyOwned();

            // Populate the container builder with registered services.
            // Doing this here will cause any services registered in the service collection to
            // override the registrations above
            builder.Populate(services);

            var applicationContainer = builder.Build();

            return(new AutofacServiceProvider(applicationContainer));
        }