Multitenant Container configuration

67 views
Skip to first unread message

gtrubach

unread,
Nov 18, 2016, 12:52:39 PM11/18/16
to Autofac
Hi!

I have one question about reconfiguring tenants in runtime. I read a lot of information that we couldn't change configuration for configured tenant. In source code it's provided by if-check:

if (this._tenantLifetimeScopes.ContainsKey(tenantId))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, Properties.Resources.MultitenantContainer_TenantAlreadyConfigured, tenantId));
}

But I cannot understand why? Why we cannot begin new lifetimescope for existing tenant with new configuration:

this._tenantLifetimeScopes[tenantId] = this.ApplicationContainer.BeginLifetimeScope(TenantLifetimeScopeTag, configuration);

And the seconde one. I tried to change source code in my application and simply remove if-check. Nothing bad happens. Can somebody explain what I'll get I'll will use this.ApplicationContainer.BeginLifetimeScope(TenantLifetimeScopeTag, configuration) for existing tenant with new configuration.

P.S. All my configuration is simply DB connection string.

Thanks!

Travis Illig

unread,
Nov 19, 2016, 2:49:39 PM11/19/16
to Autofac, genat...@gmail.com
In general, containers should be considered immutable, as mentioned in our best practices documentation. To that end, in the most recent dev codeline of Autofac (not yet published) we've marked ContainerBuilder.Update obsolete and intend to remove it in a distant (year or more) future update. In the meantime Autofac issue #811 discusses why this is the case - why updating a container isn't a good idea, why it's not so easy to just fix things. That discussion has the same relevance here - why you can't/shouldn't update a tenant scope. Rather than repeat all of that here, go read the issue to see that explanation.

What I could imagine supporting, instead of updating a tenant scope, is the ability to remove an existing tenant scope to allow it to be reconfigured. The application logic would be:
  • Remove the specific tenant scope that needs to change from the multitenant container.
  • Reconfigure the tenant's registrations, this time with the updated values.
If you think something like that is interesting, I'd recommend filing an issue with Autofac.Multitenant for an enhancement. Once we have an issue, we can talk about how it might work and we can start accepting pull requests.

genat...@gmail.com

unread,
Nov 22, 2016, 2:53:10 AM11/22/16
to Autofac
Yes it's interesting for me. I and I'm going to create enhancement issue. But I will be later when I'll have more time.

Now I have one question: can I use modified by me source code of MultitenantContainer in commercial project? And if yes what I must do with the license? Thanks!

Alex Meyer-Gleaves

unread,
Nov 22, 2016, 8:33:27 AM11/22/16
to Autofac, genat...@gmail.com
All Autofac projects are MIT licensed. You can use a modified version as you like as long as you include the license.


From the license file:
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Reply all
Reply to author
Forward
0 new messages