Show / Hide Table of Contents

Class AmbientServices

Provides the global ambient services.

Inheritance
System.Object
System.Dynamic.DynamicObject
ExpandoBase
Expando
AmbientServices
Implements
IAmbientServices
IExpando
System.Dynamic.IDynamicMetaObjectProvider
IIndexable
System.IServiceProvider
IAppServiceInfoProvider
Inherited Members
ExpandoBase.Item[String]
ExpandoBase.GetDynamicMemberNames()
ExpandoBase.HasDynamicMember(String)
ExpandoBase.TryGetMember(GetMemberBinder, Object)
ExpandoBase.TrySetMember(SetMemberBinder, Object)
ExpandoBase.TryInvokeMember(InvokeMemberBinder, Object[], Object)
ExpandoBase.ToDictionary(Func<String, String>, Func<Object, Object>)
ExpandoBase.GetInnerObjectTypeInfo()
ExpandoBase.GetThisTypeInfo()
ExpandoBase.TryGetValue(String, Object)
ExpandoBase.TrySetValue(String, Object)
System.Dynamic.DynamicObject.GetMetaObject(System.Linq.Expressions.Expression)
System.Dynamic.DynamicObject.TryBinaryOperation(System.Dynamic.BinaryOperationBinder, System.Object, System.Object)
System.Dynamic.DynamicObject.TryConvert(System.Dynamic.ConvertBinder, System.Object)
System.Dynamic.DynamicObject.TryCreateInstance(System.Dynamic.CreateInstanceBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryDeleteIndex(System.Dynamic.DeleteIndexBinder, System.Object[])
System.Dynamic.DynamicObject.TryDeleteMember(System.Dynamic.DeleteMemberBinder)
System.Dynamic.DynamicObject.TryGetIndex(System.Dynamic.GetIndexBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryInvoke(System.Dynamic.InvokeBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TrySetIndex(System.Dynamic.SetIndexBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryUnaryOperation(System.Dynamic.UnaryOperationBinder, System.Object)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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 Source

AmbientServices(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 Source

AppRuntime

Gets the application runtime.

Declaration
public IAppRuntime AppRuntime { get; }
Property Value
Type Description
IAppRuntime

The application runtime.

| Improve this Doc View Source

AssemblyLoader

Gets the assembly loader.

Declaration
public IAssemblyLoader AssemblyLoader { get; }
Property Value
Type Description
IAssemblyLoader

The assembly loader.

| Improve this Doc View Source

CompositionContainer

Gets the composition container.

Declaration
public ICompositionContext CompositionContainer { get; }
Property Value
Type Description
ICompositionContext

The composition container.

| Improve this Doc View Source

ConfigurationStore

Gets the configuration store.

Declaration
public IConfigurationStore ConfigurationStore { get; }
Property Value
Type Description
IConfigurationStore

The configuration store.

| Improve this Doc View Source

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.

| Improve this Doc View Source

LogManager

Gets the log manager.

Declaration
public ILogManager LogManager { get; }
Property Value
Type Description
ILogManager

The log manager.

Methods

| Improve this Doc View Source

GetAppServiceInfos(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.

| Improve this Doc View Source

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 serviceType.-or- null if there is no service object of type serviceType.

| Improve this Doc View Source

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

true if the service is registered, false if not.

| Improve this Doc View Source

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.

Implements

IAmbientServices
IExpando
System.Dynamic.IDynamicMetaObjectProvider
IIndexable
System.IServiceProvider
IAppServiceInfoProvider

Extension Methods

AmbientServicesExtensions.GetLogger(IAmbientServices, String)
AmbientServicesExtensions.GetLogger(IAmbientServices, Type)
AmbientServicesExtensions.GetLogger<T>(IAmbientServices)
AmbientServicesExtensions.Register<TService>(IAmbientServices, Action<IServiceRegistrationBuilder>)
AmbientServicesExtensions.Register<TService>(IAmbientServices, TService)
AmbientServicesExtensions.Register<TService, TServiceImplementation>(IAmbientServices)
AmbientServicesExtensions.RegisterTransient<TService, TServiceImplementation>(IAmbientServices)
AmbientServicesExtensions.Register<TService>(IAmbientServices, Func<TService>)
AmbientServicesExtensions.RegisterTransient<TService>(IAmbientServices, Func<TService>)
AmbientServicesExtensions.Register(IAmbientServices, Type, Func<Object>)
AmbientServicesExtensions.RegisterTransient(IAmbientServices, Type, Func<Object>)
AmbientServicesExtensions.Register(IAmbientServices, Type, Object)
AmbientServicesExtensions.Register(IAmbientServices, Type, Type)
AmbientServicesExtensions.RegisterTransient(IAmbientServices, Type, Type)
AmbientServicesExtensions.GetService<TService>(IServiceProvider)
AmbientServicesExtensions.GetRequiredService(IServiceProvider, Type)
AmbientServicesExtensions.GetRequiredService<TService>(IServiceProvider)
AmbientServicesExtensions.WithConfigurationStore(IAmbientServices, IConfigurationStore)
AmbientServicesExtensions.WithLogManager(IAmbientServices, ILogManager)
AmbientServicesExtensions.WithAppRuntime(IAmbientServices, IAppRuntime)
AmbientServicesExtensions.WithCompositionContainer(IAmbientServices, ICompositionContext)
AmbientServicesExtensions.WithCompositionContainer<TContainerBuilder>(IAmbientServices, Action<TContainerBuilder>)
AmbientServicesExtensions.WithLiteCompositionContainer(IAmbientServices, Action<LiteCompositionContainerBuilder>)
DynamicObjectExtensions.SetPropertyValue(Object, String, Object)
DynamicObjectExtensions.TrySetPropertyValue(Object, String, Object)
DynamicObjectExtensions.GetPropertyValue(Object, String)
DynamicObjectExtensions.TryGetPropertyValue(Object, String, out Object)
DynamicObjectExtensions.GetRuntimeTypeInfo(Object)
DynamicObjectExtensions.ToDynamic(Object)
DynamicObjectExtensions.ToExpando(Object)
AmbientServicesApplicationExtensions.WithDynamicAppRuntime(IAmbientServices, Func<AssemblyName, Boolean>, String, String, String, Action<DynamicAppRuntime>)
AmbientServicesApplicationExtensions.WithStaticAppRuntime(IAmbientServices, Func<AssemblyName, Boolean>, String, String, String, Action<StaticAppRuntime>)
BehaviorValue.ToBehaviorValue<TValue>(TValue)
CollectionExtensions.AddRange<T, TItem>(T, IEnumerable<TItem>)
CompositionContextExtensions.ToCompositionContext(IServiceProvider)
ExpandoExtensions.Merge<T>(T, Object)
ExpandoExtensions.GetLaxValue<T>(IIndexable, String, T)
LoggingExtensions.GetLogger(Object, IContext)
TypeExtensions.GetAbstractType(Object)
TypeExtensions.GetAbstractTypeInfo(Object)
ReflectionHelper.GetTypeInfo(Object)
AmbientServicesDebugLogExtensions.WithDebugLogManager(IAmbientServices, Action<String, String, Object, Exception>)
AmbientServicesNLogExtensions.WithNLogManager(IAmbientServices)
AmbientServicesSerilogExtensions.WithSerilogManager(IAmbientServices, LoggerConfiguration)
AmbientServicesLog4NetExtensions.WithLog4NetManager(IAmbientServices)
AmbientServicesAutofacExtensions.WithAutofacCompositionContainer(IAmbientServices, Action<AutofacCompositionContainerBuilder>)
AmbientServicesMefExtensions.WithMefCompositionContainer(IAmbientServices, Action<MefCompositionContainerBuilder>)
AmbientServicesPluginsExtensions.WithPluginsAppRuntime(IAmbientServices, Func<AssemblyName, Boolean>, String, String, String, IExpando, Nullable<Boolean>, String, String)
EntityEntryExtensions.TryGetAttachedEntityEntry(Object)
ConfigurationServiceCollectionExtensions.ConfigureOptionsExtensions(IAmbientServices)
LoggingServiceCollectionExtensions.ConfigureLoggingExtensions(IAmbientServices)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX