Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Modular multi-tenancy web application #2845

Closed
alexsandro-xpt opened this issue Jul 22, 2015 · 7 comments
Closed

Modular multi-tenancy web application #2845

alexsandro-xpt opened this issue Jul 22, 2015 · 7 comments
Milestone

Comments

@alexsandro-xpt
Copy link

Take a look in this scenery below:
I need to develop a CMS portal for 200 custumers, this customers have a set of feature like agenda, curriculum, banner named feature module. Those modules are enabled or disabled for each custumers.

Now, thinking about architecture solution for a good develop process, I wish to separate each modules as a separated Visual Studio solution within their controllers(CRUD), css, js and cshtml for late soon run it in main web application project as a middleware feature like that.

app.UseCustumerModule(); // produce /custumer, /custumer/new , /custumer/delete 
app.UseProductModule(); // produce /product, /product/new , /product/delete 
app.UseSalesModule();

or

app.UseMiddleware<CustumerModule>();
app.UseMiddleware("ProductAssemblyName");

Then if ASP.net 5 can give me that possibility to develop a web plataform system like my scenery?

To illustrate what I am saying look http://www.codeproject.com/Articles/614767/NET-ASP-NET-MVC-plug-in-architecture-with-embedded

Stackoverflow question: http://stackoverflow.com/questions/31296604/asp-net-5-middleware-feature-as-a-modular-application

Thanks

@danroth27 danroth27 added this to the Backlog milestone Jul 22, 2015
@CoskunSunali
Copy link
Contributor

You will get stuck at some point when you decide to use the security (authentication) middlewares.

Until they implement it, one can say that the ASP.NET 5 does "not" support multi-tenant scenarios.

aspnet/Security#35
aspnet/Security#364 (comment)

@alexsandro-xpt
Copy link
Author

Fine @csunali, perhaps this multi-tenant scenario feature doesn't need to be a middleware to security work.

Could be an another configuration to response controllers, cshtml and static files in shared .net project.

A big need here is, isolate the pluggable application CRUDs like Agenda, Product and others to main Web Application.

@CoskunSunali
Copy link
Contributor

Right, you don't have to use the authentication middlewares for every project but you having mentioned your project being a CMS project and CMS implementations always having a backend made me think that you will eventually have to implement authorization and authentication features. So, if you ever consider using OpenId Connect or such features (and you will if you have public API methods that get exposed), the ASP.NET 5 does not support those scenarios until architectural changes are made to the core authorization middlewares.

Apart from that, what you are asking for sounds quite achievable. I had a similar need and came across the following limitation of ASP.NET 5: You cannot have separate Startup classes within your projects. Eventually you might but ASP.NET will not run through them. Your "web application project" is the only place where the ConfigureServices and Configure methods of your Startup class will be called dynamically.

I have read discussions here and there where some fellows from the ASP.NET Team say that they don't want to search through assemblies for Startup classes for the sake of performance. Personally, that does not make sense to me. MVC and many other middlewares already make lots of type searches on many assemblies. I am almost certain that they have a valid argument but I have not heard of that yet.

So, what I have done was implementing a custom IStartup interface, implementing classes that implement the IStartup interface, searching through assemblies for classes implementing that interface and invoking their ConfigureServices and Configure methods dynamically within the web application's Startup classes.

I have ended up all my "module projects" having their own Startup classes. Actually more than one Startup classes if a module needed. There is technically no limitation on how many Startup classes one project can have. I have assigned them an InitializationOrder using a get-only property so they get executed in a meaningful order. Each Startup class can register services of its own and also configure other stuff using IServiceCollection and IApplicationBuilder classes being passed to them.

For controllers; they should work out of the box. MVC searches through the assemblies for them. Just make sure that their names do not conflict with each other no matter if they are in separate assemblies.

For cshtml and static files; I put them within their own module project and set them to be "embedded" using project.json file. Then I have developed a custom IFileProvider which checks whether a requested file is within an assembly or not. You are supposed to look for "resources" configuration section (that is recently renamed to "content" if I am not wrong) in order to embed some type of files into an assembly. You also have to attach that custom files provider to the StaticFiles middleware so that the static files middleware knows how to dive into an assembly to find a static file (a javascript file for example). There is already an EmbeddedFileProvider developed by the team at https://github.com/aspnet/FileSystem/blob/dev/src/Microsoft.AspNet.FileProviders.Embedded/EmbeddedFileProvider.cs It has its limitations but once you grab the idea, you can just extend it or develop a custom one.

By the way, the static files middleware has a bug currently, just make sure your first request does not hit a static file: aspnet/StaticFiles#65

@alexsandro-xpt
Copy link
Author

Good tip @csunali, about security, really I will eventually have to implement authorization and authentication features. I should look all that what you said closely. May be a demo project.

This scenario is a big box, because we are talking about system and their subsystem and how they interact between they self.

They could have module dependences. Imagine, Product Module could be use Image Module for product's image. Post Module uses Image Module and Agenda Module.

Today we have that legacy CMS in ASP.net Web Forms project, builded in 2006, using User Controls. In this year we are starting to rewrite everything in MVC, preferably in ASP.net 5

@alexsandro-xpt
Copy link
Author

Needs Design +1

@Eilon
Copy link
Member

Eilon commented Nov 15, 2016

cc @danroth27 because this is related to the new ASP.NET Core Modules ideas.

@pranavkm
Copy link
Contributor

At this point, our guidance is to look at a module system such as the one Orchard Core provides. Orchard Core modules allow you to build modules as NuGet packages that can be added to your application on the fly. And you can use them as a low level framework without adopting the entire Orchard CMS infrastructure. Check out https://github.com/OrchardCMS/OrchardCore.Samples to see what this looks like.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants