DOTNETCORE
DOTNETCORE
NET CORE
Definition:
1.Multiple Plaform support
2.Whenever we create an ASP.NET Core application, by default it contains an internal web
server provided by a .NET Core that is called Kestrel
3.Kestrel is a cross-platform web server for ASP.NET Core
4.Opensource
5.we can develope the more application like web,Mobile,IOT,Games,Machine
Learning,Microscrvices
6.Lightweight (important how to say it is lightweight)
We have to make sure the version of the core like right click the project and check the version
and hosing model like"targetframework" tag and also if we add any library file through Nuget
package that information also available in the rpoject files(.csproj).
Basics Structure:
Important Config file:
1.Appsetting.json-------->configuration as keyvalue type like connection string,some secret key
and acting like asp.net --->web.config
2.Launchsetting.json------->Application properties like hosting property like environent variable,
profile setting like iis or kestral server and url.
3.
4.
Where to check:
Oneway:
R.Click the project and select the properties then see the left tab select the Debug the
corresponding wildow will be open and then see the below "Hosing model Dropdown"
Second way:
Already i mentiond in the top of the document like definition of the .net core section.please
check it.
1.Inprocess
1.Default Hosting
2.This application run under the IIS worker process i mean w3wp.exe for IIS and iisexpress.exe
for IISExpress
3.Only one web server used like IIS,Nginx,Apache
2.OutofProcess
1.This hosting model used for two web server i mean kestral and main server like
IIS,Nginx,Apache
2..This application run under the Kestrel server like your project name like "HRMSProject"
Oneway:
Run under the application name and we suggestd Only for Development mode not
production
Client----->HTTP Resuest----->Kestrel-->Application)
Second Way:
host the another way application called Reverse Proxy server
Client----->HTTP Resuest----->IIS Server( w3wp.exe)------->HTTP request from IIS--
>Kestrel-->Application)
program.cs
1.This is the entry point of the application through "Main" method.------>we must "Main"
casesensitive
2.This method will creating the webhost.
so noramlly we can write a code like
3. call createwebhostbuilder--->Any name we can write like method name not-casesensitive
4.And passing the command line argument from main method like "args"
5.And use the extensition method like "usestartup()" and configure the startup.cs class like
"UseStartup<startup.cs>()"
6.The build the host and then run our application in the host
startup.cs
This class having two methods.
1.Configure---------->This is must
2.Configureservices------->This is optional
ConfigureService:
It is used for registered the Application service DI/IOC (DI--->Dependency Injection)(IOC--
>Inversion Of Control) and then use the Framework services. Application services I mean those
classes are used in some where in the applicaion.
like
service.AddMVC()--------->Better we can use this service. Because all Features like
Pages,CORS,Antiforgerytoken,Taghelper,caching
service.AddControllersWithViews()
service.AddRAZORPage()
Configure:
This method is used for Registered the middlewear in the request pipeline. some of the
middlewears are given below
useAuthentication();
useAutherozation();
use.StaticFiles();
use.DefaultFiles();---------->define the default file like html then we need to create the instance
of DefaultFilesOptions class.(Will explain below section)
userouting();
MapDefaultControllerRoute()
useDeveloperExceptionpage()------->This method only used for Dev environment. Because It
shows the exact exception in the browser.
Middleware:
It is a S/W component.And its inject in HTTP request pipeline which is used to our customised
own component like handle the incoming http request.
Those meddilewares are used and ordered in the Configure method. The order of the middleware
Execution is very important.
The middleware can be call two ways from IApplicationBuilder extension method like
1.Use-->used two parameter next meddleware runs i mean If you want to send the request from
one middleware to the next middleware then you need to call the next method
2.Run----->used only one parameter terminate the request of next middleware like terminate the
request i mean next middleware not executed
Note:
We can understand when I explain the coding part.
DI/IOC:
They are two services like
1.Framework service---->Build In IOC like
Iserviceprovider,IApplicationbuilder,IHostingEnvironment,ILoggerFactory
2.Application service--->Developer we can custom class
Next we have to registered the services in the Configureservice method in the startup.cs class
Code like
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<InterfaceName, ClassName>();
}
And then three ways we can Implement (Learn DI is one fo the SOLD Concept )
1.Constructor
2.Method
3.Property
I am using Constructor level see the below code
Note: Very Important (Become an Architech) we should learn SOLD Principle concept Then
only we can understand the DI.
We can achieve two ways to create the Web application in .net core.
1.PageModel---> ASP.Net Web Form
2.MVC
PageModel:
1.It just acting ASP.Net Webform.
2.We should inherit the pagemodel as a base calss in our razorpagemodel.
3 And we should use @page in the view page.
4.All views are under the Pages folder
MVC:
Routing:
1.It a machanism of MVC application.
2.It will Map the URL structure like inspect the incoming request
3.The routing middleware using the application pipeline like userouting();
app.UseMvc(routes =>
{
routes.MapRoute(
name:"default",
template: "{controller}/{action}/{id:int?}",
defaults: "new {controller=Home,action=index}");
});
Views:
1.We can use RAZOR page
2.Tag Helpers
Form Tag Helper
Input Tag Helper
Label Tag Helper
Textarea Tag Helper
Radio Button Tag Helper
Select Tag Helper
CRUD Operation:
But normally we can use HTML with any froent like Angular,React,VueJs.
1.Annotation
2.CustomFilters
3.Custom Exception Filter
4.How to handle the error with using Filters
5.Logs the error
6.CRUD operation
And so many concept will explain coding level because theoretically I means verbal
communication not possible I think so.
I have prepared this docuemnt Whatever i know and I have missed some concepts such as
DI/IOC Coding,Middleware Implementation coding,How to register the middleware in the
Pipeline,Tag Helper controls and How does an Application Hosting in IIS.
Because these concepts are explained by coding level i mean each and every line will show the
demo.
Let me know if you want coding level of above mentioned like missed concept and CRUD
Operation.
Note:
If you learn some additional information concept apart from this, Please share your
knowledge it's very use full to me.
I hope this document is use full to you. I think so. please reach me If any clarification.
DO WELL
ALL THE BEST