Init(args) v1.2.0

Version v1.2.0Link 1 | Link 2 | Link 3


Init(args) is a Dependency Injection solution for Unity, designed from the ground up to seamlessly blend in with the traditional Unity workflow that you are well-acquainted with.

What is Init(args)?
Init(args) is a dependency injection framework for Unity, built with a keen focus on ensuring all aspects of the toolset blend in seamlessly with the native editor experience.

What problems does Init(args) solve?
The Unity Editor’s scene-based workflow is a powerful tool, and the ability to drag-and-drop references to fields in the Inspector is already a great foundation for injecting dependencies to Objects! As such, the aim with Init(args) has not been to reinvent the wheel on this front, but rather to fix various shortcomings it has and unlock its full potential.

In vanilla Unity, all components are responsible for finding references to the objects they depend on. One way to accomplish this is by adding serialized fields, which enables users to assign references using the Inspector. As cool as this is, it has its limitations, and can’t be used in every situation:

Can’t assign Objects to interface fields.
Can’t assign Objects across scenes or prefabs.
Dragging the same managers to components again and again is laborious.
To swap a manager to a different one you have to manually update references in all components.
Can’t assign dynamic values, which makes working with things like localized texts, addressable assets and randomized values more difficult.

Due to these limitations, components often have to combine the usage of serialized fields with other means of resolving dependencies: singletons, GetComponent, GetComponentInChildren, FindObjectOfType, FindWithTag, static methods… and so on. This hodgepodge way of fetching the dependencies of components also has its own problems:
It can add a lot of unnecessary noise to your components’ code.
Dependencies can be hidden anywhere within the code.
Dependencies are usually hardwired to specific classes.
Dependencies are located using hardwired search methods.
And even where you are able to piece together a relatively dignified component using some combination of these methods, it will still most likely be virtually impossible to write any unit tests for it!

Keeping It Simple
With Init(args) you won’t have to spend large amounts of time learning about perplexing concepts, like bindings, containers, decorators or contexts… in fact, you can use just the Inspector to fulfill most of your dependency injection needs! – but with so much more flexibility than ever before.
And what about when you do want to initialize objects with arguments in code? Here as well, you can make use of all the commands you are already familiar with, like AddComponent and Instantiate – just with the added ability to pass in some arguments.
This small but significant change means that your components are no longer closed islands, black boxes with hidden dependencies; when you instantiate a component with its dependencies, you can feel assured that it will work. This also means that writing unit testing for your components becomes so frictionless and easy, that creating them can become downright addictive!

Pure Dependency Injection
The main focus of Init(args) is on enabling pure dependency injection, both with the Inspector for scene objects and prefabs, as well as in code. What this means is that reflection is used as sparingly as possible, and instead generic methods and interfaces are used to provide a strongly typed pathways through which dependencies can be delivered.
This approach has various benefits, such as solid performance compared to reflection-based solutions, and user errors being caught as early as possible at compile-time – and this fail-fast design is also in effect on the Editor side, with warnings being logged to the Console about any missing arguments detected in your scenes in edit mode.
The use of pure dependency injection can also help a lot with the legibility of your project; dependencies between objects are not obfuscated, and you can easily follow the trail of dependency breadcrumbs both in your IDE and in the Editor – a vital ability to have when debugging your application.

Just a Pinch of Magic Sprinkled On Top…
In addition to Init(args) offering all the tools you’ll ever need for pure dependency injection in Unity, there’s also a powerful system that can be used to, as if by magic, create shared instances of select classes and automatically deliver them to clients everywhere (or, if you so choose, limited to certain scenes or transform hierarchies).


There are no reviews yet.

Be the first to review “Init(args) v1.2.0”

Your email address will not be published. Required fields are marked *

Shopping Cart
AdBlocker Image

Please disable Ad Blockers
Looks like you're using an ad blocker or popup blocker. We rely on advertising to help fund our site.