I've got an ASP.NET Core application and I'd like to use different strategies based on the Route selected. As an example if someone navigates to /fr/Index I want to inject the French translation implementation into my Controller. Likewise when someone navigates to /de/Index I'd like the German translation injected.
This is to avoid having every single action on my Controller read the "language" parameter and pass it on.
From a higher level, I'd like to have something like that:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Stuff here
app.MapWhen(
context => context.Request.Query["language"] == "fr",
builder =>
{
builder.Register<ILanguage>(FrenchLanguageImplementation);
});
app.MapWhen(
context => context.Request.Query["language"] == "de",
builder =>
{
builder.Register<ILanguage>(GermanLanguageImplementation);
});
}
Unfortunately, it doesn't look like I get the IoC container resolving context at that level.
PS: I'm using Lamar as IoC.