How to use ASP.NET Core

Background

The .NET platform is made up of several developer tools, programming languages, and libraries that can be utilized for building different types of applications like web, mobile, desktop, games, and IoT. Primarily, .NET Apps are written in the following languages:

  • C#
  • F#
  • Visual Basic

Aside from the fact that the languages listed above run on the .NET platform, they are great for building type-safe and object-oriented applications. In recent times, ASP.NET has been used to develop web applications, but due to a steady evolutionary change, a new development was launched. It is the ASP.NET Core version 1.0.

Note: ASP.NET Core 1.0 is not a continuation of ASP.NET, but a new framework that unites ASP.NET MVC and ASP.NET Web API into a single programming model.

ASP.Net Core is the latest web-development framework developed by Microsoft, and it is engineered to be fast, easy, and work across different platforms. It is used for building web apps on the .NET platform. It is a free and open-source web framework and a successor of the .NET framework that can run on macOS, Linux, and Windows.

Advantages of ASP.NET Core

  1. ASP.NET Core architectural design has birthed a leaner and modular framework.
  2. ASP.NET Core does not support System.Web.dll but supports a collection of granular and well factored NuGet packages.
  3. It allows application optimization by just including the needed NuGet package.
  4. Applications have tighter security, reduced servicing, decreased cost, and improved performance.

Implementations of ASP.NET Core

  1. In ASP.NET Core, compilation happens continuously, such that a developer does not have to invoke the compilation command upon deployment.
  2. In ASP.NET Core, the Modular framework is now being distributed as NuGet packages. So, instead of installing a whole framework that may not be needed for that project. A NuGet package with the needed feature can be installed.
  3. ASP.NET Core provides optimized cloud-based applications.
  4. ASP.NET Core Host-agnostic via Open Web Interface for .NET (OWIN) and support runs in Internet Information Services (IIS).
  5. ASP.NET Core has a unified story for building web UI and web APIs.
  6. It is also a cloud-ready environment-based configuration system.
  7. It is light-weight and has a modular HTTP request pipeline.
  8. It can build and runs its applications cross-platform, i.e., its application can run on Windows, Linux, and Mac.
  9. It is open-source and community-focused.
  10. Side-by-side app versioning when targeting .NET.
  11. ASP.NET Core has in-built support for dependency injection.

Components of ASP.NET Core

Below are some of the components of ASP.NET Core:

  1. Entity Framework (EF) Core: It is a modernized way of database management that supports LINQ queries, tracks changes, and updates. It also supports schema migrationsMigration is a way to update our database and keep it in sync with our application’s model and ensure the data in the database is preserved.. It works with a number of databases such as Azure Cosmos Db, SQL Database, SQLite, MySQL, and PostgreSQL.
  2. Identity Core: It is an API that manages a User Interface login functionality. It managed profile data, roles, passwords, and a lot more about login functionality. It also supports the usage of external login providers like Google, Facebook, Microsoft, etc.
  3. Model-View-Controller (MVC) Core: This is a framework for developing web applications and APIs using a pattern that separates the application into three (3) main groups of components, which are: ModelsIt’s a representation of an application state and its business logic., ViewsIt uses CSharp codes and HTML markup to present contents on the user interface., and ControllersIt works with the model and selects a view to be rendered on the user interface. It is basically responsible for user interactions..
  4. Razor Pages: It is a server-side page-focused framework that is lightweight and flexible. It is good for a data-driven and dynamic web application with a neat separation of concerns.
  5. SignalR: It is an open-source library that permits the server-side to post contents to the client at an instance. It is helpful where an application requires features like notification, chats, etc.
  6. Blazor: Uses C#, HTML, and CSS instead of JavaScript to make our web applications’ user interface (UI) interactive.

Developing a simple App with ASP.NET Core

ASP.NET Core is largely supported by visual studio for application development.

Below are simple three steps to create an App using ASP.NET:

The first step is to open Visual Studio
The first step is to open Visual Studio
Click on create a new project.
Click on create a new project.
Select your project type
Select your project type

I have used some terms in expressing ASP.NET core idea and I will briefly explain them as I conclude:

  1. Cross-Platform: Cross-Platform defines software that can work across other Operation System(OS) environments. Application created using ASP.NET Core has this feature based on the framework in which it was created.
  2. Razor: Razor is a mark-up syntax that allows us to implement server-based codes (i.e. C# and Visual Basic) on a web page.
  3. Increased performance: In developing an application, performance is key. ASP.NET Core has a lot of feature and implementations (reference can be made to the Implementations of ASP.NET Core session)that enhances the performance of an application.
  4. Improved testability and readability: The architectural structure of ASP.NET Core has made testing quite easy. Although ASP.NET Core supports automated integration and functional testing, it is well structured such it supports Object-Oriented Programming SOLID principles which makes it readable and reusable.
  5. Dependency Injection: In ASP.NET Core, Inversion of control between classes and their dependencies by using dependency injection. In the business logic, classes are created with interfaces and these interfaces and their implementation are injected using a ConfigureServices method in the Startup class.

A very simple example is in the code snippet below.

main.cs
StartUp
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IMyDependency, MyDependency>();
}

In conclusion, ASP.NET Core is a composition of both front-end, business logic/back-end, and Database.

Free Resources