C# Класс Catel.IoC.ServiceLocator

Default implementation of the IServiceLocator interface.
Наследование: IServiceLocator
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
CompleteTypeRequestPathIfRequired void
CreateServiceInstance object
IServiceProvider object
RegisterInstance void
RegisterType void
ResolveTypeFromKnownContainer object
ThrowTypeNotRegisteredException void

Открытые методы

Метод Описание
AreAllTypesRegistered ( ) : bool

Determines whether all the specified types are registered with the service locator.

Note that this method is written for optimalization by the TypeFactory. This means that the TypeFactory does not need to call the ServiceLocator several times to construct a single type using dependency injection. Only use this method if you know what you are doing, otherwise use the IsTypeRegistered instead.

Dispose ( ) : void

Disposes this instance and all registered instances.

GetRegistrationInfo ( Type serviceType, object tag = null ) : Catel.IoC.RegistrationInfo

Gets the registration info about the specified type.

IsTypeRegistered ( Type serviceType, object tag = null ) : bool

Determines whether the specified service type is registered.

Note that the actual implementation lays in the hands of the IoC technique being used.

IsTypeRegisteredAsSingleton ( Type serviceType, object tag = null ) : bool

Determines whether the specified service type is registered as singleton.

RegisterInstance ( Type serviceType, object instance, object tag = null ) : void

Registers a specific instance of a service.

RegisterType ( Type serviceType, object>.Func createServiceFunc, object tag = null, RegistrationType registrationType = RegistrationType.Singleton, bool registerIfAlreadyRegistered = true ) : void

Registers an implementation of a service using a create type callback, but only if the type is not yet registered.

Note that the actual implementation lays in the hands of the IoC technique being used.

RegisterType ( Type serviceType, Type serviceImplementationType, object tag = null, RegistrationType registrationType = RegistrationType.Singleton, bool registerIfAlreadyRegistered = true ) : void

Registers an implementation of a service, but only if the type is not yet registered.

Note that the actual implementation lays in the hands of the IoC technique being used.

RemoveAllTypes ( Type serviceType ) : void

Removes all registered types of a certain service type.

RemoveType ( Type serviceType, object tag = null ) : void

Removes the registered type with the specific tag.

ResolveAllTypes ( ) : object[]

Resolves all the specified types.

Note that this method is written for optimalization by the TypeFactory. This means that the TypeFactory does not need to call the ServiceLocator several times to construct a single type using dependency injection. Only use this method if you know what you are doing, otherwise use the ResolveType instead.

ResolveType ( Type serviceType, object tag = null ) : object

Resolves an instance of the type registered on the service.

Note that the actual implementation lays in the hands of the IoC technique being used.

ResolveTypes ( Type serviceType ) : IEnumerable

Resolves all instances of the type registered on the service.

Note that the actual implementation lays in the hands of the IoC technique being used.

ServiceLocator ( ) : System

Initializes a new instance of the ServiceLocator class.

Приватные методы

Метод Описание
CompleteTypeRequestPathIfRequired ( Catel.IoC.TypeRequestInfo typeRequestInfoForTypeJustConstructed ) : void

Completes the type request path by checking if the currently created type is the same as the first type meaning that the type is successfully created and the current type request path can be set to null.

CreateServiceInstance ( Catel.IoC.ServiceLocatorRegistration registration ) : object

Creates the service instance.

IServiceProvider ( Type serviceType ) : object

Gets the service object of the specified type.

RegisterInstance ( Type serviceType, object instance, object tag, object originalContainer ) : void

Registers a specific instance of an service.

RegisterType ( Type serviceType, Type serviceImplementationType, object tag, RegistrationType registrationType, bool registerIfAlreadyRegistered, object originalContainer, object>.Func createServiceFunc ) : void

Registers the specific implementing type for the service type.

ResolveTypeFromKnownContainer ( Type serviceType, object tag ) : object

Resolves the type from a known container.

ThrowTypeNotRegisteredException ( Type type, string message = null ) : void

Throws the TypeNotRegisteredException but will also reset the current type request path.

Описание методов

AreAllTypesRegistered() публичный Метод

Determines whether all the specified types are registered with the service locator.
Note that this method is written for optimalization by the TypeFactory. This means that the TypeFactory does not need to call the ServiceLocator several times to construct a single type using dependency injection. Only use this method if you know what you are doing, otherwise use the IsTypeRegistered instead.
The is null.
public AreAllTypesRegistered ( ) : bool
Результат bool

