Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Last active September 3, 2023 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj-nitehawk/171a4228be267ca9312e1ae882ee6d5b to your computer and use it in GitHub Desktop.
Save dj-nitehawk/171a4228be267ca9312e1ae882ee6d5b to your computer and use it in GitHub Desktop.
Middleware order for Blazor Serverside
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();
app.UseStaticFiles();
app.UseAuthorization();
app.UseFastEndpoints();
app.UseSwaggerGen();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
@erdikalleci
Copy link

I set up the project this way but I still keep getting errors.

Excepted Unhandled:
throw new InvalidOperationException("Endpoints are not initialized! This usually happens when 'app.UseFastEndpoints()' is placed after 'app.MapControllers()'. Try changing the middleware order.");

@dj-nitehawk
Copy link
Author

sorry! the snippet hadn't been updated for the latest FE.
pls try the above now and report back.
here's the sample project i tried it on: Sample.zip (right click > save as > rename to .zip > extract)

@erdikalleci
Copy link

Yes, it worked. I tried version 5.16 yesterday, it didn't work. Trying with 5.17 is positive. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment