C# Class Catel.IoC.ServiceLocator

Default implementation of the IServiceLocator interface.
Inheritance: IServiceLocator
Afficher le fichier Open project: Catel/Catel Class Usage Examples

Private Properties

Свойство Type Description
CompleteTypeRequestPathIfRequired void
CreateServiceInstance object
IServiceProvider object
RegisterInstance void
RegisterType void
ResolveTypeFromKnownContainer object
ThrowTypeNotRegisteredException void

Méthodes publiques

Méthode Description
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.

Private Methods

Méthode Description
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.

Method Details

AreAllTypesRegistered() public méthode

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
Résultat bool

Dispose() public méthode

Disposes this instance and all registered instances.
public Dispose ( ) : void
Résultat void

GetRegistrationInfo() public méthode

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.
Résultat Catel.IoC.RegistrationInfo

IsTypeRegistered() public méthode

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.
Résultat bool

IsTypeRegisteredAsSingleton() public méthode

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.
Résultat bool

RegisterInstance() public méthode

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.
Résultat void

RegisterType() public méthode

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.
Résultat void

RegisterType() public méthode

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.
Résultat void

RemoveAllTypes() public méthode

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.
Résultat void

RemoveType() public méthode

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.
Résultat void

ResolveAllTypes() public méthode

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[]
Résultat object[]

ResolveType() public méthode

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.
Résultat object

ResolveTypes() public méthode

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.
Résultat IEnumerable

ServiceLocator() public méthode

Initializes a new instance of the ServiceLocator class.
public ServiceLocator ( ) : System
Résultat System