// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Extensions; using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Mvc.Localization.Internal { public static class MvcLocalizationServices { public static void AddLocalizationServices( IServiceCollection services, LanguageViewLocationExpanderFormat format) { services.Configure( options => { options.ViewLocationExpanders.Add(new LanguageViewLocationExpander(format)); }, DefaultOrder.DefaultFrameworkSortOrder); services.TryAdd(ServiceDescriptor.Singleton()); services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>))); services.TryAdd(ServiceDescriptor.Transient()); if (!services.Any(sd => sd.ServiceType == typeof(IHtmlEncoder))) { services.TryAdd(ServiceDescriptor.Instance(HtmlEncoder.Default)); } services.AddLocalization(); } } }