Building modular, multi-tenant ASP.NET Core apps with Orchard Core framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we're live ok thank you so much for bearing with us I think there was most let's push that one red button and obviously that's what happened ok I'm Kendra havens I'm here with Sebastian rose ok and we're here to talk about building modular multi tenant asp.net core apps with the orchard core framework but it's actually gonna be super understandable yeah yeah ok I'll ask questions and we'll we'll see how we do so I think you have some slides do we want to jump in already the best night actually why don't you introduce yourself first what do you work on so I work at Microsoft and the asp.net and mostly on performance and orchard core but just a little just readin from some benchmarking and just a little bit of protocol so I know what I will be talking about oh no treacle that's it yeah and the throughput is so obvious I know obvious my slides well wait wait maybe I need to read to reconnect my yeah happens okay no sighs it's just okay that if I if I turn my screen and we every problem as a solution oh it works it works okay so try to switch back thinking goes for this to me Oh okay so let's start then yeah so the title is building modular multi-tenant SP net core applications with orchard call the first question is about modular applications and why you would build modular applications so most of the time modular applications is to work in isolation like each project project is highlighted from every everything else and you might do that because you work with multiple teams and each team wants to own a different section of the application so we'll have to split the work and each project with each team in your environment or it might be because you want to reuse some of the parts of your application these modules for instance let's say they these parts these modules contain static assets like scripts images or middleware like authentication and UI like user management or dashboard why and these pieces of your application you want to reuse them across applications you will want module and last thing imagine that these modules these parts of your application you want actually to develop them as a community and publish your components on the public feed like you get the new gate gallery or any other gallery and with modules you can do that and create reusable parts public parts that will help you make some more global ecosystems of application components let's say like a CMS or an e-commerce that anyone could publish modules for that that's the goal of making modularity now how do you do that in a spinet core and ultracal framework is a solution let's see how it works concretely if you want to use ultracal framework to build modular application so I will switch to a visual scene you and I have a solution ready with a web application that is based on the see template in Visual Studio when you create a new web application these empty template as a start-up Plus that has a configure method that we just returned hello world from the home endpoint in emitter well okay so if I ran this ad very simple it will just output Edward thank you now I want to extend this application with a separate module so here I have a class library that I called ecommerce this is a simple sdk web class library that I make as a library you're targeting the net crop 3:0 target and it has a start like this empty app data so a startup class like any SP nightcore up with a configure method that will map a specific end point to responding ecommerce the same way so I want to be able to make that part of my application so when using AA trick or framework to do that we will need to convert this app into a modular add post and this class library to a module to do that we will use NuGet packages which are negated all and are made for SPF cost visual so here I will go manage mine you get packaging and browse or you get at all packages and because this is the host application I will import the orchard core application targets package which will convert my application to a modular host application when this is done and this application this vast library sorry I will do the same thing managing get packages but this time instead of the application target I will use orchard call that module dot you're adding a new get packaged story not with this tab but the browser this is a package I want and I will install this package so now each of the components are ready but in my startup I will need to use the services provided by Oracle so I will do services that add on Treecko oops why break because I broke that all chuckle and in the Middle where I will use the orchard call either way so my application is ready to host modules these class are very easy module and my services are configured to accept modules if I run this app again you will see that it to network so if I try to access the e-commerce and point it doesn't work because I need to tell my application to use this model until that we just add a reference to this project and with that the services will find this package as module and plug all the startup from these modules into my host application and so by doing e-commerce I have my endpoint working in my host application so now you see how we can create a modular host application and a module now the goal of modules is to be reusable it's one of the goals so let's see if I can create another ad and reuse this module so to do that I will create a new object that will be a core web application and I will base it this time with a more complex example on a web application the web application in a spirit we will configure rays or pages from the SPID MVC framework so I will say create and add this for application that will make the main application just run it to see that it works correctly and I have the more complex up than my empty ad which contains arrays of page which is defined as a home page so let's add this module to this happened the same way we did earlier I will add when you get packaged to the new application but this one will be an MVC one because it will understand all the MVC concepts to make it modular and then with that I can do the same thing as user add remove address of pages but with a twist by saying our MVC to support the services for NBC which will replace the address of pages it's included there and also here I don't need authorization I don't need this call I will do that by just green use orchard call the same way so same thing with two lines of code on one package I made this app modular host application and I will reference the module ecommerce that we created earlier and was working in a standard web app run the application still working but now I can access the endpoints defined in my module so the nice thing here is that same module is used from ninetieth that doesn't know well maybe see all these apt and knows about Indies and this is a simple module but what if I want to create a module that has more things to provide in this case because I'm working with MVC we want to create a module that will contain some MVC concepts so let's try to do that I will add an existing project that I have pre-created before which is called web api because it contains some well api so this is a web project that is a library and that reference is the module target so it's a module but like the e-commerce module it has a startup which isn't it does nothing though it provides the controller this is the weather forecast controller from the default template for I think the API project template and this one is a standard MVC controller that is routed to the controller name so this should be we have a forecast and that will return on any get a list of forecasts as I get all into JSON results okay so this is a module so I just need to reference it from my host application which is MVC host with web api and now this ad is made of its own startup and two different order modules the e-commerce module and the Web API module and this one provides weather forecasts API so if I run my app still working and I go to weather forecast I see that it returns the Jason and the research is coming from maximum so that's the first step we can have web at the eyes using the routing system and point routing system from a spinnaker MVC from external modules and you can see that you can extend your applications just by referencing an existing module so let's go a step further and add more components to this module so here we just have the Web API controller but what if I want view controller or controller I which region of you so I will add a new class wait I will copy paste this class and I will call it home controller and remove all the things here inherit from controller call it home controller and simply have an index method that will return of you and this view that I will create in the home folder to match the controller new item I want a raise of you add and here I will just say hello from home okay so I have a home controller and the default route or a controller will be the name of the controller and the action and I want change the route for now just to show you how it works and I will be there will be two steps to make it work correctly I run the app I don't change anything I just changed my module but I don't change that and prepare to access this controller I will do Web API slash home slash index and you see here hello from home so the first thing you notice is that is not home slash index at like understand an app its Web API slash home slash index because the default convention for modules controllers and routes is to prefix them with the module name just to prevent collisions from modules but I could very easily add a custom round like my home or even convention one but ok let's try with Michael and read it again and access is empty so you see here you can also redefine from a module how you want to expose it and I could also have done it from the host app to customize each modules route for the specific application now the next thing you will notice is that this view doesn't use the layout of the host application this is just because we need to say it in every view so in the host application the views which are raised or pages here are using a view start that wins test set the layout to the shared layout in this host application so if I take this code and put it in my view or in a view start under the views folder of the module I will get the same result so by doing that and running the application I get the same layout as the host application but from a view which is inside a module and which is nice here is that as a module developer I can create my view my views without having to think about how they will be hosted on what layout the host application will use so you can imagine that tomorrow I could create a new app with a different layout for a different goal for instance and all the modules are built rendering views will adapt to the layout that they will be hosting so super flexible but you could also say I want my custom layout or take it dynamically for each application it's up to you in this case we can reuse the layout which is the product so we can create controllers but I could also create arrays of page and just do add older pages and then I will take this file and call it about and convert it to a razor page that will be routed to about and this is about page if I run it again the mudras build contains a razor page and the application should expose it okay and the same way here we don't have any view which might be what you want to rainy layout I could just add a layout section here and we use the layout from the host so that's the second thing we can add in MVC modules and the last thing I will show you is how do I add static content so we quite a folder called the de bruit exactly the same way I will build an ASP right ad and in this folder I will put some kittens I find kittens have kids so I put a kitten in my dub-dub-dub good and I assume it won't hurt it let's try to run it and the same way for controllers we have a custom route to a custom convention to prevent collisions we will do Web API slash kittens dot JPEG and then we can also serve static assets so modules can serve all kinds of things and that's what is important in in these kind of models because then it's really like a micro application a mini section of your site of your web app that you can put inside a class library and reuse it now the next step of reusing a module is to publishing it and to share it across different services or companies and everywhere you want to share it so to do that we will use onion get package so ideally I will right-click on the project and say back to create a new get package if I do that visuals you will complain that the project cannot be packaged because packaging has been disabled so let's add this attribute this tag to my project I will add that tag and also define a custom package version because I want to prevent any conflict with previous attempts I did so I will give it a number and just say back and doing that I have this file that has been created so let's look at the older under Web API bin-debug I have the file just packed which contains my module and all the assets like the controller's the static files look at the kitten res of pages views and I will copy it inside this folder which I configured in visual studio let me show you I configured this folder here mine you get packages is pointing to local folder where I put my package so it will be and you get package show so very interesting if you didn't know this trick to check your packages and I can browse this source and here this is my package so I will remove the reference from the project itself ok and let's run the application just to be sure that I can't access the my home it's not available anymore because I don't reference the module anymore but I will install this package and run it again so I just include my package as when you get reference and if I go to my home then it's available again and if I go to Web API slash kittens it's also available everything came from the package I could put this package on you get or any other package repository and share it with everyone using the ochakov framework that's it for the modularity and I think you can now understand how easy it is to make one your apps not mentioning that you could have apps that are made of tens hundreds of different modules to build the main app you want now let's go back to the slides because I want to talk about multi-tenant applications so multi-tenant application is an application that will be deployed once but will be able to host as many or as much as you can as many websites with a single deployment typically that's what we call software the service when you deploy once but you can provision as many sites for each customers or as many services so a single application can host multiple isolating websites a very good example for that is what fresco when you go to wordpress.com you can create a new blog a new website you just type your name your email know create card information and you get a new site under either the prefix like Sebastian Ross blog or a domain if you pay to own the domain and to register it on wordpress.com but in terms of hosting wordpress didn't install a new website somewhere they just add a new entry in the service to provide you with the same service but in isolation from the other customers so that's what is software service and that what a multi-tenant application is so how do you do that with HP annette well you will use orchard Corso and that's why we have modularity no cheat code to be able to provide software service where every tenant can have different sets of modules which are which are deployed with your application so this is an example I mentioned a tenant can be accessed through different domains which we all point to the same servers but the server the application will route based on a domain or based on the prefix of each customer to the set of data and configuration that the tenant represents because each tenant is isolated winning each student has different services middleware and options in terms of asp.net services mineral options each student can have different data like configuration such as connection string or different data as in the database like different set of users even though it's it's provided by the same app and then you can isolate the tenant in terms of security for instance each tenant could have its own authentication logic like let's use integrated authentication or Google authentication and so on the cookies should not cross the boundaries of the tenant and also maybe you want a tenant to have different features than the other like maybe I wanted to meant to have my web api feature on my e-commerce feature or both of them based on what they want to pay for but I deploy once with all these modules and I can allow or disallow every feature for each tenant so how do we do that with what we call well what you need to do is change this start up here to just say our MVC and then let's enable multi talents by doing with talents and now I need to define somewhere what talents I want to use and to do that I have a file ready here I will take that and overwrite the one not this one yes this is one Absa teens replace so what's the difference in this file I have a new section Orchard call with three tenants by default inant which is the one that was created before that I was showing you all the time and I want a tenant for my customer a and tenant for my customer be an Inside Me section what do I say is that this talent is running because I could also disable every customer each customer I could also say this is the domain that is mapped to this is the URL prefix that I want to do it in this case my slash will be the default owner these are the default features I want my tenant to have so the default site won't have any feature and I can also add custom settings richland like connection strings the color of the layout things like so if I look at my customer a it has a URL prefix which will be the base path that I will have in the URL to target this customer this is the same as if you use in WordPress become your own thing and then here customer B so if I run that first I will have to change the layouts one sec that's here I'm on my way application pages shared okay replace you know I want to layout that works for everyone every night so I'm at a fortunate but if I do customer a IRA saw the site all I need to rebuild it's just the asset doesn't it doesn't find so I can access the customer a or the customer beside I will build it works and you can see here the customer B has access to ecommerce and Web API with commerce customer a has only access to ecommerce if I run it if I do customer a / ecommerce it works customer B / D commerce works also but if I do weather forecast which is coming from a different module customer B has it but customer hate doesn't help so I can customize every feature for each tent and this is how you do multi-tenancy and that's the last demo I have so I encourage you to go and see our website watch it projected net our source code on detail we are also forms and documentation on my Twitter and if you want to see a real usage of multi-tenancy that looks like voice proceed cam we made a site that does exactly that it's a modular application which is Australia service you type an email like my email you type a sign name and you choose what kind of website you want and this site will create a tenant inside itself and I created one just before so you see to try outside dotnet try dot out your head at night and if I go here I had I got a link right before it generated you all prefix randomly for you and now I have the site under the same domain and are currently hundreds of thousands of sites tenants under this same deployment so that's a good example of how you can reuse this multi-tenancy to make a software-as-a-service application that will create tenants dynamically without any user interaction I'm ready yes so the default experience which is the service is to load the tenants from a file but in the example I just showed you the tenants are stored inside of the file so in this case actually but dynamically and will be saved outside of the app settings but the custom JSON document that will I will store it and we have other providers that can store in a Joe blob storage or the database that's the next question so what happens if you have a module named the same as a controller action there might be conflicts and so that's why I also explained that if you find conflicts then you have to solve the conflicts and from your host application you can define the routing for the tenants so actually here in add ultra call or adam vc there is maybe a doctor : there is an extension maybe to use I don't remember exactly where but there is an extension where you can add custom endpoints from your host for different modules just to prevent any collision that could happen or try to make your modules bill all prefixed by the volume name that's cool so I'm just gonna hold the mic like this we only have the one all right so I wonder if these modules can be deployed separately from the main application nope you can't with ultra core framework by design we didn't want to allow that because we tried it's very complex the issue being that if modules are dynamically loaded it might break your site and also it doesn't match with the idea of deploying your service on different nodes because you have when you install dynamically a module you will have to do that on all the nodes of your cloud and that's hard to do because only one server will get the request to install module so our suggestion is to test locally to beam locally and then to deploy on every node so we don't do dynamic loading of of modules all right next question what is the difference between a module and a project I think some people were a little bit unclear on the terminology okay so the module is a geological concept which is represented by projects on a project that references the modules target we call it a module that's module is a project and I show you module can contain multiple features so you can split inside a module which will be an assembly or package you can split different features in the example I gave right now I just created a single feature default one I didn't create multiple features a module just to simplify the example but you can imagine a module that contains different logical sets of controllers views that you can enable and disable independently I think one last question before we switch over to our next speaker is security handled from the orchestrator module or is it independent for each module it's from the host application pertinent so each tenant will define its own security like its no ventilation its own authorize Asian and you can have different ones so you could have it at the host level because it could be a middleware that acts before the auto commit aware because at that point there will be a fork that will map every tenant to its own set of middleware so every tenant can have their own set of middleware for security or you can have the middleware define before orchard so that you have a single middle pipeline to define a security all right well thank you so much for joining us sebastian next up we have robert talking about cryptography 101 with dotnet core so let's go ahead and call him on skype thank you so much for joining let's see if I can switch over to the
Info
Channel: Microsoft Visual Studio
Views: 41,862
Rating: 4.8483415 out of 5
Keywords:
Id: yrQaKv2mxFU
Channel Id: undefined
Length: 35min 50sec (2150 seconds)
Published: Thu Oct 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.