Skip to content

Allow external libraries to extend Results #35508

Closed
@sebastienros

Description

@sebastienros

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:

app.MapGet("/", () =>
{
    return LiquidResults.View("index", new Todo(1, "Go back to work!", false));
});

(https://github.com/sebastienros/fluid/pull/292/files#diff-b2a1bda3022b9e2130cc1ececbfc576ec1f91dca2c65baef80c1604c8c36821eR11-R14)

Which could instead become:

app.MapGet("/", () =>
{
    return Results.Custom.LiquidView("index", new Todo(1, "Go back to work!", false));
});

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions