/// <summary> /// Registers <see cref="CookieTempDataProvider"/> as the default <see cref="ITempDataProvider"/> in the /// <see cref="IServiceCollection"/>. /// </summary> /// <param name="builder">The <see cref="IMvcBuilder"/>.</param> /// <returns>The <see cref="IMvcBuilder"/>.</returns> public static IMvcBuilder AddCookieTempDataProvider(this IMvcBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } // Ensure the TempData basics are registered. MvcViewFeaturesMvcCoreBuilderExtensions.AddViewServices(builder.Services); var descriptor = ServiceDescriptor.Singleton(typeof(ITempDataProvider), typeof(CookieTempDataProvider)); builder.Services.Replace(descriptor); return(builder); }
public void AddViewComponentsAsServices_ReplacesViewComponentActivator() { // Arrange var builder = CreateBuilder(); MvcViewFeaturesMvcCoreBuilderExtensions.AddViewServices(builder.Services); builder.ConfigureApplicationPartManager(manager => { manager.ApplicationParts.Add(new TestApplicationPart()); manager.FeatureProviders.Add(new ViewComponentFeatureProvider()); }); // Act builder.AddViewComponentsAsServices(); // Assert var descriptor = Assert.Single(builder.Services.ToList(), d => d.ServiceType == typeof(IViewComponentActivator)); Assert.Equal(typeof(ServiceBasedViewComponentActivator), descriptor.ImplementationType); }