This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = WebApplication.CreateBuilder(); | |
builder.Services.AddFastEndpoints(); | |
var app = builder.Build(); | |
app.UseRouting(); //should be before auth/cors/fastendpoints middlewares. | |
app.UseAuthorization(); | |
app.UseFastEndpoints(); | |
app.UseEndpoints(_ => { }); //should be right after UseFastEndpoints(). this is the terminating middleware for endpoint routes. | |
if (app.Environment.IsDevelopment()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FastEndpoints; | |
using FastEndpoints.Swagger; | |
var bld = WebApplication.CreateBuilder(args); | |
bld.Services.AddFastEndpoints(); | |
bld.Services.AddRazorPages(); | |
bld.Services.AddServerSideBlazor(); | |
bld.Services.SwaggerDocument(); | |
var app = bld.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddSingleton(typeof(IRequestBinder<>), typeof(CustomBinder<>)) | |
.AddFastEndpoints() | |
.SwaggerDocument(); | |
var app = bld.Build(); | |
app.UseAuthorization() | |
.UseFastEndpoints() | |
.UseSwaggerGen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Ardalis.Result; | |
using FastEndpoints; | |
using FastEndpoints.Swagger; | |
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddFastEndpoints() | |
.SwaggerDocument(); | |
var app = bld.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FastEndpoints; | |
using FastEndpoints.Swagger; | |
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddFastEndpoints() | |
.SwaggerDocument(); | |
var app = bld.Build(); | |
app.UseFastEndpoints() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Endpoint : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("/protected"); | |
Claims("userId"); | |
Roles("Some_Role_Name"); | |
Permissions("Some_Permission"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class OperationCancelledFilter : IEndpointFilter | |
{ | |
private readonly ILogger<OperationCancelledFilter> logger; | |
public OperationCancelledFilter(ILogger<OperationCancelledFilter> logger) | |
{ | |
this.logger = logger; | |
} | |
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Asp.Versioning; | |
using Asp.Versioning.Conventions; | |
using FastEndpoints; | |
using FastEndpoints.AspVersioning; | |
using FastEndpoints.Swagger; | |
VersionSets.CreateApi(">>Orders<<", v => v | |
.HasApiVersion(1.0) | |
.HasApiVersion(2.0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class ApikeyAuth(IOptionsMonitor<AuthenticationSchemeOptions> options, | |
ILoggerFactory logger, | |
UrlEncoder encoder, | |
IConfiguration config) | |
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder) | |
{ | |
internal const string SchemeName = "ApiKey"; | |
internal const string HeaderName = "x-api-key"; | |
readonly string _apiKey = config["Auth:ApiKey"] ?? throw new InvalidOperationException("Api key not set in appsettings.json"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FastEndpoints; | |
using FastEndpoints.Swagger; | |
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddAuthorization() | |
.AddFastEndpoints() | |
.SwaggerDocument(o => o.AutoTagPathSegmentIndex = 0); | |
var app = bld.Build(); |