Click or drag to resize

ServiceLocator Class

A (somewhat) simple implementation of the service locator pattern. The ServiceLocator knows about MonoBehaviours and how to work with them. Creating scene-specific resolvers that only live as long as their respective scene is also supported.
Remarks
Please note that when you load a new scene, the MonoBehaviours in that scene will have their Awake() method called before their scene becomes the active one. This means you can't rely on SceneManager.GetActiveScene() to return the scene they're in, so you might want to use GameObject.scene to specify which scene to register the resolver for.
Inheritance Hierarchy
SystemObject
  Archon.SwissArmyLib.UtilsServiceLocator

Namespace:  Archon.SwissArmyLib.Utils
Assembly:  Archon.SwissArmyLib (in Archon.SwissArmyLib.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static class ServiceLocator
Request Example View Source

The ServiceLocator type exposes the following members.

Methods
  NameDescription
Public methodStatic memberIsRegisteredT
Checks whether there's registered a resolver for a specific type.
Public methodStatic memberIsRegisteredInSceneT
Checks whether there's registered a scene-specific resolver for a specific type in the currently active scene.
Public methodStatic memberIsRegisteredInSceneT(Scene)
Checks whether there's registered a scene-specific resolver for a specific type in the specified scene.
Public methodStatic memberRegisterLazySingletonT
Registers a concrete singleton of the given type. The instance won't be created until the first time it is resolved.
Public methodStatic memberRegisterLazySingletonTAbstract, TConcrete
Registers a concrete singleton of the type TConcrete for the abstract type TAbstract. The instance won't be created until the first time it is resolved.
Public methodStatic memberRegisterLazySingletonForSceneT
Registers a scene-specific concrete singleton of the given type. The instance won't be created until the first time it is resolved.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterLazySingletonForSceneT(Scene)
Registers a scene-specific concrete singleton of the given type. The instance won't be created until the first time it is resolved.
Public methodStatic memberRegisterLazySingletonForSceneTAbstract, TConcrete
Registers a scene-specific concrete singleton of the type TConcrete for the abstract type TAbstract. The instance won't be created until the first time it is resolved.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterLazySingletonForSceneTAbstract, TConcrete(Scene)
Registers a scene-specific concrete singleton of the type TConcrete for the abstract type TAbstract. The instance won't be created until the first time it is resolved.
Public methodStatic memberRegisterSingletonT
Registers a concrete singleton of the given type.
Public methodStatic memberRegisterSingletonT(T)
Registers a specific instance to be a singleton for its concrete type.
Public methodStatic memberRegisterSingletonTAbstract, TConcrete
Registers a concrete singleton of the type TConcrete for the abstract type TAbstract.
Public methodStatic memberRegisterSingletonTAbstract, TConcrete(TConcrete)
Registers a specific instance to be a singleton for the abstract type.
Public methodStatic memberRegisterSingletonForSceneT
Registers a scene-specific concrete singleton of the given type.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterSingletonForSceneT(T)
Registers a specific instance to be a scene-specific singleton for its concrete type.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterSingletonForSceneT(Scene)
Registers a scene-specific concrete singleton of the given type.
Public methodStatic memberRegisterSingletonForSceneT(T, Scene)
Registers a specific instance to be a scene-specific singleton for its concrete type.
Public methodStatic memberRegisterSingletonForSceneTAbstract, TConcrete
Registers a scene-specific concrete singleton of the type TConcrete for the abstract type TAbstract.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterSingletonForSceneTAbstract, TConcrete(TConcrete)
Registers a specific instance to be a scene-specific singleton for the abstract type.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterSingletonForSceneTAbstract, TConcrete(Scene)
Registers a scene-specific concrete singleton of the type TConcrete for the abstract type TAbstract.
Public methodStatic memberRegisterSingletonForSceneTAbstract, TConcrete(TConcrete, Scene)
Registers a specific instance to be a scene-specific singleton for the abstract type.
Public methodStatic memberRegisterTransientT
Registers a concrete transient type. A new instance of the given type will be returned each time it is resolved.
Public methodStatic memberRegisterTransientT(FuncT)
Registers a concrete transient type to return new instances of when T is resolved. The specified resolver will be used for producing the instances.
Public methodStatic memberRegisterTransientTAbstract, TConcrete
Registers a concrete transient type to return new instances of when the abstract type TAbstract is resolved.
Public methodStatic memberRegisterTransientTAbstract, TConcrete(FuncTConcrete)
Registers a concrete transient type to return new instances of when the abstract type TAbstract is resolved. The specified resolver will be used for producing the instances.
Public methodStatic memberRegisterTransientForSceneT
Registers scene-specific a concrete transient type. A new instance of the given type will be returned each time it is resolved.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterTransientForSceneT(FuncT)
Registers a scene-specific concrete transient type to return new instances of when T is resolved. The specified resolver will be used for producing the instances.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterTransientForSceneT(Scene)
Registers scene-specific a concrete transient type. A new instance of the given type will be returned each time it is resolved.
Public methodStatic memberRegisterTransientForSceneT(FuncT, Scene)
Registers a scene-specific concrete transient type to return new instances of when T is resolved. The specified resolver will be used for producing the instances.
Public methodStatic memberRegisterTransientForSceneTAbstract, TConcrete
Registers a scene-specific concrete transient type to return new instances of when the abstract type TAbstract is resolved.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterTransientForSceneTAbstract, TConcrete(FuncTConcrete)
Registers a scene-specific concrete transient type to return new instances of when the abstract type TAbstract is resolved. The specified resolver will be used for producing the instances.
Remarks
The resolver is registered for the active scene according to GetActiveScene.
Public methodStatic memberRegisterTransientForSceneTAbstract, TConcrete(Scene)
Registers a scene-specific concrete transient type to return new instances of when the abstract type TAbstract is resolved.
Public methodStatic memberRegisterTransientForSceneTAbstract, TConcrete(FuncTConcrete, Scene)
Registers a scene-specific concrete transient type to return new instances of when the abstract type TAbstract is resolved. The specified resolver will be used for producing the instances.
Public methodStatic memberReset
Clears all resolvers.
Public methodStatic memberResetGlobal
Clears global resolvers.
Public methodStatic memberResetScene
Clears the currently active scene's resolvers.
Public methodStatic memberResetScene(Scene)
Clears a specific scene's resolvers.
Public methodStatic memberResetScenes
Clears all scene specific resolvers for all scenes.
Public methodStatic memberResolveT
Locates and returns a transient object or singleton of the specified type. Searches for a global object first, if nothing is found and includeActiveScene is true then it searches for a scene specific resolver. Make sure the type is registered first.
Public methodStatic memberResolveForSceneT
Locates and returns a transient object or singleton of the specified type for the currently active scene. Make sure the type is registered first.
Public methodStatic memberResolveForSceneT(Scene)
Locates and returns a transient object or singleton of the specified type for the given scene. Make sure the type is registered first.
Top
Events
  NameDescription
Public eventStatic memberGlobalReset
Called when the global resolvers are reset.
Public eventStatic memberSceneReset
Called when a scene's resolvers are reset.
Top
See Also