Show / Hide Table of Contents

Class ServiceLocator

The Service Locator patter. This pattern gives you a simple way to decouple dependencies. There are a lot props and cons about this patters but it's up to you to decide, if this pattern fits your project. Few articles we think it worth reading before using this pattern.

  • Service Locator is an Anti-Pattern
  • Service Locator is NOT an Anti-Pattern
Inheritance
System.Object
ServiceLocator
Implements
IServiceLocator
IReadOnlyServiceLocator
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StansAssets.Foundation.Patterns
Assembly: cs.temp.dll.dll
Syntax
public sealed class ServiceLocator : IServiceLocator, IReadOnlyServiceLocator
Remarks

An implementation of the IServiceLocator pattern.

Methods

Clear()

Unregisters all the registered services in the current container.

Declaration
public void Clear()

Get(Type)

Gets the service instance of the given type.

Declaration
public object Get(Type type)
Parameters
Type Name Description
System.Type type

The type of the service to lookup.

Returns
Type Description
System.Object

The service instance.

Get<T>()

Gets the service instance of the given type.

Declaration
public T Get<T>()
Returns
Type Description
T

The service instance.

Type Parameters
Name Description
T

The type of the service to lookup.

IsRegistered(Type)

Check if service is registered for a given type.

Declaration
public bool IsRegistered(Type type)
Parameters
Type Name Description
System.Type type

The type of the service to lookup.

Returns
Type Description
System.Boolean

Returns true if service is registered and false otherwise.

IsRegistered<T>()

Check if service is registered for a given type.

Declaration
public bool IsRegistered<T>()
Returns
Type Description
System.Boolean

Returns true if service is registered and false otherwise.

Type Parameters
Name Description
T

The type of the service to lookup.

Register(Type, Object)

Registers the service with the current service locator.

Declaration
public void Register(Type type, object service)
Parameters
Type Name Description
System.Type type

Service type.

System.Object service

Service instance.

Register<T>(T)

Registers the service with the current service locator.

Declaration
public void Register<T>(T service)
Parameters
Type Name Description
T service

Service instance.

Type Parameters
Name Description
T

Service type.

Unregister(Type)

Unregisters the service from the current service locator.

Declaration
public void Unregister(Type type)
Parameters
Type Name Description
System.Type type

Service type.

Unregister<T>()

Unregisters the service from the current service locator.

Declaration
public void Unregister<T>()
Type Parameters
Name Description
T

Service type.

Implements

IServiceLocator
IReadOnlyServiceLocator
In This Article
Back to top Generated by DocFX