Build Your First ASP.NET Core Web Application Workshop, Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] good morning good afternoon good evening whatever time it might be where you are out there welcome back to the live stream my name is Jeff fritz and today today is April 3rd 2020 and we're gonna write a lot of code today meetings my excellent friend oh yeah we changed up the layout here a little bit this is this is the asp net core 3.1 workshop so i've updated the workshop that's out there that's that's available for us and let me get some music playing here in the background we're gonna I'm gonna rotate through a couple different songs as we cross a module I'll choose a different song to play as we're going through here of course I'm gonna play all day long music to code buy from our friend mr. Carl Franklin these are songs that are scientifically designed they're engineered to get you in the flow to get you in the groove so that whatever task it is you're working you can focus on and just get stuff done today's song that we're starting with this is called blue this is the first song that Carl row part of the music to code by package I encourage you to execute the music command in the chat room so you can get that link and get your copy of music to code by today yeah absolutely Carl Franklin jams all day long we're gonna have a great time writing some code together and I hope you have have fun you enjoy the music and and we learn a little bit together here and I'm noticing already that the follower list isn't updated with the latest followers and that's gonna annoy me if it doesn't update with the latest actions that's really going to annoy me did it just update nope nope it didn't I see a resub yeah those are older animated slinky with the resub okay got that one but uh evil evil Chile is from some time ago and we missed missed a couple new follows in there and refresh the cache of that there we go there we go so the rendell a meal in Umbra bar biz fava with the cheer thank you so much and all of our cheers all of our subs just a reminder we're donating to the World Health Organization I still need to find the exact fund to donate to but we want to help the folks that are on the front line fighting kovat 19 all of our cheers all of our subs and and like I said the alerts aren't gonna be on here but we'll see them up here up above I've very much appreciate the cheers and subs and we're gonna pay that forward you're gonna get some emotes that you can use here on the channel you're gonna turn off the ads and we're going to what will show your name up top there for your contribution and we're gonna make a donation to help the World Health Organization all right yep the first the the most recent one appears just a little bit larger and as it as other follows other Cheers happen it Scrolls up a little bit so and yep it does look like it's updated all right I think we're ready to get into this I think we I think we're ready to start the source code for this of course is at bitly slash fritz asp net core workshop and i did have that github open that'll get you there quickly of course if you know where my github is you can browse to it directly and it's right here pain des than number two repository and this is where we're going to be working all day today is with this project and going through and looking at the documentation here I'm going to be doing a bit of reading of what's inside the documentation and a bit of where how its leading us but I'm also going to pause back up and talk through and answer questions along the way and when folks do have questions of course it'll pop up I'll bring it up over here on the side using featured chat feature Tran is that feet is is that really cool overlay that our friend lucky number seven wrote that allows us to integrate with chat and pull out some questions highlight them and let them appear on our overlay over here you like my terminal background Cyril ash thank you appreciate that you throw in a quick PR to fix the build status image what build status image oh there's a build status image as part of this so it shows up what's the matter with it now look at that nice thank you yeah we'll merge that in real quick so you're welcome to download the source code to this you're welcome to use it however you'd like there we go this is available for anybody to download to use it it's free it is open source everything that we're doing here the license I believe yet it's an MIT license use this how you'd like give it to whoever you who you want if you're watching the video go ahead and share this video copy it reuse it I hope you're watching it on YouTube and and you're enjoying this give it a like and hit the subscribe button up at the top if you're on youtube if you're here on Twitch hit that follow button every time we cross a multiple of a hundred followers we do a sticker giveaway we did cross two hundred ten thousand two hundred followers on Twitch we'll do a sticker giveaway at the end of the first module right let's get into this let's talk about asp net core let's talk about asp net core 3.1 and and have some fun i think there's a lot that that we can get into works on a blog built on blazer cool so asp net core is built on dotnet quarter asp net is of course the dotnet web development framework it's not it's not a user interface framework it's a complete web development framework that you can use that supports all kinds of ways of hosting web applications building applications for the web hosting it on a server hosting it on static files if you want to run a a static web site you can do that and and serve some static files and put things like blazer components in there that will run on top of web assembly that all falls under the concept of a asp net core now I'm already looking and seeing that our application architecture diagram is a little out of out of date here but that's okay we're gonna keep moving through here Dukas off thank you for the sub and we're gonna make another donation to help the World Health Organization very much appreciate that dukkha so what we're going to do we're gonna set up we're gonna learn about this dotnet core asp net core is completely open source it's completely free it's completely developed in the open you will never be charged if you want to use asp net core you want to use dotnet core support is available paid support is available free support looking at source code talking to the community those things that the open source communities are famous for is always available to you paid support is available for the most recent we call it the current and LTS versions of asp net core the LTS version the long-term support version is available for support for three years plus one year of conversion one year into the next one okay for at least three years if there's a new LTS version that's released before those three years are you've got support for two of them so right now you can get asp net core 2.1 and 3.1 and have support for both of those for i believe two point one's gonna be available for like another year and a half from the time of this recording but asp net core 3.1 was released in December 2019 you're gonna have support for that available through 2023 at which point you're gonna be encouraged to move on to a different version so different things that you can do around support there's links available on the Microsoft website if you want to learn more about support for that it's real easy to get started with the dotnet with dotnet core you can either get it as part of Visual Studio or of course you can download the SDK now we say SDK but really this is the command-line interface and you're gonna have this whether you install Visual Studio Visual Studio for Mac Visual Studio code or you want to work with with a text editor maybe you like to use vim maybe you like to use Emacs maybe when you use peak Oh fantastic atom brackets that's okay take and run in write code where you're comfortable where you're gonna have fun this is set up so it runs on every command line Windows Mac and Linux and you can click through where is it or I want to show there's other versions available out here we're on the on a dotnet 5 preview track if you're watching the recording here the dotnet 5 preview is is on its way you may be watching this after dotnet 5 was released but we're working with dotnet 3.1 so there's installers available or you can just download the binary and put them wherever you'd like on disk but you can download installers for all the major operating systems and there's package manager instructions for all of your favorite Linux for all of your favorite Linux distributions will bunt to Santo s debian fedora open SUSE Red Hat um SLES not familiar with SLES that's a new one with me I'm not sure what SLE is hey Josh er have found that stickers they won't in their post fantastic glad to hear it so there's install instructions for all the major operating systems okay and of course if you're running on Linux and it's not on one of those package managers you're not using one of those download the binaries put them where you'd like there's pointers to the source code here as well if you want to go download the source code and compile yourself you can do that I would su say Linux thank you the code monk thank you so much for the feedback there appreciate the help and web face had it as well okay so I've already downloaded and installed and I have the command-line tools available for me not just because I click through here and if you've been watching the stream you've been watching the rest of the YouTube archive you know that we spent large a minimal march on the command line in linux with vim you can do that always welcome to to take your tools to wherever makes you happy but I already have this downloaded and installed so I can run the dotnet command line and it will tell me hey I've I've got some features here I can run dotnet version and it'll show me I'm actually on a 300 preview I didn't install that I don't know where that came from but okay suddenly I've got the 3-1 300 preview cool and there are all kinds of templates out here for you when you run net new it's gonna restore some packages here make sure it has the latest version of the templates and there's all kinds of project models for this dotnet isn't just web development dotnet is console applications and WPF that's windows presentation foundation applications very graphical applications for Windows Windows forms those traditional battleship gray applications you may have seen going back into the 90s right very but very full-featured and event-driven component focus application development you can build worker services test unit test projects and here's some of our web projects razor components those are components that you can put in and use inside of web projects razor pages for those folks who like to build a very page focused application MVC maybe like maybe you like Ruby on Rails and you like that model-view-controller architecture that's completely supported as a first-class user interface framework with web development that we have and blazer here that's our new component based user interface development framework and there's some very simple template add ones down here that are empty Model View controller a complete application and a web app that uses razor pages really really great stuff it looks like a lot of different choices but we've we've brought to you literally all the different things that you may want to build with done now and when we get to dotnet 5 you're gonna see mobile applications appear in this list so you can build and use dotnet on the command line to build mobile apps it's really great stuff that we're excited to to see develop and folks get encouraged to be able to use and empower folks to build with dotnet wherever you want to be unhip coder points out about WinForms applications let me tell you there it is battleship gray user interface it's all the rage everybody wants it no that's that's not a thing I am sorry so hey gnarly good to see you eternal Def coder asks a question here and before we decide to choose which type of framework our razor page is more encouraged than MVC I'm gonna say no because what what we like about the the two different ways approaches to building web applications there are folks who feel very web page focused I'm gonna build this is the web page that I'm going to present so I want everything to build that page all the logic for it in one file and you can do that that's what razor pages are really nice at building MVC is a very testable very unit testable framework that you can use because you want that separation of logic you want to be able to use different views around the same controller actions so that you can mix and match as need be and have your model completely separated from that so your data model is isolated you can put all your data concerns in one place isolated away from the rest of your web framework so it's really a question about providing choice for folks what makes you happy about the way you develop and you can build using that technique thank you for the question to eternal dev coder that's writes tells e the SDK reference is basically just a new get package whose props and targets files are imported yep excuse me so [Music] gnarlie asks and we can just go over these quickly can we go over what each one of these templates are briefly and talk about advantages and disadvantages I'll go over them quickly because there's so many of them a console application of course is a console application you can build and deploy and run it on Windows Mac or Linux console application class libraries and you see a number of these labeled as class libraries these are different ways that you can put business logic into into a dll and if you're a long time Windows user you or even a short time if you're just a Windows user let's start there you've seen dll's on disk that's what these things are they've put your business logic you've put some reusable things into a library that you can reference from other projects from those front-end or service back-end projects so you have that flexibility of where you consume those things thank you for the follow G Matta M appreciate that so WPF UC application class library custom control library those are things that help you build those windows presentation foundation projects runs only on Windows takes advantage of the of the graphical libraries and capabilities that are in your graphics card compared to Windows forms which don't take advantage of it are really lower end user interface interactions but WPF is built with zamel so you get that nice markup experience that folks enjoy about web where wind forms is is built with it's how do I explain how it's laid out there's a nice designer that helps you with the layout and it ends up writing locations on disk into files of where things should be placed but you have a tremendous designer experience with Windows forms there is a designer for WPF and zamel but it's not great it's not great that's right dll's our dynamic link libraries that's what dll stands for and yes this will be a violator you'll find it on the YouTube so scrolling down services are it's a service that will run in the background I'm not quite sure with the worker services I don't know if that's intended to be a web worker service but worker services are typically background tasks that you'll start and run and install on a on a server so they run on their own independent of human interaction the unit test projects here are different unit tests they're test frameworks that you can use so you can test your projects and make sure that your code works appropriately so you write a test point it to another piece of your application and say execute go through this and it just works oh that is the ASP networker service okay so that's intended to be a low ceremony very the worker template up here very low ceremony service that has all of the features of asp net can can act as a web endpoint and run as a background service so you have a couple different ways that you can use it's a couple different test frameworks here unit test project using the MS test framework and unit using an end unit framework how much a test project and you can create test items you have a test item template there and X unit which an X unit is kind of their preferred that the more popular of the three unit test libraries for dotnet core developers because the folks who built X unit were on the.net court team at the time dotnet course started so you'll see a lot of X unit tests for things that are built by the team um continuing to scroll down Razer components bucket that's that's a that's actually a component template and same thing with the razor page those are those are item templates not project templates one to build a component that's reusable inside of a web project a razor page is that page first design for a web application um a view imports view start those are item templates different pieces of the MVC application that control references and and a start page that kicks off how you integrate with MVC blazer server applications blazer web assembly application seizes the two types of blazer projects that we have available you can build with that component first architecture that's being rolled out as part of dotnet core three one we're not gonna be focused on blazer today but when we get into the seventh module later today will take us a little bit of a challenge to integrate a blazer component with our application but those component based applications you can build and run your components and have them render either server side or in the browser using web assembly this is an empty project that literally has no code for you lets you build how you want the beginning template for a Model View controller project a beginning template for a razor pages project and a beginning template if you want to use angular or react to interact react and redux a couple more these some of these are file templates in here as well a G RPC service will build a G RPC service in that seventh module as well as part of a little bit of a challenge to go to go off-script and show how you can integrate some of these other things a Web API project template if you're building just API endpoints those restful endpoints that folks want to connect in and request things from your web server interact with your web server and get that machine first interaction Web API and G RPC you're gonna see are very similar but get ignore file a global JSON file the global JSON file specifies the version of the SDK the command-line interface that we're using you can have many versions of the command-line interface installed on your on your machine on your developer workstation and use a global JSON file to specify which version to use new get config defined that's a file template that specifies what what new get resources where do I go to get my packages to build to build my dotnet project some enterprises some organizations have have a very tight control on how they reference and use packages so where everybody goes to NPM to get node packages in in some organizations they want to control the security of those things so in the dotnet world they'll have a new get server or even a new get file file folder sitting somewhere on their network and they'll override the new get config and say don't go out to new georg to get packages from the public repository instead come to our private repository that everybody can use tool manifest it allows you to define dotnet command-line tools specific to this project web config helps configure your I is your Windows web server solution file is how we group together a series of projects and a protocol buffer file is used for G RPC so you can specify how those remote procedure calls should be communicated in a cross-platform way that's supported by Java Python JavaScript PHP did I just say PHP Ruby Dart is it supported by tart I just threw dart out there because it's a very Google thing to say so hey Laila codes it is here hello Leila good to see you you like you like in unit as you like the attributes but X unit is is a little bit better maintained let me say hello to folks in the chatroom here their unit testing is available for razor pages um but it's it's a little bit it's a little bit trickier I don't feel like it's as pure as testing model-view-controller MVC applications yes the different unit test frameworks they're subtle difference but they do basically the same things yep the way X unit and in unit report when you run tests subtle differences X unit has a lot more ceremony to it we're in unit you can just console console.writeline and it will capture that and log those things but the end unit team has been around for a long time and they're not maintaining as quickly as the X unit folks the naked flame says making a new website with an with the asp net core 3-1 api and it's been awesome but that was after you tried making your website with dotnet core with the angular template you found that to be a nightmare so this is a very good point the folks that make the angular template up there are not the angular team it's the dotnet folks and they're coming in after the fact to light that up and they're not angular first folks so building an API and adding on layering into it your angular application or your view application or react is gonna find you much success and you're gonna see in our first module here we're gonna build an API write it in API endpoint that a web server will respond to and if you're one of those JavaScript framework developers and you prefer that it's gonna look and feel very familiar to be able to hook up to so thank you for the comment the naked flame really appreciate it code show asks eight hours eight hours I still have to try streaming for that long it's it's a marathon it's a marathon we have to take it one step at the time at a time we'll get through it we'll have a lot of fun and this isn't this is nothing this is nothing because in two weeks write it down friends in two weeks we're gonna do the 12-hour developer show Friday April 17 we're gonna go for 12 hours and we're gonna start a little bit earlier than normal and we're gonna go right into the evening and and we're gonna have Fritz family members helping out with lunch and dinner we're gonna have guests joining us it's going to be tremendous and there's there's a couple folks here in the chatroom that I want to ask join for part of that as well yes Leila that that's a very good point let me put that up on the on the chat here this is a lot of cool templates here but Leila makes a good point here you can't also make your own templates and deploy them with the CLI so just like I mentioned for nougat config there's folks who in various enterprises that say you must use our new versions of these new get packages that we've we've blessed we have we've approved some folks will say remove all of these templates and use our organization's standard template that has the way we do things to start a a web application and it has our formatting and it has the way we want to pull together angular and view or whatever it might be to build you have complete flexibility here there's great documentation on how you can build templates to go with this hey lucky number seven is here David must have heard that I was making some use of that tremendous check out featured on chat that's what you're seeing the the questions come up over there we bring that in so that we can highlight some of those questions so folks that are watching the recording you can see some of the questions that I'm answering and I'm you've seen me doing this on the YouTube the YouTube archive the the more in depth questions that that we bring up over there I highlight and I put a timestamp on in the description so make sure you click the description below the YouTube videos and you can click those if there's a particular question that you're interested in you can click that link and jump right to the question in the YouTube recording it's really great stuff let me take a look here the Simon points out the new angular 8 project templates in Visual Studio 2019 have some nice Microsoft build integration but you do have to know that both angular and Web API to get it up and running yeah you're using two different technologies you-you-you need to know a little bit of both in order to get these things up and running we're folks in the past when we had asp net web forms folks could kind of focus and know just web forms and they didn't have to know JavaScript or CSS or write they could focus on just c-sharp and that component framework and be productive because it would translate and build out the styles and the JavaScript interactions appropriately for you using whatever components made sense but when you do when you do start mixing and and you get into these hybrid types of applications that are a little bit of angular a little bit of web api you're going to see that you need to know a little bit more of both of them to be successful that vehicle idea to make stream markers when we click the questions that might be cool to do yes so we've seen right I did dotnet new and made it the I of these templates Estelle Z points out you can make tools that you can run at the dotnet command-line and we're gonna run some tools today that use entity framework and allow us to orchestrate and interact with entity framework that's our data modeling and object relationship manager framework that we're going to be using but you can make tools available that'll work on Windows and Linux and ship those tools via new get real easy stuff to do we're not going to get into command-line tools building command-line tools today maybe we can do that in another stream but very good point from stealthy thank you for sharing yep it's the SDK that gives you the good bits you don't need Visual Studio you don't need Visual Studio code in fact I was gonna say maybe we roll over and do a little on the Chromebook at some point today me maybe I can figure out a way to get code over there and we can pick up and do a little bit of work from our Chromebook today just so you can see that we're gonna work on the command line with Linux and I'm not hooked into Visual Studio now let's ignore Linux no oh you developed with IDI the text editor good luck to you all the best okay um so there's a little bit about all the different things that we have available to us as we build and work on dotnet at the command-line but not everybody wants to work at the command line right there are some folks that are very they're like the mechanics in our industry they'll they'll go out and they'll buy a car but they bought the card knowing I'm gonna as soon as I get home flip open the hood and I'm gonna rewire it I'm gonna soup up the engine I'm gonna put a I'm gonna update it and do this that and the other and change out the way that the oil filter is and all you can do that and you can do that at the command-line but there are a lot of folks that prefer to just use Visual Studio so they can be productive and not think about some of those other things that really intrigue and other folks are really interested in going after so let's um so let's create a folder here and I'm just gonna call this let's call this twitch workshop so I have some place that I'm gonna be working ok and I'll be working in this folder because the source code the complete source code for the application is out here I believe it's in source in save point source might not be completely updated we'll get that updated at some point later today but you can find safe points for each one of the modules in the save points folder as we go through the day so I talked a little bit now about getting dotnet and let's talk about the project here for a little bit so that was octo tree this is a plugin I have for for github that allow me to navigate my file structure here very easily what we're gonna build today this is in if you've seen one of my other asp net core workshops here on stream on the YouTube channel this is just an update of those with some new features that like I said we're gonna light up in Ain the seventh module so there are basically three projects that we're going to build we're going to build a back-end service that asp net core is for tastic add we're gonna set up a web server that has entity framework models of some models for interacting with our database and some api's those restful endpoints that you're gonna be able to connect into to query update add even delete data from in this back-end service we're gonna have a shared project called conference DTO that has data transfer objects so we're gonna make available to share between both our back-end service and our front-end that's gonna be that typical front-end web application you would use to interact with as as a browser right through your browser that's gonna be all of our front-end web e things right HTML Javascript all in that front-end project so our front-end project is going to make queries to our back-end almost like a micro service project over here and it's gonna have this common language of conference DT OS that it's gonna share between the two there is a final module at the end that I'm not going to cover you're welcome to check out that is a series of JavaScript services using a spa front-end write that single page application front-end for those folks that are interested in JavaScript and how it interacts all of that source code is available here in the github repository as well can we say it's JavaScript but use blazer says Diggs that's not a bad idea to to put a blazer version of the front end in here as well um you know what let me let me take that as a to-do item to come back and update this so that we have a blazer front end on this so all right yes do what you love it's not a prescription absolutely all right we have a very very simple database schema now Becca here it is so we're building a conference website okay and I'm actually not going to use the default data that was shipped with this I think will load up data for the live coders work live coders conference will load up some of that data so we can use it later but there is default data here if you want to use it we'll load up some of this data save it and make it available on the github repository so we have a series of conferences that we may be managing conferences of course have tracks tracks have sessions so we see these key to many indicators and if you're not if you're not familiar with relational database architecture you have a key in this case a conference ID that is referenced by another table right so here we have a conference ID references the conferences ID field so entries in this table reference this tracks have a conference ID so all of the tracks there's many of them the Infinity reference one conference ID the tracks have a series of sessions and the sessions you can see have a track ID so there are many sessions right the infinity of many sessions that reference one track in similarly and so forth through here we have speakers at a conference those speakers speak at a session now this is interesting we have this middle table here this many-to-many that says there are many session speakers for each speaker so a speaker may speak at multiple sessions so but multiple speakers may speak at in multiple sessions so how do we do that each speaker here's an ID has a mapping to a session that they are presenting so this might be Jeff Fritz is presenting asp net core intro jeff fritz presenting right so we'll have a pointer to jeff fritz and a pointer to intro to blazer is the session right so you have this way that you can link these two tables together if you're not familiar with relational database architecture sessions can be tagged in the same thing here many to many relationship many sessions can have many different tags and attendees can go to many different sessions so we have the same many to many relationship so that foreign key that's the that's the term for it yep these the right session ID this is a foreign key the actual instance of it is over here that we're referencing and over here you'll see many copies of that same session ID in this table thank you for the follow El Simmons appreciate you joining us thank you for tuning in been doing this for ten years and you always mess up crow's-feet notation in the Rd documents yeah yeah I know that feeling the key to infinity notation here nice graphical way to do it but what else Simmons is referring to is instead of having you can have this be an arrow in ERD entity relationship diagrams this will be an arrow and on the other side to show that it's that it's referencing many of these you'll see it looks like a it looks like a pitchfork right you have it look crow's feet it looks like an upside-down W there pointing into the session attendee so these are the various modules that we're gonna go through here today there are eight of them and we're gonna end after that seventh I believe and we're probably going to skip the sixth because I don't want to do deployment but that content is available for you the other reason I don't want to do but do deployment is because it's very easy for me to Docs myself and the I've I've had tremendous luck with working with Azure on stream right what can I tell you sixteen percent of the time it works every time I just get unlucky with how I deploy so am i planning on using ASP net identity for managing users yes yes we are didi Walsh is here good morning um thank you it's like not really an M but yeah it looks like it upside down yeah it's a pitchfork so testify well I would like to and and I have many many many emails in to folks about some of the challenges that we have so Veronica hex hello good to see you this mAb is here I still need to work out how to deploy asp net chord docker images to your NASM I try that later um so what what's map is pointing out here some people's network attached storage I have a Synology server here in the house will run docker and you can package up asp net core applications and deploy it as a docker container and it works really great I can I can deploy those images to mine to mine as you have to open firewall ports so that you can browse to and get to the content on that docker on that docker container but it works amazing Jean Valjean with the raid thank you so much for bringing your viewers over here hello hello welcome in we're a weren't my name is jeff fretts and we're in the middle of our asp net core workshop we're not even in the middle we're just getting started you caught us right at the beginning here we talked about getting dotnet what it looks like at the command-line and we're about to start building an API web service an API web application that we can deploy and use on all kinds of different services Alexandre thank you so much for the follow appreciate that um taking a look here would be awesome with a Synology asp net deploy tutorial dukkha soft can you do me a favor so that I don't forget can you go over to let me show you over here on my github there is a fritz livestream either create an issue in here about and we did finish this command we built this command there is a no more and then command but open an issue or mention it in the discord server you can find information about the discord just below me here on twitch or execute the discord command and you can get access to it but remind me that would be really good to do how to deploy your asp net core application to a Synology i can definitely show you that let's take a look here yep I just got my my Synology nas within the last month really great stuff I it runs and serves my videos and photos and my backups very very quickly quite happy with it alright so let's let's get into this let's start creating our first our first project here this is gonna manage back-end services this is gonna be more like a this is gonna be more like a micro service that you might see they that's intended for machines to interact with this isn't really intended for humans to query but machines or other web applications mobile applications power bi applications might reach in and query and interact with these types of services now I'm using Visual Studio 2019 but I'm and I'm going to create an asp net core web application we're gonna call this if we're gonna put it into a conference planner solution we're gonna call this the backend service and we're going to build an API now if you're at the command line here are the dotnet new commands that you execute to do this dotnet new solution dotnet new whip Web API and dotnet solution add and you reference the project that you're adding so you get this cool little interface not interface but you get this cool little separation of a solution that contains three projects that are related and allow us to easily reference each other I kind of I got a for Drive Synology I forget which which version it is nine something so alright so I'm going to scroll down here and we are going to build a asp net core don't do this to me i restarted everything so it would run nice and lickety-split so we're gonna build a a web application and why didn't i get the template oh because i didn't get there yet alright so the location i want to put it down in is here so i'll paste that in and the solution name like it said is conference planner [Music] and we're gonna call this the backend service alright so we'll create that and it should come up and ask me for some templates here there we go I mean dotnet core asp net core 3-1 and we're gonna choose an api it's automatically going to be configured for HTTP it's got features for us there so it'll light up in in hook up certificates development certificates for us here on on our workstation I'm not gonna turn on docker support here and you can see this came from Microsoft it's one of the official 3.13 templates so we'll create that let me take a look up there is that real kayak and thank you for the follow John peek in Franklin 89 thank you so much for the subs and we're gonna make a donation to the World Health Organization and help them fight the good fight against kovat 19 lilly hazel is here hello hello my friend there she's welcome in Oh John peek gifted a sub to Franklin well thank you appreciate that very much appreciate that do I use any cool extensions in Visual Studio I try not to I want to keep this as as stock as possible so you see what the what the official right the default Visual Studio experiences a lot of folks will add in code rush my friend code rushed here on the live coders team that's Mark Miller he works for DevExpress Mark Miller he works for DevExpress tremendous plug-in that does all kinds of great refactoring features inside Visual Studio you can also get resharper from the folks at JetBrains a lot of great plugins that you can use with this those are the two big ones that you'll see folks layer on top of Visual Studio a flag good to see you chef Brent is here good morning so good to see you um there you go I'm using I'm using the Enterprise Edition of Visual Studio 2019 you can't see it but I have the preview flag back here back behind the the actions list the events list that's happened up there this is 16 6 preview 2.1 that we're using I like to use the preview versions of Visual Studio here on the channel so you can see some of the cool things that are coming we can experiment and learn a little bit about what's being built as well haven't used resharper in years as it used to force Visual Studio to render text slower while typing it says L Simmons yeah so resharper is notorious for running in the same memory space as Visual Studio and running out of memory because of how it processes and manages your application code rush handles that a little bit better so you get a little bit better performance out of code rush and I'm not compensated by either of those companies to comment on it I think they're just really cool tools um let's see here let's get into let's get into a little bit of our source code here I hope that font size is good enough is that font size good for everybody I think it should be I've even opened up the size of the editor here so you could see more of what's going on so we're gonna build to start off here we're gonna build a way for in our conference a way to store information about speakers well in c-sharp everything is object oriented so a speaker is a class and a class has properties so we're gonna have an ID for our speaker or speakers have names they have some bio information about who those speakers are and we're gonna have a website where can I learn more information about this person so we create a class that has these properties and a property is done denoted by giving a access modifier a type and then the the name of the property then we have what are we allowed to do with this well you can get the ID and you can set the ID and you can there's other ways that you can set access to these whether it's public private internal for get and set if you want to change it from the default that's defined over here these things that you see in square brackets above the properties these are called attributes and these attributes are even more specifically referred to as component annotations now required means that when we're working with this we want to make sure that the name is a required field you can't create a speaker without a name that's just silly and it's got a maximum stream length of 200 characters bio is a maximum string length of 4,000 and the website has a maximum length of a thousand now those aren't enforced by this c-sharp compiler when you're working with this they are enforced by other libraries other features of the dotnet framework that we're going to be using here and I'm using frameworks because we're gonna use entity framework to help enforce some of this and our razor templates are gonna help enforce some of these constraints as well so let's create a models folder and we're gonna create our speaker class inside that folder so I'm gonna right click up here on my project I'm going to add a new folder there it is models and I'm gonna use a hotkey alt shift C carnac isn't running Karnak where'd you go on me here friend let me turn these on and after I create this class I'll come back over and answer some questions they're from the chat room so it is Karnak there Karnak where'd you go there friend I'm gonna restart Karnak karnak puts a overlay of the hot keys that i use here so you can learn a little bit there you go alt shift see you see that in the corner and i'm gonna create a class here called speaker so ultrafeed says create a new class in visual studio wherever I am in this is my solution Explorer over here on the left so there I'm in this namespace and in the namespace is a way to organize your code so this is the namespace backend dot models I'll be able to reference my speaker class by reaching into back end models dot speaker and be able to access that instance so the actual syntax of what's here isn't what's in what's true important and I'm going to just copy it in so you don't sit here and watch me type all these things now I think I saw there was a question in the chat room here let me make sure that I grab it here where is it my goodness ah there it is definitely ask a question are these standard c-sharp attributes um they're not standard to c-sharp but they are standard to what we call the dotnet base class library the the base features that everybody has available to them and you can kind of expect to have when you deploy an application and they're part of system dot component model data annotations so you'll find this delivered with the.net core framework and usable where no matter which platform you're on so it's not standard per se but it's available everywhere right so let me see here thank you for the follow truly in appreciate you joining us let me just take a look here and I'm not gonna answer all the questions that are coming through here if they're a little bit repeated I want to make sure that I keep moving things forward yeah we're maybe 10 minutes into the actual workshop itself we took some time explaining what net is first but our friend Jean Valjean asks what about the key property on the ID field do you need it or is ID every time mapped as an ID field this is a good question because if we go back to our data model that we talked about earlier right so we created a speaker's table we're going to create a speaker's table and clearly the ideas are unique identifier and in database parlance you would call that a key a primary key and jean valjean is asking about the key I think you're referring to it's called a key attribute right or right that we would put up here we would say key and you can see if I didn't mouse away from it denotes one or more properties that uniquely identify an entity you can do that to kind of force that hey this field is the key you don't have to do that because you're right anytime that an ID property appears inside of a class that's going to be used by our entity framework data access library object relation öö RM our object relational mapping library it's inferred that that is the key that's right you're coding vice by a convention that the ID is a key thank you for the question John Valjean appreciate it [Music] um good morning friends good to see some new folks tuning in there's was there question here um shucky asks let me let me put this up I'm not gonna dig too far into this do I have a link to that helps folks understand when to choose dotnet framework versus dotnet core dotnet framework is the version of.net that's been available since 2001 so it's been around for almost 20 years runs only on Windows but has some tremendous projects that are available project models that folks can use but dotnet framework is is being put into maintenance mode no further development of new features will be added to dotnet framework dotnet core is where investment is being done going forward because dotnet framework is really a component of Windows so if you want to do something outside of Windows you can't use dotnet framework so dotnet core going forward is what's recommended by the Microsoft team for development and I'll even take that a step further because in November we won't have dotnet framework for 8 we won't have dotnet core 4 they'll be just dotnet 5 and dotnet 5 brings together the things that were in dotnet framework windows forms development WPF development web development which is also in dotnet core you have all of those things and mobile development with xamarin so dotnet 5 means there's only one dotnet framework being managed going forward and it's called just dotnet so I would see going forward Usenet core is the recommended direction but even more than dotnet core it is it is the one dotnet to rule them all forged in the fires of Redmond well played surly devil I like that uh I I like that a lot the one dotnet framework to rule them all fortune in the fires around America so so there isn't really a document foot but there isn't a document per se but there are some blog posts from the director of dotnet program management Scott hunter that you can find on the asp net web blog out there that you can read ja sure asks and and this is a very good question and he's he's almost reading ahead here it spoiler a little eart what about dotnet standard dotnet standard you know what i'm gonna cover this question when we get to the next project where we're actually working on dotnet standard that's a great question and i'm going to park it for now and we'll talk about dotnet standard when we get to the next project so alright let me go back here so we and our speaker object now let's add the capabilities so that we can interact with the database so we can interact with where we're going to save this so we can do that by adding new get package references just like npm and and p8 it had npm for node folks and what is it pair for PHP folks and what is it for python anaconda helps with python it's not anaconda isn't the thing i forget the name of the package manager for python maven for java folks we have NuGet packages for don''t tips that's what it is for python Thank You L Simmons so we can add packages at the command line using a command like this dotnet add package and I can do that right here I'll go into my conference planner folder I'll go into that back-end project and I'm gonna paste in that command dotnet add package Microsoft entity you know what it's behind me there let's move it up to the top of the screen there we go dotnet ad Peck and now it's behind the other thing I can't win here can i I tell you folks so dotnet ad package Microsoft entity framework or sequel server so this is going to get me the ability to connect to sequel server right Microsoft sequel server with my project well maybe you don't like sequel server maybe you're not on maybe you're not on Windows maybe you'd prefer to work with sequel Lite that's ok we can add a package that'll support sequel Lite as well and it's exactly the same command dotnet ad package Microsoft entity framework or sequel lite version 3 1 3 and it's installed and is now written to disk need a shorter prompt I know it's it's putting that entire folder in there and it's getting real old yep eight hours that's right Mary Jo Stabler hello hello so does it support no sequel databases as well entity framework was this designed to be able to but folks prefer to work directly with the api's for those no SQL databases so is there a way to easily list put this up separately because I parked that other one is there a way to easily list what database packages there are via the command line I don't know if you can search new get directly from the command line but you can go to new get org and search for Microsoft entity framework core and it'll show you relational abstractions there's sequel server and in memory database if he'd like their sequel Lite but you'll also find folks like Oracle I think it's Oracle entity framework or there it is their driver because Oracle makes it is under the Oracle namespace not the Microsoft namespace just like MySQL if you want to use MySQL there's one for that um I don't think it's Postgres I think it's PG SQL there we go so there's the one from the Postgres folks n PG SQL entity framework core and that'll get you up to speed if you want to connect to Postgres um I don't think it's I don't think DB is in here no MongoDB and those types of no SQL databases you'll see folks just connect into and they don't use an entity relational mapper because like entity framework because it's not relational house Basu thank you so much for the Risa 3 is that 13 months 13 months oh my goodness thank you so much for more than a year with us really great stuff and and we'll make a donation to the World Health Organization and help them fight the good fight against Co vid 19 yeah cosmos DB that's right this is sparta there's another database that folks folks will use it's non-relational it's no SQL that folks will work with and they'll work with using that API directly and and you can hide that API behind a repository model because you don't care the rest of your application and I don't wanna get it too far into architecture the rest of your application doesn't care how you communicate to the database the application just wants to be able to go get data from the repository if the repository is sequel light sequel server MongoDB cosmos DB maybe it's a file on disk it doesn't care the rest of the application just wants that data wants to save data so you put you set up what's called a repository pattern here and you're gonna see a little bit of that pattern in this application thank you for the follow Shankar 20 appreciate it MongoDB has its own ODM called mangu very cool so next thing we need to do in order to work with our entity relationship mapper is to create a database context and this is what's going to do the mapping this is right we're gonna inherit from a specific database context from entity framework that does all the work we're gonna create our own that sits on top of it that will specify there's a collection of speakers in this database that you can work with and the DB context that's referenced up there is that right that's a different class is going to go and do all the work to actually generate the insert update and delete statements into our relational database so let me let me create this class inside the model folder we'll call it application DB context and I'm just gonna copy out the contents of it go back over here to visual studio and let's create let's use the right keystrokes Jeff we doing there we go application DB context here we go and I'm going to paste these in that source code and there was a reference in the source code that we had initially right that was in in the workshop guide to put this : DB context in c-sharp saying : DB context says inherit from this other class and if you're not familiar with object-oriented programming what that means is we're gonna take application DB context and we're saying this is a database context it has all the features of DB context and we're adding more and we're customizing it specific to our application now visual studio helpfully puts these little red squiggle lines underneath of it these little right little wavy lines underneath of it I can control dot on those and we'll generate appropriate using statements so remember when I said earlier about namespace kind of gives us a way to categorize where things are living you reference and specify use things out of those namespace shortcut my references by generating these using statements up at the top of the screen and you'll see if you're if you're watching this on a on a on a recording at the high resolution you'll be able to tell that the entity framework or statement is a little bit brighter than the dimmed lines here for the other using statements that's because when I mouse over at visual studio is telling me that the using directive is unnecessary that's that's a feature that this editor provides so I can actually say you know what I don't need these so visual studio gives me this little light bulb that I can click and remove those extra using statements that I don't need and when you have thousands of these files running around in a project because you've got a very complex very large project extra using statements are gonna add extra seconds extra time to your compile so it's sometimes a good idea to clean them up but not necessary you know the compiler will handle it with how small this application is we're building for this workshop not entirely necessary to remove those but I did want to show you that so you knew why some of that notation was appearing let me take a look here a couple comments real kayak finally joined twitch happy to find the channel well thank you so much real kayak very happy that you're joining us and I look forward to seeing more from you in the chatroom as we go through the project here today all the basis class stuff belong took that's right Mary Jo box has a has a comment here and it's not a bad one why not use ID be set instead of D be set because it stands for solid better depend on abstractions not on implementation details you can do this you can absolutely do this this is a beginner course you're not going to get into that here don't want to confuse folks but that's absolutely something that you can do like I said don't want to over complicate getting into architecture things that are a little bit further down down the road here so [Music] ja sure is is right here are you certain the compiler doesn't ignore unused usings anyway it does but it needs to identify and understand that they're unused and if you have thousands of files that's time that the compiler doesn't need to be wasting it does ignore but it needs to understand if it can ignore it so not a problem gnarly I'm and and that's the point that's why I stress this is a beginner workshop and the folks that have that have questions maybe you're brand new to dotnet maybe this is your first time looking at Visual Studio I want to make sure I answer all of your questions no question nope no question is too simple there are some questions that are asking about what can you optimize can you take a in advance technique here and I will answer those questions but I'm not gonna dig into them I'm gonna hold those off as advanced questions or even intermediate questions that I want to make sure we focus on on answers for the beginner folks and I and I see some some friends here in the in the chat room friends from the live coders team like ramblin geek and Mary Jo Stabler and the bald bearded builder as well want to promote and and make sure that you know they're happy to answer questions along the way here they they're from some of them tremendous web developer some of them are tremendous dotnet developers there's all kinds of great folks on the live coders team so make sure you check them they're great friends absolutely gnarly thank you so much for the sub look at that really great stuff and we're gonna make a donation to help the World Health Organization you're gonna get those 17 emotes that we have here on the channel and turn off the ads here on Twitch thank you so much space shot makes a very good point I'm gonna I'm gonna put this up because I do want to make sure that everybody sees this and and I'm just now reminded of it if you're wondering about something that we're doing here other people probably are also and that's okay ask the question if if somebody in chat can answer it quickly they will if it's something that we want to bring up make sure folks on the recording see and and we want to dig a little bit further into will bring it up like like Chris's statement here space shots and we'll talk about it a little bit further here I'm gonna be here all day it's gonna be recorded and available on youtube so you can search through it a little bit and and I hope you have a good time with this I saved the bald bearded builder today what did I do what did what I saved the bald bearded builder let me see what did I do here banana coffee for a week but guess what arrived oh my gosh look what arrived for our friend the bald bearded builder a little bit of madrenas very nice it's so good I have a little bit of vanilla cap here ready to go in a little bit thank you so much for the share yeah madrina they're a sponsor of the channel here want to make sure we call out and thank our friends over there for supporting us here on the C sharp Fritz Channel thank you for the follow living Margaritaville it's it's gonna be 5 o'clock somewhere and it's gonna be 5 o'clock at the end of it at the end of this workshop oh yeah you can execute the coffee command you can ask about madrenas coffee and it will answer there for you they've been out of your favorite flavor for a few weeks we'll Keesler oh no drop me a line about which flavour it is you're looking for on Twitter make sure you hashtag madrina sand and our friends that madrenas will help you out first try and it's amazing glad you're enjoying I forgot to turn on live share here I'm gonna have live share running all day here let me turn this on if if you have visual studio if you downloaded visual studio code um maybe you don't have either one of those maybe you're on maybe you're on a Mac maybe you're on maybe you're looking on a tablet if you want to tune in you can even click through on your browser and we'll give you the ability to navigate around the projects as we're working on it I'm gonna create this time we're out here on stream elements let me pop this out and I'm gonna add a new timer here and we're gonna call this live share so every let's make it pop up every 10 minutes and we'll say connect and navigate around the code for this project in your own editor or browser join the live share that's not our at and we'll post that link and activate that timer there we go so no no that's not what I wanted to do so now if if you're a beginner if you want to take a look there's a read there's a read only live share there and you'll see your initials will pop up up at the top there next to where it says sharing read-only and you'll be able to navigate around the project you'll be able to take a look at things um if there's something you don't understand we'll show you how all of it works and if you click that it will open in your visual studio editor that's right or you can open it in a browser if you'd like and you'll get the visual studio code editor in a browser navigating around this project and I think you have to login with github github or your Microsoft account and you'll get navigating around and you could take a look so alright so we've created this is how we're gonna interact with our database we've got this application database context and it has a collection of speakers in the database that's really easy to do but now we need to actually specify how do you get to it well I don't have sequel server installed on my machine I purposely didn't install it I don't think I have install I think I uninstalled it by defendants over you can run sequel server in a container absolutely it takes up a little bit too much memory running on this machine that I'm also running OBS on and Visual Studio in the compiler so I'm gonna pass on running any container it's really good in a container but because I'm running some very processor intensive things already and OBS is a monster for how I'm producing and presenting I'm gonna pass on that and I'm actually gonna use the sequel Lite instance of this so I'm just writing a file to disk and it works really really nice for that I could run off of sequel Azure absolutely I could do that I'm gonna run on sequel Lite though I think that's it's something easy to use here creating this project with an interior hierarchy would be better than creating dbcontext so is that is that kamal koba koba like kobe 'ok you're gonna see this turns into interior architecture what do you see so you can define a database connection string in here it's that ODBC connection string with here's where to go and get this but I'm actually gonna write it write to disk using sequel light so the directions to register our database contact service are gonna be written a little bit like this now let me copy this and put it into what's called my startup file over here where we configure our services let me explain what this is after I paste it in here so our startup file this class has all the information necessary to startup the web server and there's basically three methods here there's a constructor called startup and it's taking some configuration information about the application will talk more about configuration later but it takes in some configuration information and stores it here in this we saw properties earlier here in this configuration property the startup class also has configure services and just like the comment says here in the default template it is used to add services to the dependency injection container to the the service locator container that we have available we we have services that are injected into all of our application that we're running here in the asp net and by using this we can configure what services are available so we say things like services add a database context here's how I want you to interact with entity framework in the database context I want you to use inside of these angle brackets this specifies the type of it and the type we want to add is that application DB contact context we had before and I've got a little red underline there a control dot and it'll give me my using statement for that there we go now there's options we need to configure so inside the parentheses that we have here in visual studio should there we go it'll give me a little highlighting here to show me which parentheses that matches up with and I'm gonna define some options and I have this this is actually a equals greater than but when I put them next to each other my font turns it into what we call a fat arrow so that's an equals greater than and here are the options that I want to configure for it so the default source code here that comes with the workshop says well take a look at the operating system and if we're on Windows use sequel server to another control dot to get my entity framework or information in here and if we're not on Windows use sequel light well I don't have sequel server installed so what I'm gonna do is actually chunk this down to just use sequel Lite all right and I'm going to I want to I see these spaces here and there it's freaking me out because I'm a tabs person so right I can see it still put the why do I have that there expression value is never used yes it is all right so I've configured now specified use sequel lightin and in my data source says we're gonna write a file called conferences DB fantastic real easy to use that you're right is that it's let's LA wayy when you do install Visual Studio you can install sequel local DB I uninstalled it [Music] so Co you come all fantastic I'll remember that thank you appreciate appreciate the note about your name and I want to make sure I get everybody's name correctly here as we talk to chat yes we are keeping it simple and progressing to better great way to describe it there spaceshot thank you um quoting mark this is this a good point for folks coming from dotnet framework coming from dotnet framework to dotnet core I found startup in di the toughest aspect of converting adding to your knowledge not easy for beginners to know that you can do what you can do in that class works right there's a lot that you can do here and configure services is like I was explaining its how we can configure those services those things that are going to be available across the rest of my application so I'm gonna configure database access I can configure logging in here I can configure all the different things that many parts of my application are going to use and I'll show you later how we inject those services into other classes it's really neat we'll take a look at that in a minute Thank You bossman snake for the follow appreciate that so now it knows how to make this available how to use the database help to have a database context that we're gonna interact with so now let me go back over here we've created these using statements yes I did that so the next thing are these things called migrations so migrations are are the way that we have those statements that you use to update your database right when you deploy to a production area you always have that wait a sec how did the database change between the last time I deploy to production and all the changes that I wrote in in development in testing since that last time what what alter table statements don't need to write or create new table or create you or or what what changes do I need to make to the database so that what I'm deploying to production matches well we have this package called entity framework tools that I'm going to install that allows you to generate and manage migrations and migrations are directions that indicate here's how the model has changed so that the database can be updated by just saying we'll take the new migrations and apply them really really need a brave cover you like the new mod view interface I'm glad you enjoy it I think it's really cool it looks a little bit like the broadcaster's to you really really great stuff there I'm like oh my goodness all right um looking down you're just trying to keep up with all the things that are going on here um Marcus asks a good question there let me flip back over to here Marcus asks a question about this database context here let me put Marcus question up here it didn't show up let me turn the auto display there we go sure the database context be transient or scoped now this is just a little bit further into this but services that are registered here can be declared with one of three different scopes different lifetime scopes they can either be transient which means every time that I request one of these make a new one they can be a singleton that says that says well it's the Highlander rates and they're only ever is one and it's managed for you by the service locator and there's also scoped which means every time there's a new request a new web request that is handled it creates a new one that's available for the life of managing that web request and after the web request is done being processed it releases it and back into the pool by using this syntax at dbcontext by default it creates scoped instances of our database context you'll sometimes hear that referred to as a unit of work pattern because you'll start the database context do your work and get rid of it at the end of that request so you have that same database context available for the entire duration so those changes you make all get committed at one time before you're done working just before you're done working with the request thank you for the question and there there are other ways to tune that absolutely there's there's ways that you can say right that you can turn this around and turn it into what's called a context pool where it will allocate more connections of these so that you get better interactions better requests for database connections you don't need to do that for how small this application is but dbcontext pool is a feature that you can light up there as well they are pooled but dbcontext pool really forces the ability to do pooling in it it does a couple other optimizations for how you with it all right so we've created we've brought in the tools so we can create our migrations so let's create an initial migration and update the database tell it to go and generate that now there's a couple different ways that you can execute and do these migrations if you're running Visual Studio there are some powershell commandlets that you can run inside the package manager console and that's PowerShell right there easy for you to use but most folks are gonna be here at the command line so we're gonna install the.net entity framework tools and this is a global tool we heard some chatter earlier about global tools that are available to you as a.net developer everywhere this is already installed on my machine so I can move forward with it I'm going to build my project and add that initial migration so let me do this we'll build the project with dotnet build and it's going to go and build everything here for us do-do-do-do-do there we go zero warning zero zero errors mmm I'm going to add an initial migration here so all of our commands are kind of dotnet and then the tool name EF a noun migrations and then a verb add after that I have the initial parameter I've named my migration initial so we'll execute that and it's going to create my initial migration that defines how we're going to interact with the database with just our new object that we've defined yes yes but it created it and now if I go over to my project check it out there's a migrations folder here and I've got two new files let me show you what these files are because they're kind of important here's our initial folder I'm sorry our initial migration and it's named after the time when this was created in the name at the end so that you have a a a key that you can kind of take a look at and see what it's doing but it generates this c-sharp code that defines for the database how to update and what to make it look like so when I say execute the initial migration we're going to update to that next version that has the initial migration built we're going to create a table name speakers here's our ID field our name field or a bio and website just like we had back here in the speaker class it's going to create those in the database and it's going to create a primary key automatically for us if we need to back out this migration if we need to roll it back when in order to roll it back the well the reverse that happens is it's going to drop the table easy make sense that kind of so that allows us to kind of queue these up so we see the difference between the two and this is a snapshot of what it looks like at the end of all of the migrations being applied so that the the model builder and that's what does our entity relationship mapping between the the relationship database relational database and our entities our classes here in c-sharp this is what's defining the connection between those two so that it can load this very quickly and get us mapped in working with the database so you'll see more migrations added as we go and create new features in the database for the database so I've created it well now let's actually update the database easy enough dotnet EF database were right there's the thing we're acting on database and the verb update apply those migrations that haven't been applied yet so let's apply those and after I'm done that done this I'll show you what the database looks like and I'll come back over to the chat room and answer some questions so it rebuilt because we now have that migration file in there build succeeded and it gives us the ever helpful done command output to indicate that it's done so if I look at my directory now there's my sequel Lite databases database conferences DB so if I look at my database browser for sequel Lite let's open that up and take a look at C dev the asp net core workshop twitch workshop folder we are down in this and over here there's the database file and you can see inside the file I have a speaker's table and it has those columns that we were talking about and it also has a table over here called migrations history EF migrations history this indicates there's the name of the migration we applied and here's the dotnet core version that we used to apply it so it in the database it keeps a log of what version and what migrations have been applied this way we can make that quick comparison and know what new updates need to be applied to update the database to match the version of our application so the moral of the story friends is don't delete this table leave it out there all right and we have a sequence table so it can count appropriately so there's our conferences DB file let me take a look back here at the chatroom let me see if there's some questions here to answer [Music] all right brave Cobra asks would you migrate the database upon startup or as a separate process tool or program good question let me let me highlight that from brave Cobra and and I like I like that you're kind of pushing a little bit of this here that's good would you my great the database at startup would you always update and say put down the latest version of this in development mode where we're making changes a lot to our database it may make sense to update the database on startup and there's a configuration you can put into your application to force that to happen but when you're getting ready to deploy to production and you're gonna have that production release you don't want to be touching the database and updating the structure of it when you get into production at that point when you're ready to update your production database you should run it as a separate process same thing about Quality Assurance if you have a test instance of your application or a staged instance some folks call it run that migration only when you update not every time you start the application so let me continue scrolling through chat here and [Music] is that confused confused Lele asks wouldn't it be easier to do this in the console inside Visual Studio yes you can do that I like doing it at the command line out here it both worked the exact same way it you doing it out here at the at the windows console it shows that you can do it maybe its own you're in your bosch console maybe it's in your Mac terminal wherever you might be working it'll work over there as well not just inside inside of Visual Studio or you're right binary chef or the terminal inside Visual Studio code your choice it works everywhere but thank you for pointing that out confused lately let me continue here this is rickety rocket asks why do you need a snapshot and another database context so I actually don't have another database context let me show you the the the one database context here this is extending the default entity framework database context giving it some additional features that light up and add okay they light up it got a message text from the boss got a double check on that this application dbcontext customizes the default context that comes along with entity framework to add the speaker's feature the context model snapshot and you notice it's actually the full name of that other class this is the model snapshot for that that indicates here's the properties in the database and how they map so it can load and get that mapping very quickly instead of having to generate and figure out where the mappings occur it's just a way to shortcut that by generating some code for us okay good good good let me continue looking down here so migrations and you are not always the best friend says Jean Valjean I'm sorry let's say get the source code Oh to do a bit of an oh okay a new big question here from let me make sure I get this from is that Frodo's e asks what are the main benefits to using dotnet for website Web Apps as opposed to PHP or some other framework thank you for this oh my gosh thank you for the sub is that Rama ragnerok arc knows thank you so much janeski thank you for the hosts and priests no sorrow thank you for the follow to answer this question what are the main benefits um so with dotnet being free and open source what you're seeing is dotnet c-sharp asp net core is being tuned to the nines for performance and is according to according to the tech empower independent benchmark benchmarks the fastest commercial available commercially available framework web framework so PHP significantly slower node significantly slower no doesn't support multi-threading dotnet does there's some experimental Java web servers that you can get java application servers that can be tuned and run just as fast really great stuff but dotnet has amazing tooling for productivity and you're seeing some of that here with Visual Studio to help you build code faster and not have to think about some of those things that are going on in memory management and and how you construct objects it's really built to help you build applications faster in score thank you for the follow appreciate that and the c-sharp does work with peach paw Peeta with PHP there's a project called peach pie that'll help you compile and use it Taha you missed the beginning of the workshop go ahead and rewind there's the videos being recorded you can go ahead and rewind Wet Seal asked a good question about migrations should migration be part of the deployment process when deploying to production yes very much so that's exactly what you want when you want to be using it when you when you push to that next environment you you do the deploy run that dotnet EF database update update the database as you're deploying and you you warm up and bring that next server online this way your database is in sync with your server and it has the same version of data architecture as you do the application that's gonna interact with it good question thank you continuing to scroll here snapshot is also used to help determine the next migration yes is this it is this tanner ax asks if I have a compiled application ready to deploy to a server does that mean I need to have EF tools installed to be able to run a migration on the production server the EF tools will go along with it check this out when you I would have to publish I don't want to publish right now when you publish that EF Tools DLL that has that capability in it will be made available it'll copy along with you when you publish so that you can run the command when you get to the next environment you're gonna want the dotnet SDK to be available over there as well you can install and run that in that target environment so that you can run the dotnet commands when you get there all right let me see here spaceshot it makes another great point about dotnet can be used for all kinds of apps not just web applications like PHP and node and and rails but web sites desktop mobile games cloud scale applications IOT applications it all these different places if you want to be able to reuse code across all of those things dotnet is a great series of technologies to enable that reuse thank you c-sharp is the main benefit for dukkha soft C sharp ism is a very advanced language ver tonight advanced I'll rephrase very mature language that has tremendous features that are added to it with a dedicated team that continued to to innovate and add features that other programming languages are picking up and adapting adapting adopting one of the two they're adopting things like you're seeing async and await in JavaScript now that started in c-sharp things like generics right that got into Java started in c-sharp so things that they are being brought out and shared with the entire community are being innovated in c-sharp first is that F Kenzo welcome in appreciate the follow vault bearded builder likes adding logic and API startup to do the migration for him so the first time new Luke deploy code runs an environment it updates the environment you can have to do it you should do a little bit of a check to do that like you said it's not just a straight call but some logic check to do it first and then apply it that's doable but you need you do need to be careful you don't want it to run every time the application starts but if you can look gate it logic gate it you can get some success with that is that dear extol Soul Stealer guess Chris welcome in thank you so much for the follows continuing here someone used asp net for a reason and it's because they wanted to avoid PHP ah yes here's another good point from winter lore games dotnet is very decompile able due to a lot of tools on get up and the like there's a great tool out there called reflector do I have that right that will allow you to decompile dotnet dot and end applications and see the source code for it so where's code for it so really great stuff and I'm glad we got all these really good questions here reflector and dotnet peek there you go dn spy is available as well cool very cool there's a lot of tools out there to help with this you're gonna find the dotnet community the dotnet ecosystem it's a very rich ecosystem with a lot of a lot of companies involved that are making open-source projects available commercial projects available products available to help you be more productive so there's excellent explanations to the commands let's talk now about the API is that we built we're snotty you've not even done the first module here let's let's get through this and we're two hours in oh my goodness so here we go we can build controllers that's it you know what let's look at this first before I go and build a controller let's do that so we have a folder up here called controllers now this is built using that MVC architecture model view controller m-v-c and controllers like we have here are built as a class that inherits from controller base that will respond to requests that come in to some sort of HTTP endpoint and this one this is an API controller so it's intended for machine interactions we can build other types of controllers that'll render HTML or JSON or other data that we may want to interact with but this is designed to interact with data as an API endpoint so what we're going to do here with this this is a weather controller right this is the sample data that it comes with it's marked as an API controller right here's another one of these attributes and it's saying this is going to behave like an API this this class isn't something that humans are going to read but ap eyes are gonna interact with machines are going to communicate with with this to get data and output information and this right here I mentioned the controller listens on some HTTP endpoint well our web server has paths that you browse to right you'll you'll go to things like your here on Twitch you'll go to twitch.tv slash c-sharp fritz that slash c-sharp Fritz that folder location is someplace that on Twitch it's being resolved and turned into my channel or maybe you're watching on YouTube on youtube.com slash c-sharp fritz in YouTube is turning that slash c-sharp fritz into some direction that is actually going and saying oh well that's that's Jeff's channel let's load up that data well that's handled by something called a route and a route is how we declare where exactly this class is going to interact in process the requests that come in from from users from from a browser from those other machines so this is gonna listen on now square controller this is this is a template this is kind of a trick here that you can use right at a macro almost that says we're gonna grab the NIEM to listen to is actually everything to the left of the word controller in the name of this class so by convention you name your controllers something controller and it helps to identify to other folks that this is a controller and you can use things like this markup this directive to say well grab everything to the left of that and that's where we're gonna answer that's where this controller is going to behave now we have things in here that that are properties that are well this is a field here a read-only field that is a logger for the weather forecast controller called underscore logger and we have another field up here that air it's a collection of different summaries weather summaries as an array of text freezing bracing chilly cool mild warm balmy hot sweltering scorching whatever right this isn't doing a real forecast it's just making one up so you can see what it looks like but down here this is a constructor that defines how you construct a weather forecast controller and we spoke about dependency injection earlier from our start up class right our start up class it configures controllers in this application and we added the ability to interact with databases well here we're receiving in a logger interface ilogger that's a that's an interface that defines how we can log information and we're gonna receive one for the weather forecast controller called logger right that's the variable name and we'll pass that along into this field we'll store it so we can reference it later and this is a private field only this class can access that logger okay if it was public it could be accessed outside the class and we have one method to find in here and it's a method because we have a scope identifier public right this is publicly accessible by outside this class and we have it it's going to output a collection an ienumerable collection a collection of weather forecasts that you can get you can use the HTTP GET verb to return these and we have a an attribute on this to kind of force and declare that this is going to handle a get request to that weather forecast location we're just gonna random get set up a random number generator take a look at the collection of weather forecasts what we're gonna generate some weather forecasts and randomly bring in some sort of a summary verb here one of these words along with some random temperature between negative 20 Celsius and 55 Celsius and return that as an array it's just a random collection I don't care we're using this as a sample so the logger is created by default nothing is being logged to here by default we could blog if we wanted to and we'll see that a little bit later so I can run this and I can actually navigate to that weather forecast controller and see what it looks like if I right-click I can say I can say build here there's also up here I can say run it with iOS Express I can also run it on the command line by changing this over to the name of my project click that and it will run on the command line open a browser and let me navigate around the application I see some other questions coming through on chat I'll come back to that in just a second let me let this startup I thought we started where is it start my project let's go you see the little building thing here doo doo doo doo come up arretez so here's the console it's running it on the command line Visual Studio is running the web application on the command line why the command line because the command line is available on every operating system it's the great equalizer so we'll run it here on the command line and you can see some debugging information popping up here but here we're getting some information logged automatically that it's listening now here's what my weather forecast looks like that was randomly generated and it generates it in JSON format and it looks kind of ugly I could open this with another browser that has some pretty JSON formatting in here when we go over to a Firefox I'll open up another Firefox and there I have some nice formatting so you can see I have 16 Fahrenheit negative 9 Celsius and it's chilly ball meat warm right it's and it's just counting up the days no big deal right but here's a way that we've connected and gotten data out of our application simple and we're gonna do that we're gonna set this up so that we're gonna start interacting with in getting session data out of our application so that's what a controller looks like we need to create a controller now for our speakers so we're gonna generate one here using Visual Studio you can also do it at the command line there is a package called code generation that's made by the Visual Studio folks that you can use to automatically generate some code here for us and the code generator templates for asp net or down here but I'm going to use this up so you can see how Visual Studio does this so I'm gonna right click on the controllers folder add a controller and it wants me to create it yep for application dbcontext in it mmm API controller with actions using entity framework because we want to create an API here so I'll choose my model which is a speaker the data context how are we actually connecting and working with our speaker and it's a speaker's controller so it'll install those same NuGet packages it listed at the command line and it's going to generate my speaker's controller here in just a second while that's going let me take a look back over here at the chat room see if we have some questions to answer come all ask a question here certainly change to the way that Silicon Valley developer looks at c-sharp their their perception of c-sharp it the past some developers don't like c-sharp just because it's developed by Microsoft I think Microsoft made a huge peak especially after 2014 in starting to develop dotnet core you you're not wrong kamal there there definitely was a bias against c sharpened dotnet because of there's a little bit of not developed here there's a little bit of i don't want to give my money to microsoft because they're they're the they're the big 900-pound gorilla right there it's definitely changed in in folks in in the angel investor community in the venture capitalist community have recognized that you get really great performance and there's a lot of folks that know how to do C sharp and dotnet so it is getting more acceptance in Silicon Valley they you know Silicon Valley is a funny place that it's very entrenched in different things but it is gaining traction there let me take a look scrolling down here there is a pop Foose Gatien yes available if you want to office Kate your code spaceshot makes a very good point here the team would not have participated the.net team would not have participated in in a benchmark like tech empower the asp net team has not only turned the heads of the community but also of other folks at Microsoft and you're seeing more folks embracing more products Microsoft products embracing open-source and engaging with those individual communities so they can make everybody better and allow everybody to build great applications no matter the platform and binary chef makes a very good point here Silicon Valley isn't quite the real world they want to innovate they're gonna innovate things fast and they come up with weird ideas like uber for pets why do I need Ober for my pet so there's all kinds of funny things that happen in Silicon Valley that folks do yes C sharp has been open source for years but of particular note the Rosalind compiler when that landed in in the mid 2010s really kind of lit the fuse for dotnet programming languages to be available but bubble no I don't think so uber for pets yep that is exact that is something that was proposed in Silicon Valley and got a lot of investment so I've got my speaker controller right let me show you by default it references there's my application in DB context and remember when over here I added the database context to my service locator services I can now receive it in the constructor over here and asp net will automatically make this available to me and i can use that database connection inside this controller so it automatically generated for me here's i can navigate to api / speakers and i'll get the list of speakers or I can go to API speakers and some ID number and over return just that speaker right and there's information down here about a-put right so I can put and say will update this speaker's information or or post here's a new speaker to insert to add to the database and there's even delete down here that says well delete the speaker with this ID ubereats in madrenas yeah that's it that would be a thing sure absolutely so that that was generated all for us I didn't have to write any of that right and that's really great stuff there we go oh my gosh I'm almost I'm almost done my first cup of coffee [Music] that's a little bit of a drina's coffee but I'm gonna I'm gonna jump in like the bald bearded builder is done here I'm gonna move to my next cup of coffee I'm gonna get a little vanilla cappuccino here it's got a green label on it so it disappears in the chromakey kind of funny like that I was what I will really enjoy supporting madrenas and let me show you I've got I've got a t-shirt here from this is pudges pudges cheesesteaks here in Southeast Pennsylvania they're local a local store owned by a family that sells cheesesteaks sells the subs if you call them that in your part of the world we call them hoagies where I'm from and in in this time when when so many businesses are closed down and we want to support our local businesses that are staying open to help feed the public I'm wearing my pledges shirt here to promote and let them make sure they know that that we're thinking of those folks I made sure I I bought the t-shirt last night from him and and I overpaid paid a little bit of a little bit extra to those folks show them a little appreciation and thanks for keeping things running here I've heard okay hang on can I can I can I pause for just a second here however there's a really hopeful just one more second before I get back into testing our API um right is that rageth Wow points that I hope I pronounced that right I've heard about this Fritz Koch in Germany and in folks have sent me pictures of it and they've even some of I've even seen someone photoshopped my face onto the coke bottle I would I would love to try this but I don't know where to get it it's from Hamburg okay okay my favorite madrenas coffee right now it's the vanilla cappuccino I really enjoyed the they have a cafe mocha that's really good and there's also a vanilla cafe vanilla that that that was the first madrina site right and you always love your your first eye so I really like the two vanilla madrenas flavors Oh death night yes make sure you get it how many coffees is in eight hours of SP neck or workshop one two three four five six six good six is good six will make this work and will be feeling magical by the end of this a true story there's a steak dinner waiting for me at the end of this and a bottle of bubbly to celebrate alright let's get into this so back into into what it's saying here the next piece of this we want to test that API it was kind of ugly looking at just the straight JSON in our browser I'd like to interact with it with something that's more like open API and we can use a plug-in called swashbuckle the open API used to be called swagger and well who Swagger's while Pirates have swagger so they called it swashbuckle it's a it's a stretch but that's the name of the project so we're gonna add swashbuckle into our project to light up the ability for us to query and interact with a really nice user interface and to make some easy to use API is available standard API is available for folks to be able to consume and use so we can add swashbuckle by executing a dotnet add package statement let me head back over here to my command line here we are and I'll paste in that ad package statement execute it and it's gonna go download it insert it into my project and make it available now I've added a couple packages into the project and you might be asking me Jeff where's it put that in NPM I have that package.json file and I forget the name of the file that we have in in what is it pip dot pi in in Python and is it pair dot PHP in PHP I forget the names of those files yeah Fritz Cola yeah that's the name of the of the coke um where does it so where does that net put these references in in.net world we have project files and this is back-end cs proj is you saw it here when I look at the bat my folder there it is back-end CS proj when you look at this it's an XML format that's XML for backwards compatibility all versions of.net have this format and we have our package references right here real easy for us as humans to be able to read and easy for the machine to parse and turn into references to load and bring in these various packages we also have a target framework specified up here we're targeting net core 3.1 and we're using in particular a web flavor of the dotnet SDK so that it knows it's targeting and building something web web ish web ish fritzsche Cola there it is certainly did oh my goodness I like that that's kind of unnerving that they doubled the price of their their sandwiches at their local shop and I understand it might be a little bit difficult to get to get ingredients to get supplies for four restaurants and they may need to raise their prices to accommodate some of those things I'm okay with that in this in this time of need right now and my goal is to ensure that those local shops stay in business so so that's where these packages land so I I just added swashbuckle and we can now start adding swagger configuration by adding swagger generation here into our services so let me go over here back into startup let me close everything except for this tidy up the tap bar up there so I'll add the ability now for swagger to be able to interact and I've got a red underline there we'll clean that up so we're adding swagger generation generate the api's for open API and swagger and we're gonna generate a little bit of swagger documentation saying that this is API version one and it's called the conference planner API and there's version one down there and actually v1 I think is in the folder hierarchy yep we got our using statements up here and here's this is neat we can add use swagger into this part down here this is the third part of the startup I didn't mention this earlier this is our this is our HTTP pipeline when a request comes in right somebody browses to the website somebody makes an HTTP request into our application it goes through this pipeline from top to bottom so we and we chain these commands by saying app use something you'll also see app dot map or app dot run are two different other ways that things are named as you come in here but the first one says make sure we're using HTTP make sure it's on a secure socket turn on routing we want to be able to route things and now I just added swagger information to the pipeline if if swagger information is requested route appropriately and I had the swagger user interface that's built in sitting in one of these packages for us and it's going to have data sitting at this location this JSON endpoint and we'll serve that appropriately so folks can interact with it finally there is a thing that we put in here to kind of cheat so it'll navigate automatically to our swagger endpoint when you just run the application so let's run the application navigate to it and take a look [Music] should the code be before use routing now I'm going to use the setup the routing first and then configure the routing capabilities after I believe that's how it's done I think that's how we've done the things that you set up in this startup class this is like set it and forget it mode these are things that you're going to set up once and you're not going to come back to it's just there you don't have to reference it and it just works so now if I go to the root of my application see it rerouted me automatically to index.html and it has my API definition conference planner v1 just like it had inside my documentation and I can even navigate directly to that JSON and see exactly what my swagger definition is my open API definition is for this API there's different responses there's different formats that it'll give you where these things are located how you can find them at that Dollar ref location but I have this really cool user interface so I can actually click through and say we'll go get that list of speakers that we have and when I click execute it's actually doing a curl you know what a kernel is curl is execute this this HTTP command we want to get at this location and pass in a header and see what comes out of it well we didn't get any speakers because there aren't any speakers yet Gavazzi and and some folks are saying that it should be before routing it's working it says use just beef just before use routing I haven't working just fine for me here [Music] if I move it down there and rerun it [Music] that's okay swagger was added after the project all right so that's the weather forecast end point I'm going to delete that and there's all of our content it worked just the same so I can even add speakers here I can say try it out and it'll give me well here's the format of what this should look like so I'm going to add a name and we'll add me Jeff is let's open this up a little bit oh you're not gonna make let me make it wider Jeff is a really nice guy and my website is HTTP Jeffrey Fritz com I can click execute and it'll it will attempt to post that if i zoom out here a little bit so there you go Karl posts and it's accepting text it's going to push JSON content and there's what it updated and the response was well here Jeff's ID won and I can download that and look at it and if I go back up here to my get we execute that I can see here we're gonna go get that data and now in the response I get information about that one speaker that was created great so I've got a simple little piece here that allows me to interact with to test out that API in C then it works cool ah Thank You Cabasa um and we're gonna get into that come on oh that's coming up that's spoiler alert in the chat room um I just close my browser with github didn't I rats there we go all right so we tried that out yep and we can also get the weather forecast they wanted the low tyrion lanister but I load Dorothy Gale all right and I actually you saw entered my data so click the try it out and you're able to navigate around and see how it works we're gonna continue adding features to this and we can continue adding features to that API I don't think oh yeah yeah there's more information that gets loaded up and it's yeah you're gonna see some new data updated down here and what it looks like let me back up just that one second we don't need that weather forecast controller I'm gonna get rid of that because we're not doing weather forecast out of this I'm gonna right-click on the project choose properties I'm gonna set the debug location so when we tell it to debug I'm not gonna go to weather forecast we're just gonna go right to the root of the website which will take us into swagger so I'll rerun yep and you can generate clients on-the-go from this as well it is it's very similar to postman surly def but it's embedded in the application right so you get documentation that kind of comes along with it there's ways to customize this with CSS and whatnot so there I can actually query and say well give me just write I why aren't you letting me key this in try it out well now you'll let me key it in and it'll give me just right speaker 1 is difference then yes we can customize this we can add some annotations that will tell more information about what our speakers are what they do right so instead of just returning speakers over here I can add information about the speaker the name of the speaker biographical information about our speaker right and these are standard summary comments that dotnet knows how to consume and where you can learn more about our speaker okay and when I launch that those comments now are going to turn into workup and features in that user interface check this out yep postman lets you generate generate test Suites nothing's right you're getting curl statements that come out of this that you can certainly use and learn more about and reuse however you like so right there's information about where is it I can actually hear speaker open this up and now why didn't it include what did I miss it should have given me information about what those are schema saying it's it right it's giving me that annotation of the maximum length and whether it's nullable but I'll wait a sec there's a there's a command to turn on for that I you have to turn on XML documentation in order to get that to come through is what I forgot and is it did you get removed from this it may have gotten dropped from this yeah I always like showing this because you can you can generate the XML now you bring that up just because it's a cool demo so dotnet Oh swashbuckle xml doc and it's it's really neat how you can you show this here we go you can get the xml docs by turning on generate the documentation file here yeah we're gonna want the know warned as well let me copy that whole block so we can update our project and turn on additional features to say generate documentation from those from those summary notes that we put on there and inside of right here we go we can inside of our project we can after the swagger doc is defined here we can actually load the documentation for it so I'll go back over here and that's anything that it configure services yeah up here so I'll paste that in so it's going to go get the appropriate xml for this and oh that's inside of that my bad move that up there out of space tap it in semi out there and this is options Oh need to just open this up a smidge alright there we go so now it's going to add my XML documentation into this let me rerun and you'll see what's happening taking a look here here come's alright so now if I scroll down here and look at mine there we go so now in my schema because I added that summary information now it becomes very documenting of itself as to here what here's what this thing is and even if I look over here at this JSON write it [Music] there's the speaker's the parameters the responses right and here's the information about the various queries where is it the definition here speaker name is required and it generates a description tag so that other API is other user interfaces can output well this is what this field is so adding that little bit of documentation in your c-sharp for this class right not only did we add to this class the this information that isn't really necessary but just that little bit of documentation now all kinds of folks can consume and learn about what these things are and benefit from it hey Frank good to see you yes there are other plugins called in swag and in swag studio that will help to generate client-side code as well that'll allow you to interact with in query these api's so that's the back-end service that's as simple as it gets to build a micro surface and we've really spent a lot of time talking through all different features here to make sure that beginners understand how we're building this they use something I believe called dapper Darryl code stuff so alright that's just the first module we're gonna pick up speed here a little bit because I've explained some of these things and we're gonna start to add features now for the rest of the back-end services we're gonna create a conference object that we're going to pass around we're going to create those other objects speak we're gonna make our speaker object a little bit more complex and we're gonna add attendees in sessions and these other things into into our back-end microservice project so it has a complete way for us to interact with that data store where where we're going to persist all of this data and that's coming up in the next module
Info
Channel: Jeffrey T. Fritz
Views: 18,337
Rating: undefined out of 5
Keywords: c#, aspnetcore, dotnetcore, .net core, asp.net, asp.net core, workshop, how-to, get started, first, software, programming, development, code
Id: jFghj_l9-CY
Channel Id: undefined
Length: 139min 46sec (8386 seconds)
Published: Sat Apr 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.