Class AmbientServices
Provides the global ambient services.
Implements
Inherited Members
Namespace: Kephas
Assembly: Kephas.Core.dll
Syntax
public class AmbientServices : Expando, IAmbientServices, IExpando, IDynamicMetaObjectProvider, IIndexable, IServiceProvider, IAppServiceInfoProvider
Remarks
It is a recommended practice to not use global services, instead get the services using the composition (the classical example is the unit testing, where the classes should be sandboxed as much as possible). However, there may be cases when this cannot be avoided, such as static classes or classes which get instantiated outside of the developer's control (like in the case of the entities instatiated by the ORMs). Those are cases where the AmbientServices can be safely used.
Constructors
| Improve this Doc View SourceAmbientServices(Boolean)
Initializes a new instance of the AmbientServices class.
Declaration
public AmbientServices(bool registerDefaultServices = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | registerDefaultServices | Optional. True to register default services. |
Properties
| Improve this Doc View SourceAppRuntime
Gets the application runtime.
Declaration
public IAppRuntime AppRuntime { get; }
Property Value
Type | Description |
---|---|
IAppRuntime | The application runtime. |
AssemblyLoader
Gets the assembly loader.
Declaration
public IAssemblyLoader AssemblyLoader { get; }
Property Value
Type | Description |
---|---|
IAssemblyLoader | The assembly loader. |
CompositionContainer
Gets the composition container.
Declaration
public ICompositionContext CompositionContainer { get; }
Property Value
Type | Description |
---|---|
ICompositionContext | The composition container. |
ConfigurationStore
Gets the configuration store.
Declaration
public IConfigurationStore ConfigurationStore { get; }
Property Value
Type | Description |
---|---|
IConfigurationStore | The configuration store. |
Instance
Gets or sets the static instance of the ambient services.
Declaration
public static IAmbientServices Instance { get; set; }
Property Value
Type | Description |
---|---|
IAmbientServices | The instance. |
Remarks
Setting the globally available instance must be executed before getting its value for the first time, otherwise it will be initialized with the default instance.
LogManager
Gets the log manager.
Declaration
public ILogManager LogManager { get; }
Property Value
Type | Description |
---|---|
ILogManager | The log manager. |
Methods
| Improve this Doc View SourceGetAppServiceInfos(IList<Type>, ICompositionRegistrationContext)
Gets the application service infos in this collection.
Declaration
public IEnumerable<(Type contractType, IAppServiceInfo appServiceInfo)> GetAppServiceInfos(IList<Type> candidateTypes, ICompositionRegistrationContext registrationContext)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.Type> | candidateTypes | List of types of the candidates. |
ICompositionRegistrationContext | registrationContext | Context for the registration. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.ValueTuple<System.Type, IAppServiceInfo>> | An enumerator that allows foreach to be used to process the application service infos in this collection. |
GetService(Type)
Gets the service object of the specified type.
Declaration
public object GetService(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | An object that specifies the type of service object to get. |
Returns
Type | Description |
---|---|
System.Object | A service object of type |
IsRegistered(Type)
Gets a value indicating whether the service with the provided contract is registered.
Declaration
public bool IsRegistered(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of the service. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Register(Type, Action<IServiceRegistrationBuilder>)
Registers the provided service using a registration builder.
Declaration
public virtual IAmbientServices Register(Type serviceType, Action<IServiceRegistrationBuilder> builder)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of the service. |
System.Action<IServiceRegistrationBuilder> | builder | The builder. |
Returns
Type | Description |
---|---|
IAmbientServices | The IAmbientServices. |