[Suggestion] Make DefaultLinkGenerator public and non sealed
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
Hi everyone,
I'd like to localize URLs of my application and, in order to do that, my solution is to translate route values for `action` and `controller` before they're actually processed by the `DefaultLinkGenerator`. This is what I'd like to do:
```csharp
public class MyLinkGenerator : DefaultLinkGenerator
{
public override string GetPathByAddress(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, PathString? pathBase = null, FragmentString fragment = default, LinkOptions options = null)
{
//Fiddle with the RouteValueDictionary here
//Then invoke the base method
return base.GetPathByAddress(httpContext, address, values, ambientValues, pathBase, fragment, options);
}
//...
}
```
Since I don't want to change the default url generation logic, I thought this was a simple and effective solution.
It's not viable though, since the `DefaultLinkGenerator` is a `private sealed` class.
Is there a particular reason why it cannot be a normal, overridable public class?
The fact it's a `private sealed` class did not stop me from achieving this solution, in fact I just had to wrap the `DefaultLinkGenerator` with my own implementation. It works but it's way uglier.
In Startup.ConfigureServices:
```
var serviceProvider = services.BuildServiceProvider();
var defaultLinkGenerator = serviceProvider.GetService();
var myLinkGenerator = new LocalizedLinkGenerator(defaultLinkGenerator);
services.AddSingleton(myLinkGenerator);
```
Would you please consider to make the `DefaultLinkGenerator` public and non-sealed?
Thanks.
P.S. Overall, I've found maaaany obstacles when trying to localize URLs. Another is in [issue #16965](https://github.com/dotnet/aspnetcore/issues/16965). It's almost like you didn't even consider people might want to do it.
Contributor guide
Assessment
This issue has not been assessed yet.