Welcome to this Learn MVC 6 training or MVC 1.0 Core i.e. a new name given to MVC 6 by Microsoft In this 2 hours of training we will try to understand what is new in MVC 1.0 Core or MVC 6 and what is a road map of Microsoft ahead Before we start the training let us clarify how the whole versioning system is working at this moment In the market lot of people are saying NET 1.0 Core then .NET 5.0 and somebody says NET on LINUX and somebody says MVC 6, MVC Core, ASP.NET Core, ASP VNEXT etc Till now we have our normal .NET framework i.e. the framework which started from 1.0, 1.1, 2.0 etc it came till 3.0, 4.5, 4.6 On the top of it side by side ASP.NET frameworks were released We have MVC 2, MVC 3, MVC 4 and MVC 5 Microsoft thought about going through a major shift into .NET framework The .NET framework went through a major change They name this new framework as .NET 5.0 On the top of it ASP.NET 5.0 was developed On the top of 5.0 we had MVC 6 That was the intermediate thing which happened some months or year back The 5.0 framework was so different they have to name the framework or version the framework as NET 1.0 Core on the top of it ASP.NET 1.0 Core is built then MVC 1.0 Core MVC is an architecture, the framework is ASP.NET We have Visual Studio 2015 Nowhere they are saying like MVC 6 or something We don’t see any web form If we are doing ASP.NET that means MVC is a architecture which is for ASP.NET Here they are not saying MVC, they are saying Web API, and Web Application The complete framework is now renamed to 1.0 Core The ASP.NET now becomes ASP.NET 1.0 Core and MVC is no more like MVC 6 it is MVC Core Renaming of the versions send out lot of messages from Microsoft to us When Microsoft migrated from 2.0 to 3.0 to 3.5 Whenever there is major version change like change from 2 to 3, 3 to 4 that means some big things have introduced, there are API changes When we have minor changes like from 4.0 to 4.5 Here we have a situation where they are saying we are starting from 1.0 Core

that means lot of things have changed This whole changes happening from past one and a half years 2 years Do not use for serious development projects We cannot compare the new 1.0 framework with a 10-12 years of framework what we have previously Whatever we are going to discuss in this video is only for training purpose Till then we will do MVC5, MVC2, AngularJS, Entity Framework the old one, AngularJS 1.X, Entity Framework6, SQL Server, old .NET This new framework is good to run on LINUX, UNIX For that we need give Microsoft 2 to 3 years opportunity to come out with a good framework If we doing any serious project stick to MVC5 If we click on this, this our old ASP.NET like MVC, Web API, Web forms, Code behind etc This both ones .NET Core and .NET frameworks are new ones If we using this that means we are using the new .NET Core using the new MVC Core, new ASP.NET Core To understand ASP.NET Core and MVC Core properly we need to first understand the .NET Core properly. We need to understand how .NET Core works internally what is changed This training is divided into two parts, the first one hour of the training we will talk about .NET Core, DNX, DNU, DNVM etc and the next part of the training we will talk about the MVC Core or the MVC6 We will first learn about .NET Core How it works, how it compiles, how the development environment is then we will go to the ASP.NET First with .NET Core and the next with MVC Core/MVC6 We have a new kind of framework and what is happening over there When we create any application in .NET it can run only on windows It can run on Window Server, window Xp, Windows 7 but at the end of the day it was only consigned to the windows There where some parallel open source framework like MONO which help to coat .NET Core into LINUX and other operating systems. By using the MONO framework we can run .NET code or other operating systems Because MONO was coming from the main Microsoft company developers were not really keen in using it or utilizing it

