Usage.Unity Projects - JuDelCo/Core GitHub Wiki

Service Container Lifecycle (Unity)

To use services you need to register them first. One way you can automatically register the services on runtime is creating this static class anywhere in your project, it will run before any scene so it's the perfect entry point for the services to setup:

using UnityEngine;
using Ju.Services;

public static class Bootstrap
{
	[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
	private static void Init()
	{
		// Core services

		ServiceContainer.RegisterService<ITaskService, TaskService>();
		ServiceContainer.RegisterService<ICoroutineService, CoroutineService>();
		ServiceContainer.RegisterService<ICacheService, CacheService>();

		// Unity related services

		ServiceContainer.RegisterService<ILogUnityService, LogUnityService>();
		ServiceContainer.RegisterService<IInputService, InputUnityService>();
		ServiceContainer.RegisterService<ITimeService, UnityTimeService>();
		ServiceContainer.RegisterService<IUnityService, UnityService>();
		ServiceContainer.RegisterService<IPrefabPoolService, PrefabPoolService>();

		// Register your custom services here
	}
}

You can rename the class and the method to whatever you want.

Read more on how to use the Service Container here.

Alternative (register services manually)

You can register the services in your own entry point method to control whenever the services get registered like it's done in native C# projects. Just keep in mind that the UnityService will fire all the update loop events and dispose the Service Container automatically.