17/08/2023
1. ASP. NET Core is an open-source and asp.net core training cross-platform that runs on Windows, Linux, and Mac to develop modern cloud-based applications including IoT apps, Web Apps, Mobile Backends, and more.
I. It is the fastest web development framework from NodeJS, Java Servlet, PHP in raw performance, and Ruby on Rails.
II. ASP.NET core is not an upgraded version of ASP.NET. ASP. NET Core is completely rewriting the work with the .NET framework.
III. It is a much faster, modular, configurable, scalable, cross-platform, and extensible to support of .NET world for which organizations from different parts of the world are grabbing this technology in faster growth.
IV. Even it can work with both .NET Core and .NET frameworks via the .NET standard framework.
V. The ASP.NET Core framework is a completely open-sourced framework. Apart from the other parts of the framework of the .NET framework libraries, the ASP.NET Core is primarily designed from scratch to be the platform-agnostic that performs seamlessly.
VI. It will allow the ASP.NET Core apps to be deployed on the various platforms or the o/s such as the macOS or Linux-based servers or certain devices.
2. Features provided by ASP.NET Core:-
a. Built-in supports for Dependency Injection
b. Built-in supports for the logging framework and it can be extensible
c. Introduced a new, fast and cross-platform web server - Kestrel. So, a web application can run without IIS, Apache, and Nginx
Multiple hosting ways are supported
d. It supports modularity, so the developer needs to include the module required by the application. However, the .NET Core framework is also providing the meta package that includes the libraries
e. Command-line supports to creating, building, and running of the application
f. There is no web.config file. We can store the custom configuration into an appsettings.json file
g. There is no Global.asax file. We can now register and use the services in the startup class
h. It has good support for asynchronous programming
Support WebSocket and SignalR
i. Provide protection against CSRF (Cross-Site Request Forgery)
3. advantages of ASP.NET Core over ASP.NET:-
a. It is cross-platform, so it can be run on Windows, Linux, and Mac.
b.There is no dependency on framework installation because all the required dependencies are shipped with our application
c. ASP.NET Core can handle more requests than the ASP.NET
Multiple deployment options available with ASP.NET Core
4. Metapackages:-
The framework .NET Core 2.0 introduced Metapackage which includes all the supported packages 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 provided by ASP.NET core.
Metapackages of .NET Core describes the set of packages that are used together and acts as a parent of the child grouping structure. The Metapackages are referenced just like any other NuGet package naming convention such as "NETStandard.Library". An by referencing the meta-package, you have, then all its child packages will be having the reference of its dependent packages accordingly.
6. Startup class in ASP.NET core:-
The startup class is the entry point of the ASP.NET Core application. Every .NET Core application must have this class. This class contains the application configuration related items. It is not necessary that the class name must be "Startup", it can be anything, we can configure the startup class in the Program class.
7. Use of the ConfigureServices method of the startup class:-
This is an optional method of startup class. It can be used to configure the services that are used by the application. This method calls first when the application is requested for the first time. Using this method, we can add the services to the DI container, so services are available as a dependency in the controller constructor.
8. use of the Configure method of the startup class:-
It defines how the application will respond to each HTTP request. We can configure the request pipeline by configuring the middleware. It accepts IApplicationBuilder as a parameter and also it has two optional parameters: IHostingEnvironment and ILoggerFactory. Using this method, we can configure built-in middleware such as routing, authentication, session, etc. as well as third-party middleware.
9. middleware:-
It is software that is injected into the application pipeline to handle requests and responses. They are just like chained to each other and form as a pipeline. The incoming requests are passed through this pipeline where all middleware is configured, and middleware can perform some action on the request before passing it to the next middleware. Same as for the responses, they are also passing through the middleware but in reverse order.
While working with the ASP.NET Core framework, there are tons of built-in Middleware components available that are already made available that we can use directly that act as a plug and play components. If we don't want to use any of the in-built middleware, then we can also create our own Middleware components in asp.net core applications whenever we want. The most important point that you need to keep in mind is, that in ASP.NET Core a given Middleware component should only have a specific purpose which means it should be used for a single responsibility.
10. difference between IApplicationBuilder.Use() and IApplicationBuilder.Run():-
We can use both the methods in Configure methods of the startup class. Both are used to add middleware delegates to the application request pipeline. The middleware adds using IApplicationBuilder.Use may call the next middleware in the pipeline whereas the middleware adds using IApplicationBuilder.The run method never calls the subsequent middleware. After IApplicationBuilder.Run method, system stop adding middleware in the request pipeline.
11. use of the "Map" extension while adding middleware to the ASP.NET Core pipeline:-
It is used for branching the pipeline. It branches the ASP.NET Core pipeline based on request path matching. If the request path starts with the given path, middleware on to that branch will execute.e.g:-
public void Configure(IApplicationBuilder app)
{
app.Map("/path1", Middleware1);
app.Map("/path2", Middleware2);
}
12. routing in ASP.NET Core:-
Routing is functionality that map incoming request to the route handler. The route can have values (extract them from the URL) that are used to process the request. Using the route, routing can find a route handler based on the URL. All the routes are registered when the application is started. There are two types of routing supported by ASP.NET Core
1. The conventional routing
2. Attribute routing
The Routing uses routes to map incoming requests with the route handler and Generates URL that is used in response. Mostly, the application has a single collection of routes and this collection is used for the process of the request. The RouteAsync method is used to map incoming requests (that match the URL) with available in route collection.
13. Enable Session in ASP.NET Core:-
The middleware for the session is provided by the package Microsoft.AspNetCore.Session. To use the session in the ASP.NET Core application, we need to add this package to the csproj file and add the Session middleware to the ASP.NET Core request pipeline.AddSession();.UseSession();
14. The various JSON files available in ASP.NET Core:-
There are the following JSON files in ASP.NET Core :
1. global.json
2. launchsettings.json
3. appsettings.json
4. bundleconfig.json
5. bower.json
6. package.json
15. Tag helper in ASP.NET Core:-
It is a feature provided by the Razor view engine that enables us to write server-side code to create and render the HTML element in view (Razor). The tag-helper is a C # class that is used to generate the view by adding the HTML element. The functionality of the tag helper is very similar to the HTML helper of ASP.NET MVC.
Example:
//HTML Helper
.TextBoxFor(model => model.FirstName, new { = "form-control", placeholder = "Enter Your First Name" })
//content with tag helper
//Equivalent HTML
16. How to disable Tag Helper at the element level:-
We can disable Tag Helper at the element level using the opt-out character ("!"). This character must apply to open and close the Html tag.
17. How to specify the service life for a registered service that is added as a dependency:-
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 of the ASP.NET Core framework. There are three types of lifetimes.
18. Singleton: 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 the AddSingleton method of IServiceCollection. ASP.NET Core creates a service instance at the time of registration and subsequence requests use this service instance. Here, we do not require to implement the Singleton design pattern and single instance maintained by the ASP.NET Core itself.
e.g :- services.AddSingleton();
19. Transient:- 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 the AddTransient method of IServiceCollection. This lifetime can be used in stateless service. It is a way to add lightweight service.
e.g:- services.AddTransient();
20. Scoped :-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 is 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 the 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 a singleton object.
e.g:-services.AddScoped();