MONO is used heavily in XAMARIN This was never concerned because most of the business users and end users were using windows With the launch of mobile new operating systems like Android and IOS came into picture These OS were used heavily by business users and retail users We don’t want to loose business of their section we want the .NET Core to run on Android, IOS As a long term solution we want the .NET Core to run everywhere NET which is from past 15 years which has been running on windows, suddenly we him to run on all hardwares and on all operating system NET Core says I will take old .NET Framework and make this run on LINUX, UNIX etc To achieve this dream of running on all platform we have to rework on 15 years old framework because this 15 years old framework was never thought to run on UNIX and LINUX or any other platform It only thought to run on Windows Because of that we have lot of dependency of this framework only on Windows This .NET framework if they can take the Core part of the .NET framework Core means There are two things in the Core one is CLR, CGS, Code Access Security Garbage collector, JIT They have to first take the Core CLR and compile it for UNIX, Windows, LINUX etc They took this .NET framework and extracted the Core Code of this One of the code which is related to Garbage Collector, CLR, CGS, Code access security On github they created a repository called as a Core CLR This Core CLR has the garbage collector, JIT and data types etc For every platform they created different different bits We have CentOS, Debian, Read Hat, OS X, Windows etc They compiled as per the OS different set ups for each one of them That is the first step We cannot start from every thing we have to first start with the base In .NET Core there is a core thing and then there are core …..like System collection, system string, etc For that they created Corefx The foundation libraries term it as like file reading, console etc They putted in corefx In corefx there are different set ups created for all the OS The complete NET Core is now coated in such a way that we can take these bits and run on LINUX, UNIX and other operating system Next thing we need the power to develop on any platform Means one is we have received the Power to

run on any platform As a developer we also want to develop on any platform C# or .NET people can stick to windows they can install Visual Studio they will create the set up and put it in their operating system. Why do we need to develop on LINUX and other operating system Some operating systems like the Mac OS Legally we need to develop on their platform If we are creating any application for their platform like IOS then we need a Mac That means visual studio should also run on Mac The second step is also develop on any platform to run anywhere The most used development tool by the Microsoft is Visual Studio Visual Studio run only on Windows Visual Studio is out of question The second benefit of allowing people to develop on other platform that tomorrow if a JavaScript guy wants to use .NET Now we need to provide an infrastructure which can take this .NET framework and do the compiling part, referencing part etc How DNX, DNU and DNVM can help to do cross platform development We have the cross platform execution environment that means the cross platform framework of .NET we already have it Now we need the environment for cross platform development We need a manager which will tell we have these framework installed in computer The manager should also help to get the latest frameworks, upgrade the latest framework etc On this operating system if we want to do development there should be a way by where we can say show all .NET framework it will not show like this The manager should display We have Red Hat, Fedora, windows etc We need some kind of utility by which we can get the latest framework and by which we can upgrade that’s where we have the first person from those three things DNVM the .NET version manager To get DNVM go to the command line utility of the respective of operating system At this moment we are on Windows run this PowerShell command PowerShell is a Windows command line utility In the same way for LINUX and operating systems they have their own command line utility Over there we need to figure out command line utility but here in windows We are going to use PowerShell Fire the standard PowerShell command Please upgrade PowerShell to PowerShell 4.0 and above If we are using an old PowerShell then this demo will not work and second ensure we have an internet connection

and do not have any kind of proxy or antivirus. If we have an antivirus enabled then getting all these frameworks from github becomes difficult This command says go to github content and install DNVM It will download the PS1 file and run This is the first time we are doing in a computer DNVM goes online and it says we don’t have any run time installed Install the latest one It determines whatever is the latest .NET 1.0 Core and starts downloading it The .NET Core is never actually installed into computer, it is copied The old .NET framework lot of DLLs are installed into GAC This Global Assembly Cache is very much propriety to windows We don’t have any kind of GAC in UNIX or LINUX All the .NET 1.0 Core gets copied to a folder It has downloaded the latest version It installs into C Users login We are logged in by the name User There is a folder created called as dnx If we go into the folder in the run time he has installed the latest .NET 1.0.0 Core In a computer if we want to query what are the versions installed, will just say DNVM list We just have only one framework There are couple of other commands If we run DNVM we will get the list of commands There is a install command DNVM install latest It will try to install the latest version it will say we already have the latest version We are saying DNVM upgrade – u We have got a error here

