This file contains hidden or 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(args); | |
bld.Services | |
.Configure<JwtSigningOptions>(s => s.SigningKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") //must register signing options | |
.Configure<JwtCreationOptions>(c => c.SigningKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") //optional | |
.SwaggerDocument() | |
.AddAuthenticationJwtBearer(s => { }) //no need to specify signing options here due to above | |
.AddAuthorization() | |
.AddFastEndpoints(); | |
var app = bld.Build(); |
This file contains hidden or 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 MyEvent : IEvent | |
{ | |
public string? Message { get; set; } | |
} | |
sealed class MyEventHandler : IEventHandler<MyEvent> | |
{ | |
public Task HandleAsync(MyEvent e, CancellationToken c) | |
=> Task.CompletedTask; | |
} |
This file contains hidden or 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(args); | |
bld.Services | |
.SwaggerDocument() | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints( | |
c => c.Endpoints.GlobalResponseModifier | |
= (ctx, content) => | |
{ |
This file contains hidden or 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(args); | |
bld.Services | |
.SwaggerDocument() | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints() | |
.UseSwaggerGen(); | |
app.Run(); |
This file contains hidden or 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.Swagger; | |
using Scalar.AspNetCore; //dotnet add package Scalar.AspNetCore | |
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.AddFastEndpoints() | |
.SwaggerDocument(); //define a swagger doc - v1 by default | |
var app = bld.Build(); | |
app.UseFastEndpoints(); |
This file contains hidden or 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
[HttpGet("publish"), AllowAnonymous] | |
sealed class MyEndpoint : EndpointWithoutRequest | |
{ | |
public override async Task HandleAsync(CancellationToken c) | |
{ | |
var evnt = new MyEvent { Message = "hello!" }; | |
await PublishAsync(evnt); | |
await SendAsync("all good!"); | |
} | |
} |
This file contains hidden or 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(args); | |
bld.Services | |
.SwaggerDocument() | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints( | |
c => | |
{ | |
c.Errors.UseProblemDetails(); |
This file contains hidden or 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 System.Text.Json.Serialization; | |
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.SwaggerDocument(o => o.UseOneOfForPolymorphism = true) //enable the setting | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints() | |
.UseSwaggerGen(); |
This file contains hidden or 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(args); | |
bld.Services | |
.AddAuthenticationJwtBearer( | |
s => s.SigningKey = "...", | |
o => | |
{ | |
o.Events = new() | |
{ | |
OnChallenge = | |
async ctx => |
This file contains hidden or 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 class MyDbContext(DbContextOptions<MyDbContext> opts) : IdentityDbContext<IdentityUser>(opts); |
NewerOlder