From 4b348efa59bff76683804aa7399ed4ec52272557 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Wed, 24 Feb 2016 22:53:24 -0800 Subject: [PATCH] Make ServiceCollectionExtensions consistent --- ...LocalizationServiceCollectionExtensions.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.Extensions.Localization/LocalizationServiceCollectionExtensions.cs b/src/Microsoft.Extensions.Localization/LocalizationServiceCollectionExtensions.cs index eb37df32e9..05ee6e9f7e 100644 --- a/src/Microsoft.Extensions.Localization/LocalizationServiceCollectionExtensions.cs +++ b/src/Microsoft.Extensions.Localization/LocalizationServiceCollectionExtensions.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Localization; namespace Microsoft.Extensions.DependencyInjection { /// - /// Extension methods for adding localization servics to the DI container. + /// Extension methods for setting up localization services in an . /// public static class LocalizationServiceCollectionExtensions { @@ -16,24 +16,25 @@ namespace Microsoft.Extensions.DependencyInjection /// Adds services required for application localization. /// /// The to add the services to. - /// The . - public static IServiceCollection AddLocalization(this IServiceCollection services) + public static void AddLocalization(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } - return AddLocalization(services, setupAction: null); + services.AddOptions(); + + services.TryAddSingleton(); + services.TryAddTransient(typeof(IStringLocalizer<>), typeof(StringLocalizer<>)); } /// /// Adds services required for application localization. /// /// The to add the services to. - /// An action to configure the . - /// The . - public static IServiceCollection AddLocalization( + /// An to configure the . + public static void AddLocalization( this IServiceCollection services, Action setupAction) { @@ -41,21 +42,13 @@ namespace Microsoft.Extensions.DependencyInjection { throw new ArgumentNullException(nameof(services)); } - - services.TryAdd(new ServiceDescriptor( - typeof(IStringLocalizerFactory), - typeof(ResourceManagerStringLocalizerFactory), - ServiceLifetime.Singleton)); - services.TryAdd(new ServiceDescriptor( - typeof(IStringLocalizer<>), - typeof(StringLocalizer<>), - ServiceLifetime.Transient)); - - if (setupAction != null) + if (setupAction == null) { - services.Configure(setupAction); + throw new ArgumentNullException(nameof(setupAction)); } - return services; + + services.AddLocalization(); + services.Configure(setupAction); } } } \ No newline at end of file