-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support nested registration of Startups #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the great write-up! We have yet to have a serious discussion in the team about multi-tenancy (of which this is one aspect), but your notes are definitely helpful in explaining one of the scenarios. |
Any news to this? Did you have a serious discussion about this very important subject? |
@MartinJohns sorry, we have not had this discussion. To be honest it hasn't come up much outside of this issue. I of course don't doubt the scenario is important, but it hasn't bubbled up close enough to the top of the priority list just yet. One thing that I think is theoretically possible right now, but perhaps a bit more difficult than it ought to be, is that if you fully use So, if you're feeling especially brave, it could be worth peeking into that corner of the system to see what might be possible! |
This is an interesting idea. I'm trying to figure out the best way to create a module/plug-in system so that you can drop in an assembly (via NuGet most likely) and it will have its own controllers, views, etc. I was initially thinking of having something like a Ideally, each module would be able to register its services into a child container to provide some isolation, and allow each module to have its own set of implementations (f.e. its own string localizer). One thing that I wasn't sure about was how to add items such as routes and DB contexts to the host application, as these things seem to usually run off calls to methods like Using the existing I also like the more explicit way of finding controllers per-assembly, instead of looking for controllers "everywhere". Unless I'm misunderstanding something, there is one major flaw: If you register a module (f.e. a "Blogs" module) based on a path ("/blogs"), then the services will only be registered/configured under that specific path, so pages in the host application would be unaware of the new configuration, meaning that it would not be possible to reference a route in the module (in order to link to it). I may be missing the whole idea here, so my apologies if that is the case. |
I know that it's not simple, but if the following was required for this to work (as an example):
... then ASP.NET/MVC wouldn't really be offering much, and it would probably make more sense to just create an entirely new framework. And before you suggest just that (:smile:), I don't have that amount of free time (or expertise, most likely). As for things like Orchard, I have looked at that to a certain degree, but I just wanted something relatively simple and I have no idea when they might have a solution for ASP.NET 5, and whether or not it would suit my needs. Anyway, I just wanted to indicate my interest in this type of architecture, as I think it would be extremely useful. |
As a voice of support, I am encountering this as I suspect are people looking for aspnet/DependencyInjection#246. I agree a universal solution may not be available; however, with DI throughout I do think it should be easier than it is. I had hoped that with Here is what I attempted (based on the Web API ASP.NET 5 Preview Template):
My hope/expectation was that |
@rynowak for your FYI information re: multi-tenancy. |
I think it's a pity that such an important feature is not considered for the initial release. I understand that this might be a bit more exotic, but it is something that likely can't easily be added on top of the existing frameworks, but instead needs to be tackled very far down. I tried updating my test-project to beta6, but unfortunately it does not work anymore. The inner "Service" MVC pipeline is not triggered. When navigation to I have two distinct |
@MartinJohns You probably need to set RequestServices to a child container once it enters your IsolatedMap |
This issue is being closed because it has not been updated in 3 months. We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate. |
Implicit imports prevents using <Import> on a project file that has the Sdk attribute. This change instead generates a file in the MSBuildProjectExtensionsPath to inject targets require to find the UserSecretsId property in a project. Resolves #242
In my old projects I used to have a solution with a web-project that renders a SPA frontend (using webpages) and a service-project that has a RESTlike API (using Web API). The service was hosted within the web-project out of cost issues, but I always kept the projects strictly separated so I could always host the service and the web project on each own.
With ASP.NET 5 and the merging of MVC, WebPages and Web API into one-MVC framework and with the global dependency injection this becomes more difficult. You can just have one single service collection that is used by all projects and registered in one Startup. You can't easily create sub-startups with their own service collection that is hosted in the same process.
With the help of PinPoint in the Jabbr chat I created a test project which allows this behavior to demonstrate my use case, but it's not nicely done.
https://github.com/MartinJohns/NestedStartupTesting/
In here I added an extension method
ApplicationBuilderExtensions.IsolatedMap
. It's basically a glorifiedapp.Map("/api")
call that creates an isolated new application builder and hooks up aMapMiddleware
in it. For this to work properly I need to create a copy of theIServiceCollection
within my web-startup and pass it to myIsolatedMap
-call. This is the ugly part that I can't find a good solution for.This approach allows me to call
service.AddMvc()
andapp.UseMvc
both in the web- and in the service-project distinctly. Both projects can add their own services and they don't mix up. This also allows me to either host my web-project together with my service-project, or host the service-project on it's own without doing any change. It has it's own Startup that is recognized and run by the environment. I could also create a hosting project and make it configurable (viaIConfiguraton
) which other projects are hosted within it, which would be great for a system where you can just add plugins that each work on their own.My solution may work, but I consider it ugly. I have two working points, once in
ConfigureServices
where I need to clone the incoming service collection, and once inConfigure
where I actually register the sub-app. I need to copy the service collection so the sub-app has an equal starting point, the same pre-requisites as the outer-app (e.g.IHostingEnvironment
).Therefor I propose a new functionality that would make this more easy possible, but would require changes in (I think) the hosting environment:
The text was updated successfully, but these errors were encountered: