diff --git a/src/Nager.Country.Translation/CountryProviderExtension.cs b/src/Nager.Country.Translation/CountryProviderExtension.cs index 531f763..0db623a 100644 --- a/src/Nager.Country.Translation/CountryProviderExtension.cs +++ b/src/Nager.Country.Translation/CountryProviderExtension.cs @@ -5,6 +5,8 @@ namespace Nager.Country.Translation { public static class CountryProviderExtension { + private static ITranslationProvider _translationProviderSingleton; + /// public static ICountryInfo GetCountryByNameConsiderTranslation( this ICountryProvider countryProvider, @@ -24,9 +26,8 @@ public static ICountryInfo GetCountryByNameConsiderTranslation( return country; } - var translationProvider = new TranslationProvider(); - var countryTanslation = translationProvider.GetCountryTranslation(country.Alpha2Code); - if (countryTanslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase))) + var countryTranslation = GetTranslationProviderInstance().GetCountryTranslation(country.Alpha2Code); + if (countryTranslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase))) { return country; } @@ -34,5 +35,11 @@ public static ICountryInfo GetCountryByNameConsiderTranslation( return null; } + + private static ITranslationProvider GetTranslationProviderInstance() + { + return _translationProviderSingleton + ?? (_translationProviderSingleton = new TranslationProvider()); + } } -} +} \ No newline at end of file