Skip to content

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

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

UModules/UService

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:

ServiceLocator.RegisterService<IService>(myServiceInstance);

For lazy instantiation:

ServiceLocator.RegisterService<IService>();

Retrieving a Service 🔍

var myService = ServiceLocator.GetService<IService>();

Unregistering a Service 🧹

ServiceLocator.UnregisterService<IService>();

Example 💡

Here is a simple usage example:

// Register a new service
ServiceLocator.RegisterService<MyService>();

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

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

License 📄

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing 🤝

Contributions are welcome! Please submit a pull request or open an issue for discussion.

About

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

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages