0% found this document useful (0 votes)
18 views

DOTNETCORE

Uploaded by

Mano Haran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

DOTNETCORE

Uploaded by

Mano Haran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

.

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.

wwwroot folder------->static files,CSS,HTML,JS


Controllers------>Handle the users request
Viewes------>presentation layer
Models-------->Data Exchange
startup.cs------>Add and use the service and then regisetered the middleware in the request
pipeline( important will see the below section)
program.cs---->Entry point of the application

Types of hosting model:


1.Out-of-process
2.In-process -------->Default Hosting

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

Client----->HTTP Resuest----->IIS Server( w3wp.exe-->Application)

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

It achieve three ways


1.Singleton-------->It is Default.Single instance will maintain throughout application
2.Transient---->Every time new instance created
3.Scope---->Create the instance once per request and will be shared in a single request

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

public Class Test


{
private ITest _obj=null;

Test( ITest test)


{
_obj=test;
}
now inside of class we can call the method like " _obj.SomeMethods"
}

Public interface ITest


{
Some method declaration.
}

Public class Tets1: ITest


{
Implement the method
}
Some of build in IOC Container like
Unity Application Code block->Provide by Microsoft
NInject
Castle windsor
Structure map
Autofac

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}");

});

1._Layout----->Acting like ASP.NET Master Page and @RenderBody(),@Rendersection()


2._viewstart------->we have to assign the value of Layout property
3._Viewimports----->We can write the direcives like namespace.So no need to write the
namespace in the all view pages I mean no need to use packages in all view page. Because It is
automatically working if we use the _Viewimport page in our application.

1.ViewData---->It is dynamic Property,dictionary Type,Keyvalue Pare,Runtime exceptoin, not


get intelligence support,Type cast is required like ViewData[“emp”] = objemployee
2.ViewBag--->Dynamic Property,Runtime exception, not get intelligence support,Type cast not
required like ViewBag.Employee = objemployee
3.Strongly Type-----Model Class like @model HRMSApplication.Models.Employee

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

You might also like