It is because of Antivirus Disable antivirus for now Once this gets installed, again a folder will be created If do a query saying DNVM list we should see the pc has two versions It says now, your computer has two .NET Core version. One is the 1.0.0-rc2 which is unstable and the other one is the 1.0.0-rc1 which is stable The active version is 1.0.0-rc2 To make the stable version default there is a command saying DNVM use The second thing is we need to have a .NET Core which we can compile Open notepad Will start writing some code and see how the compilation process and the execution process takes place The demo which we are seeing here is without visual studio We’ll assume that we are on UNIX, LINUX, Mac and we are suppose to use this .NET Core, how we go about it This is our favorite Hello World visual studio in a notepad and create a folder This is Program.cs The next step is to compile this project To compile the project we need to first define the references Is it going to use rc1 or rc2 We used to provide these references they are added here These references gets stored into the csproj file The project file which is a complicated XML file

it is compiled by using msbuild It has the references, whatever we add references to the visual studio project get registered into the XML In the new environment if we use this format it would be very difficult for other people to read this format. This format is so complicated This format understood only by Visual Studio and by msbuild For cross platform development then we need to keep the format very simple In the new system of .NET Core they said whatever references we want to define for code define in a file called as Project.json This is the most simplest project.json file we can ever write Console application will use the 4.5 framework means the full fledged old .NET desktop framework, we are not talking about Core At this moment we have just included one framework i.e. the 4.5 1 We have the source code file here Program.cs and all the references are in project.json We are referring to the old .NET framework If we see the new .NET framework which we have downloaded they are with the version 1.0 In the folder we do not see any run time which is related to NET 4.5 because the .NET 4.5 is installed into GAC DNVM system, DNU system, DNX system does not install the old .NET framework To download the old .NET framework we need to go the old way Download the set up and install the .NET framework and it will get installed into the GAC If we compile this program it would take the DLL from the GAC We are not referencing NET Core in the compilation We need to get the necessary files needed for the project For that use DNU i.e the .NET utilities Delete all of these and take the fresh

DLLs When we did a dnu restore we did not get anything from online Because he saw DNX 4.5.1 and says take all the DLLs from the GAC We don’t have to take from online This thing is only applicable when we have Core and also there is a project.lock If we do a DNU build it builds a bin directly All these compilation is happening without Visual Studio With DNVM we are managing the .NET versions With DNU we can get the necessary packages we can compile With DNX we can run Once we say DNX run, the program will start running In this program we have not utilized the .NET Core. We have utilized the old .NET, .NET DNX, .NET 4.5.1 Use dnxcore as well as use the old .NET framework When we hit compile, it will compile using both the framework. There will be two different kind of set ups created Over here we have specified dependencies We have a console Use system.Console and use

4.0.0 Use Microsoft.Csharp For the Core we need to specify which namespace we will use for which version Why didn’t we do it for 4.5 because in the new Core when they took this old set up and when they broke down the core into more small small pieces Let us say we have Microsoft.Configuration to get JSON, XML everything we will say Microsoft.Configuration To just get JSON then say Microsoft.Configuration.json We need to specify dependencies this way dnu restore says whatever are the dependencies he tries to get them from online For 4.5.1 he will not Do a dnu build In the build he did build dnu restore he will get the necessary packages as specified in the project.json At the back end he is getting lot of packages which is related to the system All of these packages he has putted in the DNX folder in the packages While in run times we have frameworks Both of them are different These packages will be used by all the applications which are running Every project what is created, they don’t need all the packages Every project will have their own references They created a project.lock.json file This file says He is referencing Linq.Expressions, objctModel System.IO This project.lock tells more in depth which packages he is referring Every project will have their own separate lock file When we did the build he has created two set ups One is for .NET Core for the old .NET and other one is for DNX Core We did not create exe

He is creating a DLL Even for the old .NET not creating exe Whenever we want to run it use the DNX command This dnx picks up the library, the compile file and runs the code DNX is a run time environment It is a .NET execution environment DNVM the manager to manage the frameworks which are there on system DNU to get the DLLs, to get the references DNX to run We have DNX, DNU and DNVM which will help to compile code, to get the new packages without using visual studio Any serious development we cannot do just using DNU, DNVM etc we need an IDE In this tutorial we will understand how internally NET Core works and what is the whole goal of Microsoft to create .NET Core and why they have created these DDDs For ASP.NET MVC application where we have 100s of pages, we cannot do by command line If we do a development in windows go with the old visual studio Install visual studio 2015 Other operating systems like Mac linux then go with Visual Studio Code Visual Studio Code is an editor Whatever demo we have seen by using the command line utility will see how it looks when we see from Visual Studio Open visual studio 2015 Community edition Click on new project Whatever we create using 4.5 or 4.x version, right from 2.0 to 4.x is only for windows Click on .NET Core Click on Console Application using .NET Core -> Ok We do not have a csproj file. all the configuration of a project is stored into project.json We have the program.cs, project, the project.lock Whatever we created

