There are numerous things to love about the new .NET 6, but for me one key thing stands out - .NET now seems more approachable than ever!
Take a straight-forward example. A new .NET Web API project would look like this -
startup.csfile with generated code
Program.csfile with more lines of code
- A lot of other files
The two file dependencies induced that warm fuzzy feeling in ASP.NET developers for sometime now.
In addition, you have code that uses a wierd
using syntax everywhere with brackets. Sure, it creates better compartmentalized & namespaced code, but did not help calm my nerves when I was evaluating ten different back end technologies to make a quick start (a while ago).
C# 10 and the new ASP.NET 6 will do wonders in the “make code look deceptively simple” area.
There is no
Program.cs file now looks cool with the new features -
- top-level statements
- file scope namespace declarations (bear with me here)
A minimal API structure now looks like this (
Program.cs file) -
A full-blown MVC web API application from the new template in .NET 6 looks like this..
“Whoa..!” is right.
I am not proud of the fact that the additional statements & brackets were putting me off a long time. While I love C# for what it can do, I seldom choose C# for personal projects for all the silly reasons - I did not need the complexity, did not like to do lot of typing or “auto filling”, and did not have a lot of patience for code scrolling tens of pages.
I am a fan of the new ASP.NET structure - for probably all the wrong reasons for a “real” developer. I will probably delve more into how a further “simplified” folder structure can make the ASP.NET world more exciting to work on. The “traditional” structure has been full of folders and a lot of files. See the eShopOnWeb example on Github. The minimal API structure at a glance by Martin Fowler is a good start for a new approach to build Web APIs on .NET 6, but what is even more interesting to me is the module-based architecture outlined in this post by Tim Deschryver.
WebApplication │ appsettings.json │ Program.cs │ GlobalImports.cs │ WebApplication.csproj │ ├───Modules │ ├───Cart │ │ CartModule.cs │ └───Orders │ │ OrdersModule.cs │ ├───Endpoints │ │ GetOrders.cs │ │ PostOrder.cs │ ├───Core │ │ Order.cs │ │───Ports │ │ IOrdersRepository.cs │ │ IPaymentService.cs │ └───Adapters │ OrdersRepository.cs │ PaymentService.cs
Awesome time this.