
Init(args) – A Next-Gen DI Framework – Unity
Init(args) is a next-gen DI framework for Unity, that combines exceptional flexibility with unprecedented ease-of-use.
What Is Init(args)?
Init(args) is a straightforward and type-safe solution for providing your components with all the objects that they depend on.
Here are some reasons why Init(args) could be the ideal choice to power the architecture of your next game…
It’s Simple
Init(args)’s Inspector and attribute-based workflow is incredibly intuitive – the basics can literally be learned in a matter of minutes.
It’s Inspector-Integrated
Services that clients will receive are visualized in the Inspector and support click-to-ping – just like you’re used to with serialized fields!
It’s Dependable
Clients always receive the services they depend on before their Awake event – regardless of whether they’re loaded as part of a scene, instantiated from a prefab, or created using AddComponent.
It’s Debuggable
Forgot to register a service that is required by a client?
Init(args) will guide you to resolve the issue with Inspector help boxes and Console messages.
In Play Mode you can see unserialized state in the Inspector so you can easily spot unreceived services.
Receive services via Init method
public class Player : MonoBehaviour<IInputManager>
{
private IInputManager inputManager;
protected override void Init(IInputManager inputManager)
{
this.inputManager = inputManager;
}
}
Instantiate with arguments
var player = playerPrefab.Instantiate(inputManager);
Add Component with arguments
var player = gameObject.AddComponent<Player, IInputManager>(inputManager);
Create ScriptableObject with arguments
var dialogueAsset = Create.Instance<DialogueAsset, Guid>(id);
new GameObject with arguments
new GameObject<Player, BoxCollider>(“Player”)
.Init1(inputManager, Second.Component);
Register Global Services
[Service(typeof(IInputManager))]
class InputManager : IInputManager
[Service(ResourcePath = “Player”)]
class Player : MonoBehaviour
Wrappers – attach plain old class objects to GameObjects
var player = new Player();
gameObject.AddComponent<PlayerComponent, Player>(player);
Recent Comments