those already here The project.json has projectlock.json which tells this project uses which packages To reference something here, the frameworks is referencing dnxcore When we do a save automatically he is doing a DNU restore and referencing the .NET host If we do a delete and save it is restoring This command is internally doing a DNU restore In this video we were trying to understand what is the concept of NET Core 1.0 What is DNVM, DNU and DNX The official name is .NET 1.0 Core MVC 1.0 Core ASP.NET 1.0 Core Previously they named it as .NET 5.0 they have again named it as 1.0 because it is not the extension of 4.5 In this case we are starting from the Core framework We are not building on top of 4.5 We took 4.5 we have downsized it and started from Garbage Collector etc We have understood the fundamentals of .NET Core. We have understood DNU,DNX and DNVM Will Start with ASP.NET Core training what are the new features in ASP.NET Core To do ASP.NET Core or the new MVC 6

we need to have the visual studio 2015 Without Visual Studio 2015 it is difficult to do anyone of these Click on New project -> Go to the web The time we go to the web there are three templates which are shown before us The first template will help to do the windows development i.e. normal .NET ASP.NET web application .NET framework is the MVC 5, ASP.NET on old .NET framework i.e. 4.5 To learn this them follow all the video series of MVC 5 where we have covered MVC 5 with entity framework with AngularJS, with SQL Server as a back end JQuery and JSON etc The above ASP.NET Core uses the pure .NET Core internally and below ASP.NET Core uses the .NET framework of windows as well We will create projects by using both of them Will name this as ASPDotnetCore Select the ASP.NET Core templates We did not find the word MVC and when we selected this neither the word MVC is here If we create an ASP.NET application using the using the Microsoft stack At the right hand side we can see the application with example of MVC views The template itself does not say MVC It is implied internally MVC will be used We are creating the project from scratch will start with Empty If we start from Empty then we can understand things If we start from Web API then lot of things will be readymade The project has been created i.e. the solution explorer Add one more project Add the project with the .NET framework. ASP.NET Core and .NET Framework We can do the side by side comparison of both of the templates

There is Project.Readme.html Delete this There is a project.json file. This file has all the references of the project We talked about the importance of project.json All the references of the project which we were doing using the add reference here Henceforth has to be added via project.json file To add let us say Microsoft.ASP.NET Mvc : “1.0.0-rc2-final” In the previous training we were doing by using the command prompt Here we don’t need to do DNU, DNX and DNVM The time do save at the right hand side it is restoring package This restoring package is like doing a DNU restore It will take the package from the feed and try to apply it over here It is taking lot of time. Go to the output it is trying to get something from online This is AspNetCore not AspNet.Mvc Whenever we change the project.json file Visual Studio automatically does a DNU restore To add the reference we need to update the Project.json file The Add reference does not work for NET Core or ASP.NET Core because the add reference uses GAC At this moment it is not compatible for the Core The below is .NET framework i.e. 4.5

and at the top we have AspDotnetCore In both the places we have ASP.NET Core but the .NET frameworks are different in both templates All the DLLs/packages are new For AspDotnetWithNormal There are somethings which are coming from Global Assembly Cache While for AspDotnerCore it is pure .NET Core We will remove the AspDotnetWithNormalDotnetFramework because to do AspDotnetWithNormalDotnetFramework then it is like doing half half Half in .NET Core and half in .NET framework Remove this and will concentrate only on the pure ASP.NET Core and .NET Core ProjectLock.json file we have talked about in the previous part of the video There is no global.asax file The old global.asax file which was there right form the classic ASP gone out from here and we have something called as Startup.cs file In Startup.cs file they have two methods at this moment We have two methods at this moment, we have configured services and configure In configure there is some code which says Response.WriteAsync(“Hello World”) There is app.run and it is taking the context object and doing a response.Write If we run this application as it is, will see a Hello World The configure method configures the request object Whole ASP.NET is about taking a request from the browser or from a client and sending a response In Configure we can catch the response Do a Control+F5 we should just see a Hello World This code overhere if we replace this code It was getting hold of the context object and from the context object it was getting the response and writing asynchronously on it If we do a .(dot) here The response in MVC 6 or MVC Core is written asynchronously The code was a task which was sent out The task was writing to the response asynchronously and the response then run by the app

