autofac/Autofac.Multitenant

Support for configuring multi-tenant types via configuration file

RyannosaurusRex opened this issue · 3 comments

Is there support for configuring the Autofac.Multitenant-specific options via a configuration file instead of through code? I personally prefer code, but I have lost to a mandate that it be configurable via an XML or JSON file, similar to http://docs.autofac.org/en/latest/configuration/xml.html. Is this possible/currently supported or on a roadmap?

I didn't see docs for it at http://docs.autofac.org/en/latest/advanced/multitenant.html is mostly why I'm asking.

There isn't a specific configuration mechanism for multitenancy, but it's easy enough to use the two concepts - configuration and multitenant containers - together.

var builder = new ContainerBuilder();
// register global app types
var appContainer = builder.Build();
var tenantContainer = new MultitenantContainer(new IdStrategy(), appContainer);

foreach(var tenantId in tenantIds)
{
  var config = new ConfigurationBuilder();
  config.AddJsonFile(tenantId.ToString() + ".json");
  var module = new ConfigurationModule(config.Build());
  tenantContainer.ConfigureTenant(tenantId, b => b.RegisterModule(module));
}

Basically, just register the configuration for the specific tenant when configuring that tenant.

But, like I said, there's not a specific extension or mechanism for that since the way configuration is read may differ from app to app. You could probably make a solution like this cleaner in your own code by writing your own extension methods.

Ah, of course. That totally works. Thanks for pointing me in the right direction!