Click or drag to resize

MultitenantContainer Class

IContainer implementation that provides the ability to register and resolve dependencies in a multitenant environment.
Inheritance Hierarchy
SystemObject
  Autofac.UtilDisposable
    Autofac.MultitenantMultitenantContainer

Namespace:  Autofac.Multitenant
Assembly:  Autofac.Multitenant (in Autofac.Multitenant.dll) Version: 6.0.0+9a36082eb9b91dac82616d9efefa940b8c375948
Syntax
public class MultitenantContainer : Disposable, 
	IContainer, ILifetimeScope, IComponentContext, IDisposable, IAsyncDisposable

The MultitenantContainer type exposes the following members.

Constructors
  NameDescription
Public methodMultitenantContainer
Initializes a new instance of the MultitenantContainer class.
Top
Properties
  NameDescription
Public propertyApplicationContainer
Gets the base application container.
Public propertyComponentRegistry
Gets the current tenant's registry that associates services with the components that provide them.
Public propertyDiagnosticSource
Gets the DiagnosticListener to which trace events should be written.
Public propertyDisposer
Gets the disposer associated with the current tenant's ILifetimeScope. Component instances can be associated with it manually if required.
Protected propertyIsDisposed
Gets a value indicating whether the current instance has been disposed.
(Inherited from Disposable.)
Public propertyTag
Gets the tag applied to the current tenant's ILifetimeScope.
Public propertyTenantIdentificationStrategy
Gets the strategy used for identifying the current tenant.
Top
Methods
  NameDescription
Public methodBeginLifetimeScope
Begin a new nested scope for the current tenant. Component instances created via the new scope will be disposed along with it.
Public methodBeginLifetimeScope(Object)
Begin a new nested scope for the current tenant. Component instances created via the new scope will be disposed along with it.
Public methodBeginLifetimeScope(ActionContainerBuilder)
Begin a new nested scope for the current tenant, with additional components available to it. Component instances created via the new scope will be disposed along with it.
Public methodBeginLifetimeScope(Object, ActionContainerBuilder)
Begin a new nested scope for the current tenant, with additional components available to it. Component instances created via the new scope will be disposed along with it.
Public methodClearTenants
Clears all tenants configurations and disposes the associated lifetime scopes.
Public methodConfigureTenant
Allows configuration of tenant-specific components. You may only call this method if the tenant is not currently configured.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from Disposable.)
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
(Overrides DisposableDispose(Boolean).)
Public methodDisposeAsync (Inherited from Disposable.)
Protected methodDisposeAsync(Boolean)
Releases unmanaged and - optionally - managed resources - possibly async.
(Overrides DisposableDisposeAsync(Boolean).)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetCurrentTenantScope
Retrieves the lifetime scope for the current tenant based on execution context.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetTenants
Returns collection of all registered tenants IDs.
Public methodGetTenantScope
Retrieves the lifetime scope for a specific tenant.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReconfigureTenant
Allows re-configuration of tenant-specific components by closing and rebuilding the tenant scope.
Public methodRemoveTenant
Removes the tenant configuration and disposes the associated lifetime scope.
Public methodResolveComponent
Resolve an instance of the provided registration within the current tenant context.
Public methodTenantIsConfigured
Returns whether the given tenant ID has been configured.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events
  NameDescription
Public eventChildLifetimeScopeBeginning
Fired when a new scope based on the current scope is beginning.
Public eventCurrentScopeEnding
Fired when this scope is ending.
Public eventResolveOperationBeginning
Fired when a resolve operation is beginning in this scope.
Top
Extension Methods
  NameDescription
