Skip to content

Instantly share code, notes, and snippets.

@trnktms

trnktms/Startup.cs

Last active Jun 3, 2021
Embed
What would you like to do?
public class Startup
{
private static readonly string _defaultLanguage = "en";
private static readonly List<CultureInfo> _supportedCultures = new List<CultureInfo> { new CultureInfo(_defaultLanguage) };
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers();
// Dictionary registrations
services.Configure<SitecoreLocalizerOptions>(options => options.Cultures = _supportedCultures);
services.AddHttpClient<ISitecoreLocalizer, SitecoreLocalizer>("sitecoreLocalizer", client =>
{
client.BaseAddress = Configuration.DictionaryServiceUri;
});
services.AddTransient<ISitecoreLocalizer, SitecoreLocalizer>();
services.AddTransient<IStringLocalizer, SitecoreLocalizer>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
...
// Open the endpoint to Sitecore CM publishing web hook
endpoints.MapControllerRoute(
"localization",
"api/localization/reload",
new { controller = "Localization", action = "Reload" }
);
...
});
// Initialize the dictionary cache
Task.Run(async () => await app.ApplicationServices.GetRequiredService<ISitecoreLocalizer>().Reload()).Wait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment