From NSwag To Built-In OpenAPI
With the .NET 9.0 release, and specifically ASP.NET Core 9.0, we got a built-in OpenAPI generator. No need to depend on Swashbuckle or NSwag anymore.
OpenAPI generation has been an issue for Ogma3 for quite some time now, and there was no silver bullet. Swashbuckle would have dodgy support for forms, NSwag would outright not support HEAD method, et cetera.
Thankfully, with the new, first-party support, all those issues should be a song of the past, leaving just one: migrating off NSwag. As it turns out, it was not that hard, and you can read the details below.
Read the full post Fluent Validator for File Size With Client-side Validation
Fluent Validation is a great package for handling, well, validation.
It ties in well with ASP.NET as well, providing client-side hits in the form of data-val attributes on your
form inputs that can be used by whatever means of client-side validation you use, the jQuery thingamajig by default.
There’s but one problem, one thing that good ol’ attribute-based validators have over this package: the ease of
creating custom client-side validators. Server-side? No issue at all, the docs guide you cleanly through the process.
Client-side? That’s where issues begin.
In this post, however, we will make a file size validator that also works client-side. So sit back and enjoy.
Read the full post Generic MediatR Handlers
Odd as it might be, I couldn’t find much information about it myself, so I thought
I’ll share my findings instead. Perhaps it’ll be of help to those seeking answers
in the future.
Creating a generic controller? Nothing could be easier, simply create a method
with a signature like
private async Task<ActionResult> BlockContent<T>(PostData data) where T : BaseModel, IBlockableContent
and use it like you would any other generic method:
[HttpPost("story")]
public async Task<ActionResult> BlockStory(PostData data) => await BlockContent<Story>(data);
[HttpPost("chapter")]
public async Task<ActionResult> BlockChapter(PostData data) => await BlockContent<Chapter>(data);
[HttpPost("blogpost")]
public async Task<ActionResult> BlockBlogpost(PostData data) => await BlockContent<Blogpost>(data);
But how about using it with MediatR and the CQRS pattern..?
Read the full post