I started working with autofac’s multitenancy integration and I have a question:
Can I add a controller that’s only available for an specific tenant?
I know that you can override a controller registered in the base container, but I want a controller that is only available for the tenant that registered?
Is that possible?
I started working with autofac’s multitenancy integration and I have a question: Can I
Share
While I haven’t tried it, I believe you could do that with a little manual registration.
The problem is, if you auto-register all the controllers in the main container using
builder.RegisterControllers(theAssembly)then all the controllers will automatically be picked up – including the tenant-specific one. (Assuming the tenant-specific one is in the assembly with everything else.)To make it easy on yourself, you might want to split the tenant-specific stuff into a separate assembly. Then to get controllers that are only for one tenant, it’d be something like this:
Just like any other tenant-specific dependency.
When MVC tries to resolve an instance of your controller, it does it from the DependencyResolver, which will behave in a multitenant fashion and only be able to resolve the controller when the right tenant is making the request. If some other tenant makes a request for that controller, the controller won’t be found in the list of registered components so they’ll get an error.
Note that if you put your controller in a separate assembly that isn’t referenced by the main application assembly, you may also need to tell the ASP.NET compilation system about it or the controller type won’t be found properly. Add it to the
system.web/compilation/assemblieslist:But, like I said, I haven’t tried it. I’ve only ever done controller overrides.