Service Injection 101 Here is a quick showcase of how easily a service can be injected to a component: Service.cs: using Sisus.Init; using UnityEngine; [Service] class Service { public void Greet() => Debug.Log(“Hello, World!”); } Client.cs: using Sisus.Init; class Client : MonoBehaviour<Service> { protected override void Init(Service service) => service.Greet(); } You can test the ..
Category : 03. Getting Started
AddComponent with Arguments A new component that derives from MonoBehaviour<T…> or implements IInitializable<T…> can be attached to GameObject and initialized with arguments using the AddComponent<TComponent, T…> extension methods in the Sisus.Init namespace. The methods work just like the built-in AddComponent<T> methods, except you also list the types of the component’s Init parameters as generic type ..
What Is Dependency Injection Creating new components using the base classes in Init(args) is very similar to how it would work normally in Unity. The key difference is how the component obtains references to other objects that it depends on (its dependencies). Instead of components manually retrieving their dependencies using various methods like GameObject.Find, FindObjectOfType, ..