![]() |
Init(args)
Scripting Reference
|
Class that can provide an instance of any class that has the ServiceAttribute on demand.
This is a simple proxy for the static Service<TDefiningClassOrInterface> class; Calling the Get method on any instance of this class will return the shared service instance stored in Service<TDefiningClassOrInterface>.Instance.
A benefit of using ServiceProvider instead of Service<> directly, is the ability to call Get through the IServiceProvider interface. This makes it possible to create mock implementations of the interface for unit tests.
Additionally, it makes it easier to swap your service provider with another implementation at a later time.
A third benefit is that it makes your code less coupled with other classes, making it much easier to port the code over to another project for example.
The ServiceProvider class is a service itself. This means that an instance of the class can be automatically received by any classes that derive from MonoBehaviour<IServiceProvider> or ScriptableObject<IServiceProvider>.
Public Member Functions | |
TDefiningClassOrInterface | Get< TDefiningClassOrInterface > () |
Returns shared instance of TDefiningClassOrInterface service. | |