Posts

Showing posts with the label asp.net core

Web API Without Controller

If the mantra of "thin controllers, fat models" is followed to the extreme, it would result in very short controller methods, sometimes even only a couple of lines long. Today I am experimenting with doing away with controllers entirely, and just mapping routes directly to methods that execute the business logic. The code in this post can be found in: https://github.com/ojraqueno/web-api-without-controller Setting Up the New Project First, I created the web API project template using dotnet new : dotnet new webapi -n ControllerLessWebAPI That will create a new API project for me inside the ControllerLessWebAPI folder. I can run that project by going into the directory and running dotnet run : dotnet run It will start the website, which in my case is located in localhost port 5001. If I go to https://localhost:5001/weatherforecast , I can see some random JSON data being returned. Removing the Controller The starter template contains a WeatherControlle...

ASP.NET MVC vs ASP.NET Core: Practical Differences

Image
ASP.NET Core has been around for a while, but not everyone is using the new framework yet. If you're someone who's migrating from ASP.NET MVC to ASP.NET Core, you might be wondering what the differences between the two frameworks are. In this post, I will share the main differences between the two, from the point of view of a developer who has worked with both. Here is an overview: Dependency injection is built-in. Controllers are unified. Client-side assets are centralized. And more - read below! Dependency injection is built-in Dependency injection is a popular pattern in object-oriented languages that helps make code maintainable. With ASP.NET MVC, developers had to make use of 3rd-party NuGet packages to enable dependency injection in their projects. In ASP.NET Core, dependency injection is baked into the framework. There is no need to use any NuGet package, although using 3rd party DI packages is still supported. Dependency injection is supported n...

Configuration in ASP.NET Core

Image
Lots have changed in the new ASP.NET Core world. From the project structure to the hosting model to the improved Razor engine, the Microsoft team introduced a slew of changes that is more apt for modern web development geared toward the cloud. One of the big changes is the configuration model. In a non-core ASP.NET project, we store configuration settings in the appsettings section of web.config . This is no longer the case in ASP.NET core projects. In this post we will take a detailed look at the new configuration model.