Public Extension MethodInjectPropertiesTService(TService)Overloaded.
Set any properties on instance that can be resolved in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectPropertiesTService(TService, IEnumerableParameter)Overloaded.
Set any properties on instance that can be resolved in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectPropertiesTService(TService, Parameter)Overloaded.
Set any properties on instance that can be resolved in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectPropertiesTService(TService, IPropertySelector)Overloaded.
Set any properties on instance that can be resolved by service and that satisfy the constraints imposed by propertySelector.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectPropertiesTService(TService, IPropertySelector, IEnumerableParameter)Overloaded.
Set any properties on instance that can be resolved by service and that satisfy the constraints imposed by propertySelector.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectPropertiesTService(TService, IPropertySelector, Parameter)Overloaded.
Set any properties on instance that can be resolved by service and that satisfy the constraints imposed by propertySelector.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectUnsetPropertiesTService(TService)Overloaded.
Set any null-valued properties on instance that can be resolved by the container.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectUnsetPropertiesTService(TService, IEnumerableParameter)Overloaded.
Set any null-valued properties on instance that can be resolved by the container.
(Defined by ResolutionExtensions.)
Public Extension MethodInjectUnsetPropertiesTService(TService, Parameter)Overloaded.
Set any null-valued properties on instance that can be resolved by the container.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegistered(Type)Overloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredTServiceOverloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredService
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredWithKey(Object, Type)Overloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredWithKeyTService(Object)Overloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredWithName(String, Type)Overloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodIsRegisteredWithNameTService(String)Overloaded.
Determine whether the specified service is available in the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolve(Type)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolve(Type, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolve(Type, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveTServiceOverloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveTService(IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveTService(Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveExportsTOverloaded.
Locate all of the MEF exports registered as supplying contract type T.
(Defined by RegistrationExtensions.)
Public Extension MethodResolveExportsT(String)Overloaded.
Locate all of the MEF exports registered as supplying contract type T.
(Defined by RegistrationExtensions.)
Public Extension MethodResolveKeyed(Object, Type)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveKeyed(Object, Type, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveKeyed(Object, Type, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveKeyedTService(Object)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveKeyedTService(Object, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveKeyedTService(Object, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamed(String, Type)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamed(String, Type, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamed(String, Type, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamedTService(String)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamedTService(String, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveNamedTService(String, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptional(Type)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptional(Type, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptional(Type, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalTServiceOverloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalTServiceOverloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalTService(IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalTService(Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalTService(IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalTService(Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalKeyedTService(Object, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalNamedTService(String)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalNamedTService(String)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalNamedTService(String, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalNamedTService(String, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalNamedTService(String, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalNamedTService(String, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionValueExtensions.)
Public Extension MethodResolveOptionalService(Service)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalService(Service, IEnumerableParameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveOptionalService(Service, Parameter)Overloaded.
Retrieve a service from the context, or null if the service is not registered.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveService(Service)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveService(Service, IEnumerableParameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodResolveService(Service, Parameter)Overloaded.
Retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodSubscribeToDiagnostics(DiagnosticTracerBase)Overloaded.
Subscribes a diagnostic tracer to Autofac events.
(Defined by ContainerExtensions.)
Public Extension MethodSubscribeToDiagnosticsTOverloaded.
Subscribes a diagnostic tracer to Autofac events.
(Defined by ContainerExtensions.)
Public Extension MethodTryResolve(Type, Object)Overloaded.
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodTryResolveT(T)Overloaded.
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodTryResolveT(NullableT)Overloaded.
Try to retrieve a service from the context.
(Defined by ResolutionValueExtensions.)
Public Extension MethodTryResolveKeyed
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodTryResolveNamed
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodTryResolveService(Service, Object)Overloaded.
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Public Extension MethodTryResolveService(Service, IEnumerableParameter, Object)Overloaded.
Try to retrieve a service from the context.
(Defined by ResolutionExtensions.)
Top
Remarks

This container implementation modifies the definition of the standard container implementation by returning values that are tenant-specific. For example, resolving a component via ResolveComponent(ResolveRequest) will yield a resolution of the dependency for the current tenant, not from a global container/lifetime.

The "current tenant ID" is resolved from an implementation of ITenantIdentificationStrategy that is passed into the container during construction.

The ability to remove (RemoveTenant(Object)) or reconfigure (ReconfigureTenant(Object, ActionContainerBuilder) an active tenant exists. However, it must still be noted that tenant lifetime scopes are immutable: once they are retrieved, configured, or an item is resolved, that tenant lifetime scope cannot be updated or otherwise changed. This is important since it means you need to configure your defaults and tenant overrides early, in application startup.

Even when using ReconfigureTenant(Object, ActionContainerBuilder), the existing tenant scope isn't modified, but is disposed and rebuilt. Any dependencies that were resolved from a removed scope will also be disposed. You will need to account for this in your application. Depending on your architecture, it may require users to re-login or some other form of soft reset.

If you do not configure a tenant lifetime scope for a tenant but resolve a tenant-specific dependency for that tenant, the lifetime scope will be implicitly created for you.

You may explicitly create and configure a tenant lifetime scope using the ConfigureTenant(Object, ActionContainerBuilder) method. If you need to perform some logic and build up the configuration for a tenant, you can do that using a ConfigurationActionBuilder.

See Also