Exemplo n.º 1
0
        /// <summary>
        /// Adds all web based services required for Umbraco to run
        /// </summary>
        public static IUmbracoBuilder AddWebComponents(this IUmbracoBuilder builder)
        {
            // Add service session
            // This can be overwritten by the user by adding their own call to AddSession
            // since the last call of AddSession take precedence
            builder.Services.AddSession(options =>
            {
                options.Cookie.Name     = "UMB_SESSION";
                options.Cookie.HttpOnly = true;
            });

            builder.Services.ConfigureOptions <UmbracoMvcConfigureOptions>();
            builder.Services.ConfigureOptions <UmbracoRequestLocalizationOptions>();
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, UmbracoApiBehaviorApplicationModelProvider>());
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, BackOfficeApplicationModelProvider>());
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, VirtualPageApplicationModelProvider>());
            builder.AddUmbracoImageSharp();

            // AspNetCore specific services
            builder.Services.AddUnique <IRequestAccessor, AspNetCoreRequestAccessor>();
            builder.AddNotificationHandler <UmbracoRequestBeginNotification, AspNetCoreRequestAccessor>();

            // Password hasher
            builder.Services.AddUnique <IPasswordHasher, AspNetCorePasswordHasher>();

            builder.Services.AddUnique <Cms.Core.Web.ICookieManager, AspNetCoreCookieManager>();
            builder.Services.AddTransient <IIpResolver, AspNetCoreIpResolver>();
            builder.Services.AddUnique <IUserAgentProvider, AspNetCoreUserAgentProvider>();

            builder.Services.AddMultipleUnique <ISessionIdResolver, ISessionManager, AspNetCoreSessionManager>();

            builder.Services.AddUnique <IMarchal, AspNetCoreMarchal>();

            builder.Services.AddUnique <IProfilerHtml, WebProfilerHtml>();

            builder.Services.AddUnique <IMacroRenderer, MacroRenderer>();
            builder.Services.AddSingleton <PartialViewMacroEngine>();

            // register the umbraco context factory

            builder.Services.AddUnique <IUmbracoContextFactory, UmbracoContextFactory>();
            builder.Services.AddUnique <IBackOfficeSecurityAccessor, BackOfficeSecurityAccessor>();

            var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList();

            builder.WithCollectionBuilder <UmbracoApiControllerTypeCollectionBuilder>()?
            .Add(umbracoApiControllerTypes);

            builder.Services.AddSingleton <UmbracoRequestLoggingMiddleware>();
            builder.Services.AddSingleton <PreviewAuthenticationMiddleware>();
            builder.Services.AddSingleton <UmbracoRequestMiddleware>();
            builder.Services.AddSingleton <BootFailedMiddleware>();

            builder.Services.AddSingleton <UmbracoJsonModelBinder>();

            builder.Services.AddUnique <ITemplateRenderer, TemplateRenderer>();
            builder.Services.AddUnique <IPublicAccessChecker, PublicAccessChecker>();

            builder.Services.AddSingleton <ContentModelBinder>();

            builder.Services.AddSingleton <IUmbracoHelperAccessor, UmbracoHelperAccessor>();
            builder.Services.AddSingleton <IScopedServiceProvider, ScopedServiceProvider>();
            builder.Services.AddScoped <UmbracoHelper>();
            builder.Services.AddScoped <IBackOfficeSecurity, BackOfficeSecurity>();

            builder.AddHttpClients();

            return(builder);
        }