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.NETCore 1.0 is not a continuation ofASP.NET, but a new framework that unitesASP.NETMVC andASP.NETWeb 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
ASP.NETCore architectural design has birthed a leaner and modular framework.ASP.NETCore does not support System.Web.dll but supports a collection of granular and well factored NuGet packages.- It allows application optimization by just including the needed NuGet package.
- Applications have tighter security, reduced servicing, decreased cost, and improved performance.
Implementations of ASP.NET Core
- In
ASP.NETCore, compilation happens continuously, such that a developer does not have to invoke the compilation command upon deployment. - In
ASP.NETCore, 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. ASP.NETCore provides optimized cloud-based applications.ASP.NETCore Host-agnostic via Open Web Interface for .NET (OWIN) and support runs in Internet Information Services (IIS).ASP.NETCore has a unified story for building web UI and web APIs.- It is also a cloud-ready environment-based configuration system.
- It is light-weight and has a modular HTTP request pipeline.
- It can build and runs its applications cross-platform, i.e., its application can run on Windows, Linux, and Mac.
- It is open-source and community-focused.
- Side-by-side app versioning when targeting .NET.
ASP.NETCore has in-built support for dependency injection.
Components of ASP.NET Core
Below are some of the components of ASP.NET Core:
- Entity Framework (EF) Core: It is a modernized way of database management that supports LINQ queries, tracks changes, and updates. It also supports schema
. It works with a number of databases such as Azure Cosmos Db, SQL Database, SQLite, MySQL, and PostgreSQL.migrations Migration 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. - 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.
- 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:
,Models It’s a representation of an application state and its business logic. , andViews It uses CSharp codes and HTML markup to present contents on the user interface. .Controllers It works with the model and selects a view to be rendered on the user interface. It is basically responsible for user interactions. - 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.
- 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.
- 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:
I have used some terms in expressing ASP.NET core idea and I will briefly explain them as I conclude:
- Cross-Platform: Cross-Platform defines software that can work across other Operation System(OS) environments. Application created using
ASP.NETCore has this feature based on the framework in which it was created. - 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.
- Increased performance: In developing an application, performance is key.
ASP.NETCore has a lot of feature and implementations (reference can be made to the Implementations ofASP.NETCore session)that enhances the performance of an application. - Improved testability and readability: The architectural structure of
ASP.NETCore has made testing quite easy. AlthoughASP.NETCore supports automated integration and functional testing, it is well structured such it supports Object-Oriented Programming SOLID principles which makes it readable and reusable. - Dependency Injection: In
ASP.NETCore, 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 aConfigureServicesmethod in the Startup class.
A very simple example is in the code snippet below.
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.