public static IMvcBuilder AddPrecompiledRazorViews( [NotNull] this IMvcBuilder builder, [NotNull] params Assembly[] assemblies) { var razorFileInfos = RazorFileInfoCollections.GetFileInfoCollections(assemblies); builder.Services.TryAddEnumerable(ServiceDescriptor.Instance(razorFileInfos)); return(builder); }
public static IMvcBuilder AddWebApiConventions(this IMvcBuilder builder) { builder.Services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <MvcOptions>, WebApiCompatShimOptionsSetup>()); builder.Services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <WebApiCompatShimOptions>, WebApiCompatShimOptionsSetup>()); // The constructors on DefaultContentNegotiator aren't DI friendly, so just // new it up. builder.Services.TryAdd(ServiceDescriptor.Instance <IContentNegotiator>(new DefaultContentNegotiator())); return(builder); }
public static IServiceCollection AddWebApiConventions(this IServiceCollection services) { services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <MvcOptions>, WebApiCompatShimOptionsSetup>()); services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <WebApiCompatShimOptions>, WebApiCompatShimOptionsSetup>()); // The constructors on DefaultContentNegotiator aren't DI friendly, so just // new it up. services.TryAdd(ServiceDescriptor.Instance <IContentNegotiator>(new DefaultContentNegotiator())); return(services); }
/// <summary> /// Register the specified <paramref name="controllerTypes"/> as services and as a source for controller /// discovery. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/>.</param> /// <param name="controllerTypes">A sequence of controller <see cref="Type"/>s to register in the /// <paramref name="services"/> and used for controller discovery.</param> /// <returns>The <see cref="IServiceCollection"/>.</returns> public static IServiceCollection WithControllersAsServices( [NotNull] this IServiceCollection services, [NotNull] IEnumerable <Type> controllerTypes) { var controllerTypeProvider = new FixedSetControllerTypeProvider(); foreach (var type in controllerTypes) { services.TryAdd(ServiceDescriptor.Transient(type, type)); controllerTypeProvider.ControllerTypes.Add(type.GetTypeInfo()); } services.Replace(ServiceDescriptor.Transient <IControllerActivator, ServiceBasedControllerActivator>()); services.Replace(ServiceDescriptor.Instance <IControllerTypeProvider>(controllerTypeProvider)); return(services); }
/// <summary> /// Adds Mvc localization to the application. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/>.</param> /// <param name="option">The view format for localized views.</param> /// <returns>The <see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddMvcLocalization( [NotNull] this IServiceCollection services, LanguageViewLocationExpanderFormat format) { services.Configure <RazorViewEngineOptions>( options => { options.ViewLocationExpanders.Add(new LanguageViewLocationExpander(format)); }, DefaultOrder.DefaultFrameworkSortOrder); services.TryAdd(ServiceDescriptor.Singleton <IHtmlLocalizerFactory, HtmlLocalizerFactory>()); services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer <>), typeof(HtmlLocalizer <>))); services.TryAdd(ServiceDescriptor.Transient <IViewLocalizer, ViewLocalizer>()); if (!services.Any(sd => sd.ServiceType == typeof(IHtmlEncoder))) { services.TryAdd(ServiceDescriptor.Instance <IHtmlEncoder>(HtmlEncoder.Default)); } return(services.AddLocalization()); }