Dispose() публичный Метод

Disposes this instance and all registered instances.
public Dispose ( ) : void
Результат void

GetRegistrationInfo() публичный Метод

Gets the registration info about the specified type.
The is null.
public GetRegistrationInfo ( Type serviceType, object tag = null ) : Catel.IoC.RegistrationInfo
serviceType System.Type Type of the service.
tag object The tag the service is registered with. The default value is null.
Результат Catel.IoC.RegistrationInfo

IsTypeRegistered() публичный Метод

Determines whether the specified service type is registered.
Note that the actual implementation lays in the hands of the IoC technique being used.
The is null.
public IsTypeRegistered ( Type serviceType, object tag = null ) : bool
serviceType System.Type The type of the service.
tag object The tag to register the service with. The default value is null.
Результат bool

IsTypeRegisteredAsSingleton() публичный Метод

Determines whether the specified service type is registered as singleton.
public IsTypeRegisteredAsSingleton ( Type serviceType, object tag = null ) : bool
serviceType System.Type The service type.
tag object The tag to register the service with. The default value is null.
Результат bool

RegisterInstance() публичный Метод

Registers a specific instance of a service.
The is null. The is null. The is not of the right type.
public RegisterInstance ( Type serviceType, object instance, object tag = null ) : void
serviceType System.Type Type of the service.
instance object The instance.
tag object The tag to register the service with. The default value is null.
Результат void

RegisterType() публичный Метод

Registers an implementation of a service using a create type callback, but only if the type is not yet registered.
Note that the actual implementation lays in the hands of the IoC technique being used.
If is null. If is null.
public RegisterType ( Type serviceType, object>.Func createServiceFunc, object tag = null, RegistrationType registrationType = RegistrationType.Singleton, bool registerIfAlreadyRegistered = true ) : void
serviceType System.Type The type of the service.
createServiceFunc object>.Func The create service function.
tag object The tag to register the service with. The default value is null.
registrationType RegistrationType The registration type. The default value is .
registerIfAlreadyRegistered bool If set to true, an older type registration is overwritten by this new one.
Результат void

RegisterType() публичный Метод

Registers an implementation of a service, but only if the type is not yet registered.
Note that the actual implementation lays in the hands of the IoC technique being used.
If is null. If is null.
public RegisterType ( Type serviceType, Type serviceImplementationType, object tag = null, RegistrationType registrationType = RegistrationType.Singleton, bool registerIfAlreadyRegistered = true ) : void
serviceType System.Type The type of the service.
serviceImplementationType System.Type The type of the implementation.
tag object The tag to register the service with. The default value is null.
registrationType RegistrationType The registration type. The default value is .
registerIfAlreadyRegistered bool If set to true, an older type registration is overwritten by this new one.
Результат void

RemoveAllTypes() публичный Метод

Removes all registered types of a certain service type.
The is null.
public RemoveAllTypes ( Type serviceType ) : void
serviceType System.Type The type of the service.
Результат void

RemoveType() публичный Метод

Removes the registered type with the specific tag.
The is null.
public RemoveType ( Type serviceType, object tag = null ) : void
serviceType System.Type The type of the service.
tag object The tag of the registered the service. The default value is null.
Результат void

ResolveAllTypes() публичный Метод

Resolves all the specified types.
Note that this method is written for optimalization by the TypeFactory. This means that the TypeFactory does not need to call the ServiceLocator several times to construct a single type using dependency injection. Only use this method if you know what you are doing, otherwise use the ResolveType instead.
The is null.
public ResolveAllTypes ( ) : object[]
Результат object[]

ResolveType() публичный Метод

Resolves an instance of the type registered on the service.
Note that the actual implementation lays in the hands of the IoC technique being used.
The is null. The type is not found in any container.
public ResolveType ( Type serviceType, object tag = null ) : object
serviceType System.Type The type of the service.
tag object The tag to register the service with. The default value is null.
Результат object

ResolveTypes() публичный Метод

Resolves all instances of the type registered on the service.
Note that the actual implementation lays in the hands of the IoC technique being used.
The is null.
public ResolveTypes ( Type serviceType ) : IEnumerable
serviceType System.Type The type of the service.
Результат IEnumerable

ServiceLocator() публичный Метод

Initializes a new instance of the ServiceLocator class.
public ServiceLocator ( ) : System
Результат System