Response in web application is not like Hello World, it will be HTML, Controller output etc Create a simple HTML page Static contents like HTML, Jquery, CSS go into wwwRoot folder Add a HTML file here Click on New Item -> Client side Do a Control+F5 to see the output We have not added any controller, we have not added any Model any view When we talk about MVC, it has to first hit the controller In MVC 6 ore MVC Core we can use MVC or avoid MVC completely The second thing which is important to understand about MVC 6 or MVC Core is Do to something we have to use it, add reference of it To reduce the memory footprint, reduce the size of the project To do HTML refer the HTML components To do MVC refer the MVC Component, to do entity framework refer the EF component. Without the component nothing will work Display static component Go to the Project.json file Click on view -> Solution explorer In the MVC Core or the ASP.NET Core we have to specify what we want it doesn’t work app UseStaticFiles To use the MVC add a reference to MVC app.UseMVC To refer entity framework add entity framework app.UseEntityFramework We are coding from scratch At this moment we are doing everything from scratch

so we need to add it If we use those templates then all things are there When we go for live projects, will not use this template the Core 1 We will use the Web API or the MVC 1 Without refereing things will not work In the old ASP.NET i.e. MVC 5, when we do a new project everything will be loaded at the start We can pick the necessary things rather than picking up the whole thing Let us create controllers, some views, models etc Again the concept wil not change we need those three. Add a new folder Controllers Add a view folder First add a controller Add -> New Item Add ASP.NET MVC Controller It not AactionResult it is IActionResult We need to add a view from scratch To add view for a Home then add it to the Home folder The ActionResult i.e. the Index is same as the View name, no need to say Return View Index We have to add the reference of MVC and use that MVC in Startup.cs In the project.json we have already added MVC We have referred ASP.NET Core MVC Here we need to specify a default route otherwise this code will work In the services say services

AddMVC If we hit Home/index we should get the output To run through the controller we can go through the controller To run straight forward a HTML file, run the HTML file In MVC 5 we always need to go via the controller and it was difficult to load the HTML file separately We should be able to see Microsoft Views MVC view is running via the controller but the simple HTML is running separately There are two important concepts to understand When it comes to MVC 6 or ASP.NET Core one is services and one is middle ware These two are bit of a new concept Services are classes or objects which are injected in controller This Home controller needs a logger service, error handling mechanism There can be lot of services and classes which we would use in the controller This services will be injected rather than creating an object Watch the design pattern section where we have explained what is the importance of Inversion of Control and Dependency Injection Because we have selected ASP.NET Core we cannot add class libraries using class library created in using 4.5 EventExecptionHandler or we can have FileExceptionHandler We have different ways of handling exception. Once the exception happens there are various ways of doing it We can use anyone of these in MVC To encapsulate and abstract things create a interface as IException Both of these classes will use the IException return

“Event view” return File One handles exception using the Event Viewer and the other handles exception using the file To refer the exception handling into the ASP.NET Core add the things into Project.json file The ExceptionHandling is using 1.5.0-rc2-24027 We are in 1.0 Will try to put rc2-final here The ExceptionHandling class is in a higher framework and the ASP.NET Core is in a lower framework It is trying to restore the packages but some warnings are there This exception handling was greater than rc2-Final In this ASP.NET Core we have multiple frameworks, we have frameworks which are using 1.0-rc2 Core The application can have multiple .NET Framework If we add a new exception handler then it will not work we need to change overhere We will refer in the Home controller IExceptionHandler In the home controller we will not refer everything, we will just refer to IException In IException whatever comes we use Somebody should inject

