-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Allow external libraries to extend Results #35508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @khellang had similar questions about this. |
We talked about this when we introduced the |
Another alternative is to use |
Yeah having to accept |
Background and MotivationWe would like for library authors to provide custom IResult instances and for a single place to register these extensions for easier discoverability. Proposed APInamespace Microsoft.AspNetCore.Http.Results
{
+ // Marker interface for extensibility
+ public interface IResultExtensions
+ {
+ }
public static class Results
{
+ public static IResultExtensions Extensions { get; }
}
} Usage Examples// Library code
public static class LiquidResultExtensions
{
public static IResult LiquidView(this IResultExtensions resultExtensions, string name)
{
return new LiquidView(name);
}
}
// App code
MapGet("/view", () => Results.Extensions.LiquidView("cool-view")); Alternative DesignsUsers can discover result types from libraries through documentation RisksN/A |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
1 similar comment
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API ReviewWe considered a few options
This felt iffy since it's only usable within C# that has global static usings. At this point, we feel there is a need for an API for the community to rally around, so even if it does get deprecated by a newer language feature, we think it's worthwhile. Naming:
Since the type name has There was some concern about using |
When using minimal APIs, external libraries could want to expose custom results, like views. There is no way to add custom extension methods to the
Results
class. However a solution could be to expose a public property e.g.Results.Custom
that could be used to expose other types of results.Today the only solution is for each library to create their own factory class, or return an
IResult
instance directly which doesn't help for discoverability, and consistency.Example:
(https://github.com/sebastienros/fluid/pull/292/files#diff-b2a1bda3022b9e2130cc1ececbfc576ec1f91dca2c65baef80c1604c8c36821eR11-R14)
Which could instead become:
The text was updated successfully, but these errors were encountered: