ASP.NET Core is not an upgraded version of ASP.NET. ASP.NET Core is completely rewriting that work with .net Core framework. It is much faster, configurable, modular, scalable, extensible and cross-platform support. It can work with both .NET Core and .net framework via the .NET standard framework. It is best suitable for developing cloud-based such as web application, mobile application, IoT application.
Following are the core features that are provided by the ASP.NET Core
· Built-in supports for Dependency Injection
· Built-in supports for the logging framework and it can be extensible
· Introduced new, fast and cross-platform web server — Kestrel. So, a web application can run without IIS, Apache, and Nginx.
· Multiple hosting ways are supported
· It supports modularity, so the developer needs to include the module required by the application. However, .NET Core framework is also providing the meta package that includes the libraries
· Command-line supports to create, build and run the application
· There is no web.config file. We can store the custom configuration into an appsettings.json file
· There is no Global.asax file. We can now register and use the services into startup class
· It has good support for asynchronous programming
· Support WebSocket and SignalR
· Provide protection against CSRF (Cross-Site Request Forgery)
There are following advantages of ASP.NET Core over ASP.NET :
· It is cross-platform, so it can be run on Windows, Linux, and Mac.
· There is no dependency on framework installation because all the required dependencies are ship with our application
· ASP.NET Core can handle more request than the ASP.NET
· Multiple deployment options available withASP.NET Core
The framework .NET Core 2.0 introduced Metapackage that includes all the supported package by ASP.NET code with their dependencies into one package. It helps us to do fast development as we don’t require to include the individual ASP.NET Core packages. The assembly Microsoft.AspNetCore.All is a meta package provide by ASP.NET core.
There are following JSON files in ASP.NET Core :
The Razor pages provide the option to bind property automatically when posted the data using BindProperty attribute. By default, it only binds the properties only with non-GET verbs. we need to set SupportsGet property to true to bind a property on getting request.
ASP.NET Core allows us to specify the lifetime for registered services. The service instance gets disposed of automatically based on a specified lifetime. So, we do not care about the cleaning these dependencies, it will take care by ASP.NET Core framework. There is three type of lifetimes.
ASP.NET Core will create and share a single instance of the service through the application life. The service can be added as a singleton using AddSingleton method of IServiceCollection. ASP.NET Core creates service instance at the time of registration and subsequence request use this service instance. Here, we do not require to implement Singleton design pattern and single instance maintained by the ASP.NET Core itself.
ASP.NET Core will create and share an instance of the service every time to the application when we ask for it. The service can be added as Transient using AddTransient method of IServiceCollection. This lifetime can be used in stateless service. It is a way to add lightweight service.
ASP.NET Core will create and share an instance of the service per request to the application. It means that a single instance of service available per request. It will create a new instance in the new request. The service can be added as scoped using an AddScoped method of IServiceCollection. We need to take care while, service registered via Scoped in middleware and inject the service in the Invoke or InvokeAsync methods. If we inject dependency via the constructor, it behaves like singleton object.