C# Class Catel.IoC.ServiceLocator

Default implementation of the IServiceLocator interface.
Inheritance: IServiceLocator
Exibir arquivo Open project: Catel/Catel Class Usage Examples

Private Properties

Property Type Description
CompleteTypeRequestPathIfRequired void
CreateServiceInstance object
IServiceProvider object
RegisterInstance void
RegisterType void
ResolveTypeFromKnownContainer object
ThrowTypeNotRegisteredException void

Public Methods

Method 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

Method 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 method

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
return bool

Dispose() public method

Disposes this instance and all registered instances.
public Dispose ( ) : void
return void

GetRegistrationInfo() public method

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.
return Catel.IoC.RegistrationInfo

IsTypeRegistered() public method

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.
return bool

IsTypeRegisteredAsSingleton() public method

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.
return bool

RegisterInstance() public method

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.
return void

RegisterType() public method

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.
return void

RegisterType() public method

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.
return void

RemoveAllTypes() public method

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.
return void

RemoveType() public method

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.
return void

ResolveAllTypes() public method

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[]
return object[]

ResolveType() public method

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.
return object

ResolveTypes() public method

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.
return IEnumerable

ServiceLocator() public method

Initializes a new instance of the ServiceLocator class.
public ServiceLocator ( ) : System
return System