3-Layer Architecture in ASP.NET MVC

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to learn how to create and implement a three layer architecture for our project in asp.net MVC there is some difference between the three layers application and three tire applications we call an application three layers if all the three layers are deploy in the single servers however if they are in different physical server then it would be considered as three entire in three tera plication your application layer data access layer and business layer would be in three different servers so in that three layers architecture first one is then your presentation layer second one is that logical layer and third one is that your data layer first need to understand what is the layer a layer is a useable person's of code that perform a specific functions so let's start one by one so first I am going to create that your three layer project first open that where you create the new project select that one blank application first I am going to select that we are blank application another user type visually this one is a blank solution okay so this one will be the three complication okay click on ok.now your blog blank solution has been created once we are going to open the solution Explorer click here that is it 3d element blank solution now first I'm going to add one layer that is it get a new project here I am going to select that your last layer really this one that is a class family I am going to give the name that a business logic logic ok business logic click on OK now you can see that first project has been added so I'm going to delete this class I'll do that next I'm going to create add one more project that is a class level project this one I'm going to learn give the name Business Objects click on OK now second one also it is delete that default class now next one is the orthotics death add new project that this one will do with the y-axis click on OK and the last one is that your MVC project so go to the way it is to dr. canvas implication so we have users click on ok select empty MVC so this one is your presentation layer net all those creative this one is a presentation layer that we map user if you feel weak there close all those so this one VIP user this one is a MVC application this this fall is called that presentation layer and this one is here at access layer but if you will look that business logic and business object this both will call that your business layer so first need to understand what he said data access layer so that contains method that helps the business layer to connect the data and perform required action whether to return or to manipulate data insert update blip and handsome ok second one is your business layer so a business access layer contains business logic validation or calculation related to the data ok now this one is that your presentation layer ok we have to use this one am I'm going to make a default so right click and set as a default mean to me that say it as a start of this okay now first I'm going to start with going to create the database so open that your escrow server and right click we have the new database that is a new database this one I am going to test user DB just click on OK now I'm going to create one table first I'm going to add one one table so we can understand what actually is three layer architecture is working so here I am going to add user ID making dessert so it will be the user name 150 only so user address this one also you can make that 50 okay user email this one also you may get your trick okay and one more I'm going to add that is a moment before you can direct a user nobody this now going to clear that River so users and that I need to column will be the user ID now then say that table has been created with that users right-click and refresh open the table you can see that this one is then you search that sister now open the visual studio first I am going to create that object so here I am going to add the one class going to give the name this one will give the user business object move it click on add Here I am going to add some properties first one is that your user ID okay then your user name then user address user address after that user email and then last one is that user phone user that's one now next one is that to add that data access layer in the data access layer just delete this default class and add that entity model so add new item data select that we did dr. data to data model and we'll give that user DV model user click on add then click on next now the select the database that is your user DB click on ok next year sensitive next next and select that tables click on this now you can see that this entity from murdered idioms file has been added click on OK one more object need to add here that is going to power that is a custom message or custom custom that is a B you hear me to add two things first one is that long so integer that is a custom this is numbers our custom number second one is that custom message juster messes and here this one makers a plan public this one is also eager to show you that one just imbued that to class has been added next one this objects need to add the difference in the data access layer so as the reference of retract access layer had add a reference just go to their to your projects and he have need to add that your business object click on ok so doctor in the data access layer also in the business logic also need them at that that preference that is a business object ok that was header so I'm going to create one class files in that at Isis layer add that class so here it will be the user dl ok that one is a data access layer so what we'll do make this one is a public going to create the constructor okay so what's the entities that is your user DB entities new the user DB entities give the variable of user DB entities and now I'm going to create the object of a user DB entities okay that's one next one I am going to add that it will result the custom be who cooking custom beer which I have added this one this in the business object he in the business which would kind of added that one class that is a bo it will return and add and users that so then the tired user here I am going to pass that is a user do so just like all the user B who is no subject okay so what's the name of that table that particular model that is a user this one so create that object of reuse add people and new the choosers so this slice that variable first one is the user address so this will become this start use an address the next one will be that email so this one also have to use the email the next one is that you buy that you sell mobile your phone the next one is that username because user ID is the auto number so it will be the username that's up now in that entities need to add dot users dot and that is object user okay now simple dot Save Changes so that changes here I'm going to keep it one variable that is again great value if the return value is greater than zero then your custom message it will be then get that object a skull commune stone masses so it will be assigned dot custom assets equal to data successfully when H 1 is that number not easy just a massive number and to give you two a return value okay as it will be seen that I'm going to copy this one are they some problem there is some to add users that simple and now I'm going to return that returned with this object that's all ok that is a simple now I need to add into business logic that I'm going to call that your data Excel layer layer into that your business logic so add the reference add reference and select the data access layer click on OK now here also need to create one class that is going to get the name that is user DN business logic ok now as here also need to make that one public and leave that one method same method and good to call same one see okay so here it will be simple return that your business logic this be a DL import dot otherwise if you want you can create the new business logic dot your add user or simple this one need to pass this reminder single line so it will be that return now this one this user BL I'm going to call into your presentation layer that is your MVC application here also need to add the reference here also need to add a to reference that is a business logic and your business object not that access layer click on OK look at that too is that now I'm going to add a controller add controller so simple and here and and controller select the embassy empty controller and now Kootenay home controller I can see the home controller has been added I am going to add the view right click add view click on add you can see that here view has been added okay now open that now view has been added so now here first need to return to return that one that you object to be a custom view object so I'm going to create one more action result okay this excel result it will with that also than index but it will come that custom view so this one home controller this at the reference obj your custom video that one also we are going to return that now one sir that I will get that information that custom bo object so I have to add it so I have to call that one your business logic so user meal go to the hall here you shall be here we have the object of ops so BL alpha new user BL and user BL dot add user it will be that just need to pass so this one is the user bu which will be the business object so this will need to pass here okay this one it will return and what it will be written it will written that object so what is that your object is that custom this one so create the object of a custom here so till here really change now add into view just call this usual view into that individual CSS tml took all that model that uses view that import that is them so now use the using statement so HTML dot begin form so index controller then form method is that post so inside that need to add some value so do give it with the class equal to container container the next will be the div class this one with the row okay then again then Dave this one will be the class that you form okay so here is TM l dot label for model model dot first one is the username okay the new Steven attributes that is your class staffing level control even that one do I need to add one text box just copy this one and paste it here instead of live call it will be the text box for our dead class this one with the form control now I'm going to add the rest of them I am at address up there just like user name the user address user email and diesel phone same language now I'm going to add the button so Dave this one also it will be the class row same form yeah inside that I'm going to have the button so this move input' type submit' then when you save name save and class to button button bass that is a bootstrap primary like simple now run the application let's see one more T need to be changed here that is here which will make that HTTP POST otherwise you will get that ambiguity error now after run the application and I can see that their design has been today so next one - teens what we will do we will do that call that your object so this one this - this one is a these two is their business logic and business object this one is the business logic layer okay so here in the business logic layer what we can do here that one because we know that when a business logic layer or business access layer contains business logic where Edison or calculation related to that data so what we'll do here validation in the business object I will do that very soon so how will you do that validation here open the solution Explorer first you need to add the reference that is a your system dot component model dot determines for this one I have the reference here and once you are at the reference call that here using system dot component model dot data notation so here if you will give the name first I am going to give the name there like a display that will be the name username same like other I'm producing them this one is a user address then user email and the user phone okay that phone okay next one is that you are required so it will the required that error message will be the user name is required same for other addresses reply email Foom the next hear that one more things that is email address where this one here that I reverse her please inter valid email address very demon address okay this this this things previously what we are doing we are doing in a that embassy project now there are things that validation part we are doing in here your business logic layer in the business logic okay no up in the index of CSS HTML so he need to have that your have that is a very decent message for that it will the model model dot username next when you with the null there are new human attributes so that class will be your turn changes the text Ranger I'm going to add further then can see that user address is that email and is a phone is at now open the home controller here I'm going to write if model dot smarter straight what is valid then this one's manatee stood bar otherwise else else is not required just the reference save it now after the end application now you can take that that your first your label name has been changed because of your data annotation that is change okay now I'm going to click on save you can see that username is required user address is required to use an email is required and user kun is required that all things is required that things we are doing in your business logic layer in the business okay now first I'm going to add just like I am going to have that taken user name is that using address is mango I am going to add that your address now need to have the phone number this cell phone number now I feel free maybe you'll get that error see you are getting that one error here so what what's the error of saying let's go to the world there is saying that no connection string name user DB entities could not be found in the application dot config file means like that he's checking that connection string because once you are going to deploy it will check only in that app config in that your Embassy project that we're not going to check here it will check here so what we'll do just close the application and open that your data access layer go to the app config file okay and just copy that your connection is free just copy this connection string okay this connect sense thing we need to be aged into that web.config of MVC project open the here now if you will rather into here just paste it here 30 your connection string okay now I will run the application and again now enter some data like I take this in Banglore militarist and for once you're going to click on save you will get that one hair ever again here so you are getting that error into your data access layer okay this one data access layer you are getting the error while you are trying to save so just close you need to install that entity framework because there is no entity framework so just go to the data access layer the - nougat package otherwise just mr. strong that one good over here managed to get a package manager based is this fear and select the entity framework okay this will need to install click on I accept now if you look that one first that entity framework has been added into data access layer okay so next one I have installed entity framework into that your MVC project so because once yeah we're going to host that one are so going to be done it will take this wave config file so in the wave config file I have pasted that the connection string that is here that user DB entities that is a connection strings okay so now everything is has been done now if you'll run the application just this actually is not required we direct waxen so that's danger index knife doing the application open the ESCO server here you'll check that if that is a no data now I will check into that web browser I will try to add that data here I click on save let's see now open that door sir let's go so here you can see there that I has press save now if you'll again if you'll try to add take you sent to successfully okay now what I have done just close a have created first one I have that created a blank project that is a three layer application in there plaid brand for Josiah abide that business logic business object rataxes this three class library we have added and then next last one is that you present a seller that is you and the see one is that here business logic then he written here that logic here first we will start with the data access layer here we have added that you're in today framework then the user DL in the user dear simples passing that this one is user object this user object user be go that we have created in the business object here this one and here that in the business object also that we have added that valid SNL's okay because in the business / chief we can do the calculation and validation that all things will be done in a business logic here okay so this one we have added that which in the business object we have added relation also if you open that to your data access layer here that I'm passing that your object at model and that trying to save that this data here I am saving the data if you'll return greater than zero it will return the decided message if you will equal to zero then it will return that this error message that is the error message because once it will be safe it will be a greater than zero MD okay that is done now if you look up in that your business object or we just layer so only I am calling that one business access your data access layer in there to you built in the business logic layer and crawling that only data access layer and same things we have called into I have created that controller that is a home controller as same thing I am assigning that value that is a user bo that it's coming from the rear view in the index view in the interest viewer you are getting that one that is user Bo and that value I am passing through that your business logic layer see the business slowing that add user that I am passing the federal value now it's saving two things we have to do that one first one that once you added that entity remember in the data access layer same things you need to copy that connection into that wave config also here also need to okay see if you are doing that that particular layer if you work with a layer in there in the future if someone asked to work as a Oracle because now I am using that here as core server but if your client will ask to work in a Oracle database you have to use that Oracle database so only you need to change the data access layer rest of the things is seen it will be the same only you need to change the data access layer because that are your connection all those things will be happen in a data access layer so only you need to replace that this data access layer and it will work perfectly okay so that's where we are using that one that layer architectures if you work with her so if you look at the business layer is the vital in that a validates the input condition before calling a method from the data layer this ensures the data input is correct before proceedings and can often ensure that the outputs are correct as well meaning the advantage is that a residual course so you can be your port will will use I hope it's a clear thanks for watching
Info
Channel: Tek Tuition
Views: 46,509
Rating: undefined out of 5
Keywords: 3-Layer Architecture in ASP.NET MVC, 3 tier architecture in asp.net mvc 4 tutorial, 3 tier architecture in asp.net mvc with entity framework example, asp.net mvc web app on 3 tier architecture source code, 3 tier architecture in mvc 5 example, 3 tier architecture in asp.net with entity framework example, 3-tier architecture in c# windows application, 3 tier architecture entity framework in mvc using code first, Tek Tuition, 3 Layer, 3 Tier
Id: Hqj8Xxebf9Y
Channel Id: undefined
Length: 34min 19sec (2059 seconds)
Published: Thu Oct 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.