the ExceptionHandler In the constructor we can give the opportunity from here inject IExceptioHandler This ExceptionHandling class we need to inject as a service They have given an in build dependecny injection and it is termed as a service In Startup.cs file we had a method called as ConfigureServices services (dot) AddSingleton means a global object In this IException inject FileExceptionHandler We have different ways of doing injection, we have Singleton, We are injecting a singleton object, a global object acrossthe MVC project using the services If we run this in a debug mode We have configured the services automatically will inject the file exception handler in the Home controller In the Startup.cs we configured inject FileExceptionHandler he has injected FIleExceptionHandler In the second part of the video we will talk about the different ways of injecting the services We have two methods in Startup.cs file, one is ConfigureCservices where we add a service and use that service in the controller AddMVC we added as a service And one is a middle ware Middle ware is it is series of logic which we want to run in the request pipe line We can compare the middle ware with the http handlers and http module HTTP handler and HTTP module is some kind of a pre-Processing logic which we want to run before executing things In middle ware we can have series of middle ware These Middle wares can have logic and run those middle wares one after another A Middle ware is a class Services are dependency injected where middle ware purpose is to run the logic as a Pre-Processing logic like a chain One is Authentication

and the other one is Authorization We will write to the context object Activate app.Run We are falling back to the old code and disabling the code of MVC and static file Whatever we want to run will write in Invoke To use both of these middle wares app use Authorization UseAuthentication Will run Authentication middle ware first and after that will run Authorization middle ware and run the response We have also run app.UseMVC, even MVC is a middle ware for ASP.NET Core Do a Control+F5 UseAuthentication methods have come automatically because these are extension methods If we do something like Authentication has failed do not run the next task and it will not run the next task Services are dependency injected Middles ware helps to run pre-processing logic

before sending the response In the request pipeline they helps to build a chain of pre-procesing logic Till now our favorite place to put configuration data was a Web.Config file Now we can put configuration wherever we want to put We can put configuration in XML file, JSON File, Environmental variables Add a new config.Json In Config.Json add a simple key called as “Key1” and it has “Value1” Read this configuration data in the project To read the configuration data use the ConfigurationBuilder We have ConfigurationBuilder which is in the Microsoft.Extension.Configuration To use the ConfigurationBuilder Go to the Project.json file and refer the configuration Use the DLL of Json In the previous ASP.NET we have to say System.Configuration, everything comes into that Even though if we not using text files to read configuration still it is there We can say .Json, Read from EnvironmentalVariables Read from Ini files, read from XML, read from CommandLine Will do a separate video on how to read the configuration Now will take the simplest one Json Whenever we add something new to Project.Json file it restores the package Go to Stratup.cs and create an object of configuration Builder Now will set the path of the Json We have got the Configure object will say Set base path to the current directory Then add the Json file When we build the configuration by adding the Json file If we are building from different sources we can say Configure.Add from environmental variable The AddJson file is taking data from the config.json Now we can read the Key1 value The configuration no more come form webConfig file

They have made it more configurable Put a debug point or display this str1 It has come into the configure The configuration data is red from the Config.Json file The old web.config file only IIS understood it Only IIS knew how to read the configuration Tomorrow if we host this on Apache web server or host on other place from the other hosting environment then it is difficult By decoupling Web.config file from ASP.NET framework is a good move Now we can have any kind of hoster One of the goal of ASP.NET Core was to run on any platform to develop on any platform and we can host on any platform To convince us they have created a nice Web Server called as Kestrel Kestrel is a light weight web server only for testing purpose We can host the application inside kestrel From the program.cs file it will run the kestrel web server and host the application The program,cs file will start The console application is the actual kestrel what is running UseKestrel, UseContentRoot useAuthorization, all these are middle ware We can comment this code We want to run anywhere use any platform to code and host inside any other platform Create one more part of this video In that will take small topics around ASP.NET core In the Services we added Singleton

other ways of adding services is add as Scoped also add as a Transient Will understand the difference between adding as transient injecting as transient, as Scope and singleton In the next video will talk about dependency injection using the services of ASP.NET Core