An open API service indexing awesome lists of open source software.

https://github.com/umodules/uservice

A lightweight service locator utility for Unity to register, manage, and retrieve services, including MonoBehaviour.
https://github.com/umodules/uservice

dependency-injection monobehaviour service-locator unity

Last synced: about 2 months ago
JSON representation

A lightweight service locator utility for Unity to register, manage, and retrieve services, including MonoBehaviour.

Awesome Lists containing this project

README

          

# UService ๐Ÿš€
UService is a lightweight service locator utility for Unity, designed to manage and retrieve service instances efficiently. The tool allows for the easy registration, retrieval, and management of services, including `MonoBehaviour` services which must be attached to `GameObject`.

## Features โœจ
* ๐Ÿ”ง **Service Registration:** Register services either by providing an instance or through lazy instantiation.
* ๐ŸŽฎ **MonoBehaviour Management:** Handles `MonoBehaviour` services by attaching them to Unity `GameObjects`.
* ๐Ÿ” **Service Retrieval:** Retrieve registered services with lazy instantiation.
* ๐Ÿงน **Unregister Services:** Clean up services when they are no longer needed.

## Installation ๐Ÿ“ฆ
* Clone or download the repository.
* Add the `ServiceLocator` script to your Unity project.
* Make sure the namespace `UService` is referenced in your code.

## Usage ๐Ÿš€
### Registering a Service ๐Ÿ› ๏ธ
To register an existing instance of a service:
```C#
ServiceLocator.RegisterService(myServiceInstance);
```
For lazy instantiation:
```C#
ServiceLocator.RegisterService();
```

### Retrieving a Service ๐Ÿ”
```C#
var myService = ServiceLocator.GetService();
```

### Unregistering a Service ๐Ÿงน
```C#
ServiceLocator.UnregisterService();
```
## Example ๐Ÿ’ก
Here is a simple usage example:
```C#
// Register a new service
ServiceLocator.RegisterService();

// Retrieve the registered service
MyService service = ServiceLocator.GetService();

// Unregister the service when it's no longer needed
ServiceLocator.UnregisterService();
```

## License ๐Ÿ“„
This project is licensed under the MIT License. See the [LICENSE](https://github.com/UModules/UService/blob/main/LICENSE) file for details.

## Contributing ๐Ÿค
Contributions are welcome! Please submit a pull request or open an issue for discussion.