Class Composition
Represents a composition.
Inheritance
Namespace: Umbraco.Core.Composing
Assembly: Umbraco.Core.dll
Syntax
public class Composition : IRegister
Remarks
Although a composition exposes the application's service container, people should use the
extension methods (such as PropertyEditors()
or SetPublishedContentModelFactory()
) and
avoid accessing the container. This is because everything needs to be properly registered and with
the proper lifecycle. These methods will take care of it. Directly registering into the container
may cause issues.
Constructors
View SourceComposition(IRegister, TypeLoader, IProfilingLogger, IRuntimeState, Configs)
Initializes a new instance of the Composition class.
Declaration
public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs = null)
Parameters
Type | Name | Description |
---|---|---|
IRegister | register | A register. |
TypeLoader | typeLoader | A type loader. |
IProfilingLogger | logger | A logger. |
IRuntimeState | runtimeState | The runtime state. |
Configs | configs | Optional configs. |
Properties
View SourceConcrete
Gets the concrete container.
Declaration
public object Concrete { get; }
Property Value
Type | Description |
---|---|
System.Object |
Configs
Gets the configurations.
Declaration
public Configs Configs { get; }
Property Value
Type | Description |
---|---|
Configs |
Logger
Gets the logger.
Declaration
public IProfilingLogger Logger { get; }
Property Value
Type | Description |
---|---|
IProfilingLogger |
OnCreatingFactory
Gets a dictionary of action to execute when creating the factory.
Declaration
public Dictionary<string, Action> OnCreatingFactory { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Action> |
RuntimeState
Gets the runtime state.
Declaration
public IRuntimeState RuntimeState { get; }
Property Value
Type | Description |
---|---|
IRuntimeState |
TypeLoader
Gets the type loader.
Declaration
public TypeLoader TypeLoader { get; }
Property Value
Type | Description |
---|---|
TypeLoader |
Methods
View SourceConfigureForWeb()
Configures the container for web support.
Declaration
public void ConfigureForWeb()
Remarks
Enables support for MVC, WebAPI, but not per-request scope. This is used early in the boot process, where anything "scoped" should not be linked to a web request.
CreateFactory()
Creates the factory.
Declaration
public IFactory CreateFactory()
Returns
Type | Description |
---|---|
IFactory |
Register(Type, Object)
Registers a service with an implementing instance.
Declaration
public void Register(Type serviceType, object instance)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | |
System.Object | instance |
Register(Type, Type, Lifetime)
Registers a service with an implementation type.
Declaration
public void Register(Type serviceType, Type implementingType, Lifetime lifetime = Lifetime.Transient)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | |
System.Type | implementingType | |
Lifetime | lifetime |
Register(Type, Lifetime)
Registers a service as its own implementation.
Declaration
public void Register(Type serviceType, Lifetime lifetime = Lifetime.Transient)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | |
Lifetime | lifetime |
Register<TService>(Func<IFactory, TService>, Lifetime)
Registers a service with an implementation factory.
Declaration
public void Register<TService>(Func<IFactory, TService> factory, Lifetime lifetime = Lifetime.Transient)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Func<IFactory, TService> | factory | |
Lifetime | lifetime |
Type Parameters
Name | Description |
---|---|
TService |
RegisterAuto(Type)
Registers a base type for auto-registration.
Declaration
public void RegisterAuto(Type serviceBaseType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceBaseType |
Remarks
Auto-registration means that anytime the container is asked to create an instance
of a type deriving from serviceBaseType
, it will first register that
type automatically.
This can be used for instance for views or controllers. Then, one just needs to register a common base class or interface, and the container knows how to create instances.
RegisterFor<TService, TTarget>(TService)
Registers a service for a target, with an implementing instance.
Declaration
public void RegisterFor<TService, TTarget>(TService instance)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
TService | instance |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
There can only be one implementation or instanced registered for a service and target; what happens if many are registered is not specified.
RegisterFor<TService, TTarget>(Func<IFactory, TService>, Lifetime)
Registers a service for a target, with an implementation factory.
Declaration
public void RegisterFor<TService, TTarget>(Func<IFactory, TService> factory, Lifetime lifetime = Lifetime.Transient)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Func<IFactory, TService> | factory | |
Lifetime | lifetime |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
There can only be one implementation or instanced registered for a service and target; what happens if many are registered is not specified.
RegisterFor<TService, TTarget>(Type, Lifetime)
Registers a service for a target, with an implementation type.
Declaration
public void RegisterFor<TService, TTarget>(Type implementingType, Lifetime lifetime = Lifetime.Transient)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Type | implementingType | |
Lifetime | lifetime |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
There can only be one implementation or instanced registered for a service and target; what happens if many are registered is not specified.
RegisterFor<TService, TTarget>(Lifetime)
Registers a service for a target, as its own implementation.
Declaration
public void RegisterFor<TService, TTarget>(Lifetime lifetime = Lifetime.Transient)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
Lifetime | lifetime |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
There can only be one implementation or instanced registered for a service and target; what happens if many are registered is not specified.
RegisterUnique(Type)
Registers a unique service as its own implementation.
Declaration
public void RegisterUnique(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUnique(Type, Object)
Registers a unique service with an implementing instance.
Declaration
public void RegisterUnique(Type serviceType, object instance)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | |
System.Object | instance |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUnique(Type, Type)
Registers a unique service with an implementation type.
Declaration
public void RegisterUnique(Type serviceType, Type implementingType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | |
System.Type | implementingType |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUnique<TService>(Func<IFactory, TService>)
Registers a unique service with an implementation factory.
Declaration
public void RegisterUnique<TService>(Func<IFactory, TService> factory)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Func<IFactory, TService> | factory |
Type Parameters
Name | Description |
---|---|
TService |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUniqueFor<TService, TTarget>()
Registers a unique service for a target, as its own implementation.
Declaration
public void RegisterUniqueFor<TService, TTarget>()
where TService : class
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUniqueFor<TService, TTarget>(TService)
Registers a unique service for a target, with an implementing instance.
Declaration
public void RegisterUniqueFor<TService, TTarget>(TService instance)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
TService | instance |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUniqueFor<TService, TTarget>(Func<IFactory, TService>)
Registers a unique service for a target, with an implementation factory.
Declaration
public void RegisterUniqueFor<TService, TTarget>(Func<IFactory, TService> factory)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Func<IFactory, TService> | factory |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
RegisterUniqueFor<TService, TTarget>(Type)
Registers a unique service for a target, with an implementing type.
Declaration
public void RegisterUniqueFor<TService, TTarget>(Type implementingType)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Type | implementingType |
Type Parameters
Name | Description |
---|---|
TService | |
TTarget |
Remarks
Unique services have one single implementation, and a Singleton lifetime.
WithCollectionBuilder<TBuilder>()
Gets a collection builder (and registers the collection).
Declaration
public TBuilder WithCollectionBuilder<TBuilder>()
where TBuilder : ICollectionBuilder, new()
Returns
Type | Description |
---|---|
TBuilder | The collection builder. |
Type Parameters
Name | Description |
---|---|
TBuilder | The type of the collection builder. |