Saturday, March 16, 2019

Super DRY ASP.NET Core web API HTTP REST endpoints

Howdy guys and gals. I've created a tiny little thing (only some few hundreds of lines of code actually), which I believe is a very good starting point for learning some architectural best practices, focusing on OOP, SOLID Architecture, and specifically DRY ("Don't Repeat Yourself").

The aim of the project is to provide a "Starter Kit" for your next ASP.NET Core web API project(s), getting an "out of the box" strong architectural structure, allowing you to simply "fill in the gaps" related to your own domain problem, by following existing conventions. In such a way, it is not a library in fact, but rather a pre-fabricated class hierarchy and solution/project files structure, and a folder structure, allowing you to simply fill in the blanks, in whatever ways your own domain problem require.

https://github.com/polterguy/magic

(Watch the video for a demonstration)

By intelligently using generic classes and polymorphism, it is possible to (among other things) create and wrap your database tables without writing a single line of code, by simply inheriting from intelligently designed base classes, giving you all the common CRUD operations automagically (hence its name "Magic").

The project internally consumes Fluent nHibernate, and will even automatically create your database in Debug builds.

It should also provide you with some ideas in regards to how to architect your own intelligent class hierarchies, in addition to featuring many other nifty solutions, such as transparently supporting multiple different database providers, by simply changing an appsettings.config section, or dynamically load controllers from assemblies, etc, etc, etc. It also illustrates how to use Ninject in ASP.NET Core, and uses Swagger UI for documenting your web APIs.

Especially for a "noob", it in such a regard literally becomes a "free good architectural foundation" for an ASP.NET Core web API project.

Out of the box, it's a simple TODO CRUD HTTP REST endpoint, but the idea is to use this as an example to wrap your own database tables, providing CRUD controller endpoints, automagically mapping between your view model, through your database model, into your database, with extension points at every single layer in your pipeline. Basically, it creates your controller, domain to database mapping, service layer, service interfaces, etc, without you having to code a single line of code, by simply inheriting from the correct class ...

It uses some "intelligent" generics/polymorphism trickery, which probably should be of interest also to the seasoned software architect out there, effectively giving you a domain driven design experience, "for free", out of the box, without having to apply a single line of code, but simply declaring your classes, and inheriting them from the correct base classes ...

Let me know what you think about it.

Super DRY ASP.NET Core web API HTTP REST endpoints Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team