E33: Be a Superhero on Day 1 with ABP Framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey do you want to be a superhero on yournextasp.net project of course you do stay tuned to find out [Music] how hey everybody and welcome to another episode of code hour this is episode 33 and actually it's a little bit less of an episode and more of a presentation it's going to be 60 minutes instead of my traditional 30 but it's totally going to be worth it i hope you'll stick with me because this is going to be on abp.io if you're a regular subscriber of my channel you'll know i do a lot on asp.net boilerplate and abp.io is the next version of asp.net boilerplate so let's get into what is it first of all similar to asp.net boilerplate it is a one-time code generator that generates a net core back end and of one of three different front ends either angular asp.nvc or blazer so already you can see some differences by the way this is going to be for an audience that does not necessarily know what asp.net boilerplate is but if you do and you know a lot about it then i'm going to be drawing a lot of comparisons so hopefully i can address both audiences if you've never heard of it or if you are familiar with the v1 so the second thing it is is a framework so it pulls down code from npm and nuget and one difference here is that abp.io is a little bit heavier on the framework and a little bit lighter on the one-time code generation and the consequence to that the benefit really is that as an abp.io user you're going to more easily be able to get new fresh content bug fixes and features as they ship them out what's it for it is four new projects and not existing projects if you have an existing project just stick with what you've got uh and what does it give you gives you three main things it gives you an end-to-end 100 working site right off the bat it's a huge benefit because you can get up to speed fast you can be a superhero on day one it also gives you a whole bunch of foundational features that's going to be the core of this presentation and what those are and it gives you a whole bunch of best practices so let's before i get into the foundational features let's talk about the history of it it was originally as i mentioned asp.net boilerplate if you're familiar with the terms in asp.net boilerplate there was the asp.net boilerplate which was the free and open source version and then there was the asp.net 0 which was the paid version that allowed them to make money so the uh they being volosoft is the name of their company that that provides this now the new terms are the abp framework is the free and open source version of it that you can start your project on or if you want more features then you can use the abp commercial and support and taken together those two things are abp.io so why did we need a whole new version of asp.net boilerplate what was wrong with the old one well the answer is that the original one was written in 2013 seven years ago or by the time you're watching this eight years ago it's probably 2021 and that was written even before angular 2 was a thing so this got some it's got some technology history to it and and from a maturity perspective that's a benefit but it also has some disadvantages and one of the if you watch my episode 19 you'll know that i complained a little bit about the dependency injection technology that they use and so when abp.io came out in 2019 that was based on.net core came out with net core 3 and so rather than using an any old di framework they were able to use what was built in with net core so got some advantages there a while ago i asked halil ibrahim calkin who is the lead developer on asp.net boilerplate i said hey um what is the lifespan of abp asp.net boilerplate is there an upgrade path to abp.io and he said hey we're going to create a migration guide which they have done and he said there's no end-of-life plan for asp.net airplay yet that's still true today so you could still choose either one that you wanted to do and that migration guide i have a link to it i don't know here or maybe here and that migration guide is going to be a it's a good starting point i haven't actually done it so i can't guarantee that it's going to be easy to do in fact it looks a little time consuming if you're planning on upgrading give it some time i think so it's still open source that's fantastic news here is their github page as of today 4.9 000 stars after already having been around for a year that's pretty good by comparison the asp.net boilerplate older version had 9 000 stars so if you're considering whether i should start my next project based on this sketchy technology it's it's mature it's been around a long time it's based on something that's even more mature and been around even longer so that's good to know by the way it's been a boilerplate has over 1 million downloads on nougat so it's a popular framework let's talk abp commercial real quick and i think it's important to talk about this from two perspectives if you even if you plan on using the free version it's worth knowing what you are not getting if you choose not to go commercial and it's also worth remembering that if you have the ability to pay for it you can help support this technology and even if you don't there are other people that are supporting it this company bolosoft is making money and so you know they're going to be around for a while and that's really important so some of the features that you do not get with the pro version include these fancy themes so they have ui themes asp.net blog play just had one theme you got to choose from but there's multiple ui themes the abp suite gives you the ability to to do crud generation from front end to back end with just a couple clicks at least that's what it looks like i haven't tried it out yet it looks pretty awesome okay so we talked about themes and the abp suite and support of course as you would expect and then the last thing is modules and so modules cover is a big swath of things because modules are an a concept that is introduced by abp not a new concept but it's a concept that they allow you to bring in bits of functionality and there's a lot of different modules in abp.io and you get additional ones and beefed up ones when you pay so the uh here's here's just digging through their website a little bit there is you get identity server integration even if you're doing the free version but you get like a fancy ui if you're doing the the paid one there's twilio sms integration stuff like that you can all code all this stuff yourself but it just will be a helpful accelerator if you go for the paid version digging into some of these a little bit that say basic and pro the account management i think is interesting so you still get login registration multi-tenancy i'll talk about all these later the user lockout these are all great features forget passwords social audience what you get extra on top of that is you've got two-factor authentication email confirmation email verification ldap integration so that's all good now let us dig into the benefits now hopefully i'm going to convince you in this section that it's worth sticking around for the rest of the 60 minute presentation so i'm organizing the benefits by day one week one and month one what you can expect and how it will benefit you to choose this framework so first of all this is the site that you get right on day one immediately you get identity management you can create edit update delete users roles and permissions that are associated with them and multi-tenancy multi-tenancy is huge i did a whole episode on multi-tenancy i think it was like episode 21. check that out but the multi-tenancy is very similar so if you watched that other episode it was based on asp.net boilerplate but it will be very very similar for avp.io so this is what you're going to get right out of the day one and you can come back to your boss and say boss check this out i got this working i got this edit functionality and already login and the ability to to do all that that's going to be fantastic and then by the end of the first week you might have your first entity and the ability to view edit update products already pretty quickly and your boss will say well done that is very impressive and you could say well i'm standing on the shoulders of giants i've got this fantastic technology that i'm using or yeah it could be just take all that glory for yourself right why not so the beak one benefits are you get all these foundational features you get the pre-implemented best practices i didn't mention domain-driven design but it is all everything in avp.io is based on domain driven design and that those concepts are beefed up a lot more so than they were in aesp.net boilerplate and the documentation is really very very good and so that gives you the ability to get up to speed quickly on their framework and they're always focusing on getting the documentation good and that's really a huge benefit so at the end of the first month hopefully you've got a site i would hope this was a site that i built i don't know if it took a month maybe it took a couple months but this is one that i actually built based on asp.net boilerplate but this is something that you might be able to generate and that would be fantastic it's based on an enterprise grade architecture so this isn't just your like quick and dirty ruby on rails project this is something which is going to be a platform something you can build on over time something that's going to be able to last enterprise grade and i talked about documentation before but it's also really useful from a more longer term perspective because if you have new developers that join onto your project then they can get up to speed faster as well because of that documentation and if you have multiple abp.io or asp.net boilerplate projects within your organization or if your consulting company which is who pays my my bills uh from a day-to-day basis then and and they have multiple asp.net projects then the then you have the ability for developers to move in and out once they're up to speed on avp.o they can move in and out of multiple different projects because they're all going to be similar even though you can customize them so that's cool that's enterprise consistency and it's another benefit of that documentation that you're liable to see further down the road all right this is the fun stuff let's get into the foundational features so i've organized this into four different areas the front end the back end deployment and testing it's a little bit hard to talk about the front end because there are three different front ends there's angular asp.net mvc and blazer and if you saw the last presentation that i did last code error that i did i did a angular versus blazer so hopefully you're already prepped up to to make that decision between the two actually since i recorded that blazer 5 was released and it fixes a whole bunch of things that i complained about blazer i think blazer is probably pretty uh pretty good choice for a new project today but i have a lot of angular experience and so i'm gonna focus a little more heavily on angular in this presentation but those are the three different benefits i'm going to talk about a little bit about what you get with them generically so for instance tag helpers this is something that applies more to sp mvc asp.net core mvc but there's also something similar in the angular world and probably in the blazer world and so what you can do is uh over here you have you can do like an abp dash input that tag helper then gets translated based on the model it looks over here at the model and sees okay i've got a required password for instance and it knows without you saying the data type or the description or whether the validation it knows to automatically populate it like this and that's really nice it knows if you have a bool to automatically generate as a checkbox and if you have dynamic forms if you use this abp dynamic forms it just generates all of those for everything so that's a nice helper and if you don't end up liking it you can get rid of it and swap it in with custom code so that's an example the data table is really nice here's the angular data table this is new but it gives you filtering sorting and pagination right out of the box there is a bunch of miscellaneous things too there is pop modal pop-ups that you can customize and there's a toaster that they have built in that's attractive and works nicely very cool localization works front end to backhand here's how it looks on well here's how it looks on on the back end so the way localization works you have now slightly different in abp.io but you have a bunch of json files and each one is for a language and then inside of those you put in basically a dictionary name value pair and then in your front end you just pipe it in angular anyway over to abp localization and then you can even parameterize it so check out this are you sure you want to delete you know the starship pro edition or something like that and that product name gets plunked into there so that's nice let's talk security this is a little bit complicated takes a little bit of getting used to but it's super powerful and wonderful and it's a huge huge benefit of adp.io when you actually this is a little bit different check this out what is funny about this if this is the home page that you go to and you click the login button and you go over here do you notice anything funny there's urls there's url so 4200 is what angular serves up and 44 360 is what the back-end asp.course serves up which is traditionally typically most of it is an api this is not an api this is a page and the reason that they did that is it's part of oauth 2 it has better identity server support and supports the proof key for code exchange pkce protocol and one of the benefits is that if you generate the mobile site and i mean covered that but you can generate a mobile application in react as part of avp.io2 which is really cool but if you've got a mobile site and you've got the web front end and maybe you have different front ends they can all go to the same place for login that provides tokens and then that is what everybody uses one central place as far as routing and authentication this is a slight difference the way they did it in abp.io the the routing table is done by modules and so the module goes and looks over at the product routing module and then there is from a security perspective there's an auth guard and a permission guard if you toss in the auth guard it'll automatically only allow access to that route if someone is logged in and if you put the permission guard then you can put a required policy and someone can only log in if they have this permission and i will get into what permissions are a little bit later talked about multi-tenancy a little bit just to give you a sense of what that looks like this is the ability to switch switch tenants and if you're not familiar with the term multi-tenancy imagine you have a bookstore and you're you're selling books and then you realize that if you're don't want to just be a single bookstore maybe you have a whole bunch of bookstores and each one of them has their own set of books and you want each one of them to have a sort of a slice of your site a version of your site where they sell their own books they manage their own users they manage their own everything and then that's a that's a really good example of having multiple tenants that are all using your site and that each one of them's view of the data is different so it's a hard it can be a hard problem to solve an abp.io kills it makes it so much easier if you're using multi-tenancy if you have a need for multi-tenants on your project seriously consider abp.org to make your life so much easier and this is how it works you can inherit from my multi-tenant and then you get a tenant id and it automatically manages only showing data for the currently logged in tenant if if you don't need it there's a go into the multi-tenancy consts and turn is disabled to false okay auto generated service proxies i love this feature especially for angular it's wonderful so it comes with swashbuckle by default which is a if you're not familiar with swashbuckle it's a product it's a open source technology that is part of the net framework actually so you know it's supported it actually comes out of the box i believe with asp.net core but it's all hooked up with avp.io to give you a swagger site which is documentation for your apis love it it's wonderful but abp doesn't stop there they give you the ability to generate all of the all of the objects all of the strongly typed objects into typescript so you get all that nice intellisense and then in addition that proxy also gives you the ability to call into your back end with for typing virtually any code no code the way you do it by the way is with a net tool called volo abp cli and that tool i'll be using it when i show demo this in a little bit but that tool is going to allow you to generate the proxy in addition to generating the site and this is what the code looks like at least from an angular perspective you can do this dot product service dot get you can pass in whatever it needs and dot subscribe and all that code that's all you need to type all the code to make that work is pre-implemented for you to call into the backend wonderful wonderful feature saves a ton of time all right um i don't know is it well i don't know if it's time maybe it's just demo is it time to demo i think it's time to do a demo let's do it so if i were to start this right now i'm going to go to abp.io and get started and when you do that they give you two different ways of doing it you can do it with a cli which is the way i'm going to do it now or you can get a direct download and the direct download is kind of cool you can just say this is lee's store sure store three and then i want this to be an application i want to do based on angular and oh i didn't even mention this but there's support as well that's another big benefit of abp.io if you don't really want to use a traditional database with relationships between them is an option that's cool and oh and yeah there there's that mobile component you can generate a react native mobile app you might be missing by the way from asp.net boilerplate other ui frameworks they no longer have the react there but i believe they're working on that i don't currently have the react and they don't currently have the view all right and so you could just create now and you could download it or you could do it using the clr so that's what i'm going to do when you do run this you do need to run it as windows powershell as admin or if you're on a mac of course this all works on a mac too and if i type that right now i think it's not going to work oh well it's already installed but if i uninstall it yeah i get this error it turns out that between the last time i ran through this presentation and now volasoft has released the version that is compatible with 5. so that's fantastic and uh we're running some fresh bits here and i went install done f5 so let's go and run the dot net tool install again with dyno 5 installed awesome we've got 4.0.0 all right and with that installed now the next trick is to run abp new and with minus minus help and see some examples of what the options are all right so we're gonna do dot net new we'll call it lee's store three and front end is gonna be angular we do not need the react native mobile client although that would be cool we want a database we don't need so the default is entity framework ef and that's just fine we'll leave that as the default the last thing is it's kind of convenient to do to specify the connection string their default connection string is goes through an instance and i don't have an instance there we go we got an angular spin core let's open the visual studio up and take a look at that project and i'm going to just do a quick walk walkthrough of all of the code that is provided in the back end and meanwhile i'm going to open up the front end and start downloading the internet oh and they used yarn rather than npm for this for abp and so you can just do yarn and it will download the internet for you that's going to take a long time so while we're waiting for that we'll switch back over to visual studio and i'm going to go over the solution so the thing you care most about probably because it's the front-end thing so the thing to look at first anyway is the app http api host and that project is the traditional asp.core mvc project and that's the thing that you want to be your startup project so in general when you're ready to start a new project you can right click on that and and then hit the a button and it'll set a startup project you can hit f5 in a run however you don't have a database yet and so we need to create a database i'm going to switch over to sql server i've got sql server installed here and i'm going to create a new database called leads store three and as expected there are no database tables in there we need to get some database tables in there and to do that we run the db migrator so that's the other project that's important inside of the abp.io set of projects now if you're looking at this from the asp.net boilerplate perspective you're thinking gosh there's a lot of projects there a lot more than there used to be so let me just go over them real quick there is an http api which is equivalent to the one that used to be called http api.cor and that is where if you need controllers if you want to write controllers which might be useful if you're doing file upload or file download then http api is the place to put those this is new http api.client is the ability to define an external facing api either for separate customers that are not your web application or for maybe if you have a command line tool that needs to have get access to it or a desktop app or your web app you know some some other mobile apps some other thing and actually i did a whole episode on this at some point and uh two episodes and in those episodes i show how to do that in asp.net boilerplate it is completely changed in avp.io they're built into the framework so you don't need two episodes of code hour to figure out how to do that i'll probably do one in the future if you're interested write in the comments if you like that well let's talk about the migration so the migrator is a really useful project for running your migrations now you could just do it from the command line you could go into the package manager console and write and run update database and that's fine it'll run your migrations and it'll do just do just fine with it you'll need to make sure to change the default project to db migrations if you were to do update database however i would encourage you to use the db migrator two reasons for that one the db migrator will if you have if you're doing multi-tenancy watch my episode on multi-tenancy and there is an option there to have one database per tenant that is supported with the db migrator and if you have multiple database that is that is not supported with the update database command it's one reason you should probably use the dbmi greater the other is and this is cool there's a new feature in abp.io for seeding your data from inside of c sharp normally if you want to seed data you have to do that inside of a migration with insert commands but the db migrator and i'm not going to show as part of this presentation but it's a thing that you can do it's actually in the startup sample if you go through abp.io and you go through their sample project then that is they show you how to do that there so i'm going to run the db migrator let's just talk about some of these other projects the application here the application is where you define your app services so these are like controllers and traditional asp.net mvc but but but instead they give you additional functionality and johnny and it's part of the domain driven design architecture so that's the application the contracts is where you would put all of your interfaces the domain is where you put all of your entities the domain.shared is where you put enums things like enums also i believe that is where the localization is so localization goes that's where all of those json files i showed earlier are located the entity framework core is where your data context lives if you're using entity framework there's the data context and then the data migrations have been separated out and now they live in the db migrations project so those are all of the projects now let's see did that run good news that ran successfully or so it says so it claims let's find out for sure we're gonna zip on over to lead store three and refresh the tables and hopefully we see a whole bunch of there we go a bunch of abp tables that's good that will help us enormously when we try to run this thing set the host as the startup project let's see if the front end has completed downloading the internet yes it has your current version of yarn's out of date but i don't think that's a big problem so next if you follow their documentation they tell you to do yarn serve or something like that but it's the same thing as doing ng serve if you've installed angular at the minus g at the global level okay there we go that took a while that i don't know why that took so long uh but it says it's running on localhost 4200 so let's see if the front end is working that's a good sign we see a lease store 3 up there in the title an error has occurred hdb failed to get to 44 392. and i think that's because i started i failed to run the back end so i set that as the startup project and let's just check the app settings.json hopefully this contains the same database that uh i specified at the command line yep that's good that's a good sign and by the way when i ran the db migrate i forgot to mention this but inside of the it has its own app settings json that's where it looks to run the database migrations into that database control f5 to start without debugging because it's a little faster that way hey there we are there is the swagger file and i could go and try to ask it for you know give me a list of roles for instance i probably would expect this to fail with an unauthenticated response yeah 401 unauthenticated well let's check back with our angular front end and see if that's working now excellent at least our three is successfully running let's log in and here's the login page and i can get a admin and password account from there it is one q two three one whatever okay and we're logged in so you can tell we're logged in because now we can go up to this administration tab that showed up we can get in take a look at the users the roles the tenants you can see for instance that there's an admin account we create a new one called the smith so that's how that works and that is roughly what a uh site looks like right out of the box okay we're back that was the demo so let's talk about some back-end features i haven't gotten into this in detail yet but there's a app service which is associated with each entity that you would want to expose crud for or other things maybe you would increment quantity or decrement quantity or make sale method and you would put that onto generally onto an app service it's like a controller but it has more functionality and so this is an example of one such thing and let's just take a look at it a bit by bit first of all the products app service here in this example inherits from crud app service you can just inherit from app service if you want and that will give you virtually nothing just in this example but increment quantity but if you inherit from credit service then you get create read update and delete methods without any coding at all fully implemented that's that's great that's a lot of functionality saved you also get dependency injection for free already set up and it uses convention based determining of what the teams inherit from so this is just asking for an i repository which is talking about the repository pattern which is a great way of accessing the database in a unit testable and independent modular way so it's a great pattern and the dependency injection by the way if you were to define something called a products i products app service and a products app service and you ask for the i products app service it will know it will use convention to figure out the products app service the authorization here is declarative and i'm going to get into again i've touched on security a little bit i'm going to dig into it a lot more in just a second but you get to put at a high level i would like and nobody can get into this method unless they have in this case the view edit products permission you can define whatever permissions you want validation happens automatically that's really nice if you take a parameter that's a product dto data transfer object it'll automatically validate it before it even gets into your app service there is audit logging which you can turn on and so that type of logging says anytime a method call happens it'll save it into the database so you know it could be useful from security perspective logging awesome setup for log for net by default which is just great it's one more thing you don't need to set up when you're starting a brand new project it uses unit of work transactions units work pattern transactions and connection management automatically so it you don't need to worry about any of that if you throw an exception in the middle of this increment quantity for example it'll automatically anything that's happened up until that point it'll automatically roll it all back and it won't it'll be like it's never even happened so that's that's it's great stuff you're getting right out of the box i talked about exceptions a little bit you can also throw these user-friendly exceptions and these are cool a user-friendly exception well normally when an exception happens it'll return a http 401 or 40. i don't know it'll return a maybe a 400 response back to the server and it'll pop up a real pretty nice modal dialogue to the user that just says a generic message because you don't want to expose any of the internal details of your application to the user but if you throw a user-friendly exception whatever the text of the string is there will get popped up to the user it's just a nice convenience functionality and localization supported as well you just pass in l and say which key you want it'll automatically pick up the value and determine which language it should be based on the user's connection users http headers and such it has object mapping it uses it uses auto mapper by default and there we go that's kind of a real quick overview of all the back-end features but there's so much more let's dig in more detail into permissions so there are there's multi-tenancy which is built in throughout and then there's users that concept of a user obviously straightforward there's uh that bob smith account that i created earlier for instance there are roles so you could create a supervisor role that's right out of the box and you can associate the two so you can say b smith is a supervisor or b smith is a supervisor and a something else and then there's these permission things so permissions you create those yourself inside of the least or whatever permission definition provider and so here's some code sample that's creating a new permission called view edit products and it uses localization to get a nice descriptive name which you'll use in the ui and then the final parameter is whether you want it to be just for the host just for the tenant or for both toast and tenant you can then decorate as i showed earlier you can decorate your classes or your methods actually you can decorate controllers too with an authorized attribute and pass in as a parameter that permission that you just defined and that locks that down to only allow people within that permission but how does abp know which user which permission the user has that is tied between the role and the permission so when you go in and edit a role you can after you've defined some permissions you can say which the user can say which permissions the user has so this is that view edit products permission that we added now showing up in the ui i hope that makes sense you have to fiddle with it for a little bit before you get a feeling for it but it's really powerful it's really wonderful i love the permission management the way they did that i talked a little bit about validation but just to get into a little bit more detail if you have a create product dto or something which is exposed back to the user then you can use annotations built into.net you can use required length range there's a whole there's a regex there's a whole bunch of those and when it's going into an app service abp.io will validate that dto and if it doesn't look good it'll return a nice validation message back to the front end here's custom validators an example of custom validation if you inherit from eye validatable object so that's really nice to do more complicated validation than you can do just in your regular angular whatever front end so there's auditing this is a wonderful fantastic feature if you inherit from audited aggregate route or full auto diagon route or there's a couple other variations then you will get a creation time creator id last modification time last modifier id and potentially if you do full auto dagger group which i'll show in just a second then you also get it deleted by deletion is deleted and abp.io will automatically fill in all of those values when you create something for the first time it'll fill in the created when you modify something it'll fill in modified time but it also because it already has the context of the security can figure out who it was that did it so he can automatically fill in for you the creator id or the last modifier id or the deleted id who took the action and that's wonderful as far as deletion goes the deletion side of that story if you inherit from full auto dagger root or i softly then you get these is deleted field and then when someone goes into the ui and they delete something you delete it just like you would normally in code but instead of hard deleting it it just fills in the is deleted into the database so it is deleted becomes one in this case and whenever you pull data back out there's a filter and abp will automatically exclude anything which has been self-deleted which is really cool feature if you still want to be able to get the soft deleted things you can turn off that filter with like this data filter.disable i soft delete and that will allow you to pull back things that have been soft deleted that's auditing that's a great feature as far as logging goes this is a really important gotcha if you're using abp and that is because when you're running the site the user never sees the details of what the error message is what the exception is it's best practice right it's a good thing to do but how do you find out what the actual error was the answer is that all errors automatically go into the logs which go through log4net and get stored in this location asp.net core whatever your application name is hb api host slash logs slash logs.txt so personally the way i work is i just keep a tail running on that all the time because i'm always just keeping an eye on it and i use a tool called bear tail to do the tail but you could use powershell you could use visual studio code whatever you want and i just like this tool because it also does color coding and things like that and one thing that's new about abp.io is it's also logging in this example uh sorry for the fuzziness it's also logging all of the queries that are being executed and that's great for keeping an eye on performance nice update there and there's a whole bunch of other miscellaneous things that are really cool so it has signalr built in it can do background jobs that are like long-running tasks which web applications are typically not very good they're not designed for but there's a facility in.net and abp exposes it makes it even easier to use there's an event bus which you can use and turn on the module it's uh uses rabbitmq under the covers but you can change which message queueing technology you want that's pluggable i mentioned data seeding i'd love to give an example but there's not enough time modules so modules are a great feature for pulling in different bits of functionality and you can define your own modules back in c sharp so it's a really sweet sweet way of organizing code and you can tie into the startup and shut down lifecycle of the modules it's got email it's got text templating it's got this whole virtual file system so if you have an image or something that you want to expose back out to the front end you can plug that into the virtual file system and it'll treat it just as if even though it's an embedded resource it'll treat it as if it's available for the front end to pull it's a new feature in abp dot io that's really cool so that's the meat of it that's the important stuff we've talked about the front end the back end from a deployment perspective there are a there's a whole new micro services project demo project that you can take a look at and they've shown you how you can hook it up with kubernetes which is what i'm doing on my actual project with asp.net boilerplate and docker and identities are hooking up a redis cache and pulling and sending this how it's actually going to potentially look in production with a big sophisticated micro services architecture that's really cool one thing they don't do unlike asp.net boilerplate there's no doctor files built in you have to either steal those from the demo site or build them yourself and i when i when i did my microservices site based on asp.net boilerplate i had to do everything from scratch anyway because i was very accustomed to what my customer needed i mentioned the migrator but i think i just want to talk about it just a second more one other thing that's really nice about the migrator is that project that command line project can be compiled and if you've got that in a ci cd server you can use let's say you're using azure devops you could have a multi-phase pipeline you can have phase one of it compiling that migrator and storing it as an asset and then phase two which runs in your dev environment then you can run that migration and then let's say a week later you validated it and someone runs in the test environment then they run that exact migrator and it runs just those migrations in the test environment and then you can do the same thing in your pre-prod and your prod do that for each of your environments and doing it that way is really powerful it's really nice because it allows you to say okay my ci cd server can have admin credentials into the database but the application that's running only has the ability to read and write data to specific tables but can't delete database tables so that's a really nice best practice i love the migrator project so it's just a little bit about deployment as far as testing goes they have integration testing built in and i i call it integration testing they call it unit testing but it is it's a bunch of tests in c sharp that will spin up a database and then make it really easy to call into a class and have all of its dependencies automatically populated such that you can call in it'll call other things and it'll call into the database into your in-memory database and you can simulate actual queries and run those queries and so i call that an integration test because it's sort of it's not just testing a really narrow slice of functionality but it's wonderful it's a little bit slow so i wouldn't plan on doing all of your tests this way but it's wonderful for getting queries if you have complex queries and you really want integration-style testing it's absolutely fantastic it's based on so so when i do projects i usually have a set of tests just like they provide and then i have a sibling project which is pure unit tests which uses mocking exclusively and would never actually hit the database so it uses x unit it has this in memory database i mentioned it uses and substitute i've used moke in previous projects or mock or harry potter and substitutes just fine just a different syntax and uh should lee if you're not familiar with should we should be awesome instead of saying except assert dot r equal and then you pass in a parameter and it has another parameter it's much more reads like a sentence exception dot message dot should be and then you pass in a string that's really nice i love should we love it i threw that in there by default so that's a fairly good look at all of the foundational features that you get with abp.io i'm going to talk a little bit about how to do things and i'd like to actually demo it so i'm going to start with how to end a back end how to add backend crud the process here is to add the entity add it to the database context i'll show you about the db context model creating extensions which is a new thing that's required in abp.io and i'm going to give you a little bit of code if you want which you can short circuit a lot of boilerplate that is sort of necessary and then you have to add the migration you can then run the my greater project add your app service add your dtos register permissions run the app see the swagger and rejoice and that sounds like a lot but it's not that bad i'm going to demo it now really quick and this is applicable to everybody and i'm just going to talk through briefly the front end part of it because angular is not necessarily applicable to all of my audience it's only applicable to a third let's do this i'm going to make a product so i'm going to go into entities here we go inheriting from the full audited aggregate route as i mentioned earlier and one of the parameters for that is what data type it is if i were real data driven design and by the way there's a really good pluralsight course by deborah carotta on domain driven design and they they talk about the importance of doing a good and you can do it that way if you want the benefit there is that in your front end you could create it independently without sending it to the database and you could modify it and make changes to it and then once you're happy with it then send it into the database and you can know that the id is not going to change i don't need to do that for this so i'm just going to call it all right i mentioned this earlier but if you have enums the right place to put that is inside of shared all right we've done step one added the entity now we need to add it to the database context i'm going to jump over into the entity framework core you'll see i've got a lease store 3db context now i can create a new product there and check out this description here it says hey don't forget to map them inside of the lease store 3db context model creating extensions well all right you can do that sibling product right there and they give you an example of how to do it so i'm going to follow their guidelines first i'm going to show you a little shortcut if you like okay there we go so this is saying that we have a product and we would like its name to be product and we would like to configure a convention which picks up um basically the any annotations that you put on it but then you can also be a lot more specific you can say okay the name field is required and it has a max length of 100. and that's the way they recommend you do it and that's fine you could do it that way however i liked the way they did it in asp.net boilerplate i like the reflection based way of doing it and so i figured out how to do that and if you want i'll show this code it's in github there you go this code is another way of doing it and this just will auto go through all of the properties inside of your database context that inherit from db set except for users and then it's going to loop through them all and call.2bable and configure by convention by doing it that way then you can just put all of your annotations directly on your product so okay so now we ought to be able to just add a migration so you go into package manager console window if you're missing that you can get that in from view windows and then make sure to change the default project to db migrations that's important things will go wrong if you don't specify that and then you add migration let's take a look over our migration make sure it looks good we're trying to add an app product by the way that app prefix that came from this new thing the db table prefix which you can change if you want to and you can also set a default schema it's an awesome new thing that's kind of nice i'm happy with that we're going to make an identity and all of these columns notice the is deleted we never explicitly added that that came and the last modified all that came from the full audited aggregate group looks good to me let's run it i'm going to run it with the dbmi grader all right it says it completed correctly let's just look over in the database real quick okay there it is cool all right and so we didn't add entity added to the database contacts added to db context model creating extensions we added our migration we chose not to seed the data we ran the migrator project or called update database and so that's great six is to add the app service so now we're going to expose that there we go credit app service it's going to have a whole bunch of generic foreign first of all what is this for it's for a product we'll call it a product dto and then end and the get list input is for pagination and filtering and sorting and we can do page sorted result request then for how to create a new one uh we could reuse the product dto but it's the best practice to do a create product dto a separate one talk about that just a second let's create these classes okay it's complaining now because product dto should inherit from i entity dto we'll do better one better than that entity dto and i think it needs a key so we'll call it hint go and last but not least wants a constructor with a repository we're almost done actually but let's talk about dtos real quick the purpose of these dtos is to not expose anything that we don't accidentally intend to from the entity from the database so we're only returning those fields that we strictly have to there's also a benefit that if you have a foreign table that doesn't no doesn't auto mapper doesn't go try to go down that rabbit hole of getting the the you know the products customer and the customers customer type and you know down this whole revenue of all these other things so we're just exposing only the fields that we strictly need to when we're returning data in the products ddo and when we're updating it and inserting it we're only allowing the front end to insert and update the values that we explicitly are allowing so if we had like an is admin field we wouldn't want to accidentally expose that that's just something that the back end owns exclusively so and it prevents a number of security vulnerabilities such as overposting product dto will look a lot like our product and the create one will look just like it except we're going to be able to put these annotations on it and the annotations will be used for validation so i'm going to take these and move them into the place that they should be i mentioned this previously but they should go into contracts all right i think we're about done here so we've added the app service we added the dtos oh permissions yeah let's do permissions so back here on the app service let's just do an abp authorize or just authorize and we need to create this permission it doesn't exist yet so we're going to have a correct product call it whatever we want just following their pattern these all are going to have a common group name list or three and uh product and then we need to register the permission definition provider register credit product its display name which will be used in the ui will be called the final parameter here is optional but i really would encourage you to always specify it especially if you're doing multi-tenancy because it's easy to get wrong and if you get it wrong it's kind of a pain to fix so we want this to be for the i don't know we're not really doing multi-tenancy so i'll do both but i think probably more typical if we had a bookstore and we had a multi-tenancy and we were selling multiple bookstores or or whatever we could have this be probably would only be ever in the tenants it would never be in the host because the host is just the person or the account which is creating other hosts usually and i used localization here just as an example actually it's required here i think and permissions crud product is something that i would need to add into en.json and shared and that's it we have now completed the last step now we got to run the app see the swagger and i'm getting ready to rejoice there it is there it is products yes excellent i should hopefully already be logged in and i might be able to get products oh there it is authorization failed i just pulled up beartail and we're looking in least or three host logs why did that fail it failed because authorization failed and i bet that if i go into the front end right now and take a look at the user admin but he belongs to the role called admin and if i view that set of permissions i need to add view update products save it back and [Music] 200 yay so that is running the app seeing the swagger and rejoicing fantastic hey i'm not going to get into the details of the front end too much but there's one thing that i do really want to show that is regenerating the proxies you can follow the guide yourself how to do the front end for whichever friend you prefer but just one thing that's really cool and that is i can run abp generate dash proxy and that's going to look inside of my swagger file and generate a set of strongly typed product typescript file and a bunch of other things one thing that's really nice about the way abp does this they used to use and swag in asp.net boilerplate and and so it was wonderful i love it but it generated one gigantic file and whenever i was doing code reviews on my project people that were new to the project would come and be like that's a it's an interesting uh you know fourth four thousand line you know 20 000 file or whatever it is that you've got there and you know i know you're a good developer but um you might want to try breaking that out in individual files and i have to explain that yes it's probably not a best practice to have 20 000 line files but that is what's being auto-generated so i don't really have a lot of choice in the matter so this is broken out into individual files which is a huge improvement and i think it's going to be a nice improvement for the ide as well for visual studio code notice that the enum was generated too and that's really nice there we go it automatically figured that out so that's going to be strongly typed isn't that nice and the product service i'm going to get a create method and delete method get method and here's my create product dto and my product dto and those are all just just generated for me it saves a ton of time love that feature if i was doing this in angular i would add a module i would update the routing there's a new nav component which is how it displays the top nav or it could be the left now depending on the ui template that you choose then you can duplicate their books folder which you can download from their template that's probably a good way to do it it's tempting as you get started on this project to look at the details as i've started to show you and you're thinking oh gosh why do they use two spaces instead of four spaces or or why did they put braces on the same line or why are they doing this why didn't they do that i've had a lot of co-workers that have felt the same way i've felt the same way at times and at times like these i think it's really important to take a step back and remember parkinson's law of triviality parkinson's law trivia it's when members of an organization give disproportionate weight to the tiny little details the trivial non-important things it's also known as bike shedding or missing the forest for the trees and so if you're tempted to complain about little details it's important to take a step back and remember everything that you're getting with abp.io you're getting localization pagination sorting and all these ui helpers and proxy generation i just showed you the login authentication authorization security model is just fantastic multi-tenancy is just an enormous feature that's super helpful if you need that the testing the in-memory database being automatically set up the database migrator project the authorization the domain driven design based classes and the club the auto crud that you're getting server-side validation uh client-side validation too i'll show that data annotations and custom validator that cool user-friendly helper exception the auto-mapper i didn't show that in as much detail but the automapper is really really helpful modules dependency injection auditing the ability to do soft deleting and and auditings just amazing the fact that you can see who last updated or created things the soft delete that filters the way the filters work the repository pattern the transactions logging the data seating the signalr background jobs the virtual file system all of that is just a huge amount of fantastic functionality so i'm a big fan of avp.io and it's remembered important to step back and that is how you can hopefully be a superhero on your next asp.net project so that's the end of my presentation hope you have learned something and enjoyed if you found this useful please like please subscribe i generally do a lot of content on asp.net boilerplate abp and these types of technology and have a wonderful day week month whatever [Music] you
Info
Channel: Lee Richardson
Views: 11,203
Rating: undefined out of 5
Keywords:
Id: ea0Zx9DLcGA
Channel Id: undefined
Length: 61min 12sec (3672 seconds)
Published: Fri Dec 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.