Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Multitenant support has been available for a long time, it's just that 3.0 is the first time we've had a NuGet package for it. :)</p> <p>The <code>RequestParameterTenantIdentificationStrategy</code> is, as documented, just a very simple example showing one possible (and <strong>not recommended</strong>) way to identify tenant. You will have to choose for yourself how to identify your tenant based on the operating context. It could be from a <code>web.config</code> value, an environment variable, or some other thing in the current environment. If you don't want to use <code>HttpContext.Current</code>, don't. It's up to you to pick where you get that info from.</p> <p>(A note on the <code>RPTIStrategy</code> - the part that isn't recommended is using a querystring or request parameter as the tenant ID mechanism. I use <code>HttpContext</code> in my production apps and it works fine. There's only so much you can abstract out before you have to actually touch the bare metal.)</p> <p>There is no way out of the box to provide the lambda registration syntax you're asking for, primarily because tenant is not passed through the resolution process. The resolution process is:</p> <ol> <li>Identify the tenant with the strategy.</li> <li>Find the tenant's configured lifetime scope.</li> <li>Use standard Autofac Resolve style syntax.</li> </ol> <p>It's intentionally simple and analogous to the existing operations. At the time of resolve, the sub-lifetime-scope belonging to the tenant is <em>tagged</em> with the tenant ID but the resolution operation doesn't know about the tenant ID... so the lambda wouldn't work (and probably won't anytime soon because it'd change the fundamental internals of the way Autofac works if it did).</p> <p>To accomplish what you're looking for, you can use a combination of the <code>InstancePerTenant</code> extension when registering...</p> <pre><code>var builder = new ContainerBuilder(); builder.RegisterType&lt;Foo&gt;().As&lt;IFoo&gt;().InstancePerTenant(); </code></pre> <p>...and registering the <code>ITenantIdentificationStrategy</code> as a dependency in your container.</p> <pre><code>builder.Register(myIdStrategy).As&lt;ITenantIdentificationStrategy&gt;(); </code></pre> <p>Then make your class take an <code>ITenantIdentificationStrategy</code> rather than the tenant ID directly. Use the strategy to get the tenant ID instead.</p> <p>If you REALLY want to get fancy, you could register a keyed lambda that resolves the ID strategy, then gets the tenant ID. Then you could add a parameter registration to the object like you did but using a keyed service. (I'm going to go by memory now, so you'll have to double-check my syntax here, but it'll be something like this...)</p> <pre><code>builder.Register(c =&gt; { var s = c.Resolve&lt;ITenantIdentificationStrategy&gt;(); object id; s.TryIdentifyTenant(out id); return id; }).Keyed&lt;object&gt;("tenantId"); builder.RegisterType&lt;Foo&gt;() .As&lt;IFoo&gt;() .WithParameter( (pi, c) =&gt; pi.Name == "tenantId", (pi, c) =&gt; c.ResolveKeyed&lt;object&gt;("tenantId")) .InstancePerApiRequest(); </code></pre> <p>Again, you'll want to double-check me on that, but I'm pretty sure that (or a minor variation) should work to get you what you want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload