Learning Zenject: Injection Patterns

In this video we’ll talk about the 4 Zenject injection patterns used for dependency mapping.

An injection is the passing of a dependency to a dependent object. Dependency Injection (DI) frameworks, such as Zenject, automate injections using an Inversion of Control (Ioc) Container.

The Container is responsible for filling all of the dependencies in your application. But you have to tell it how to create the objects that it needs to inject.

As a result, you need to create binding statements that contain instructions for object creation. These instructions can hold information about type, scope, state, and much more.

But how does the Container know where to inject the objects that it creates?

This is where the 4 Zenject injection patterns come in.

Zenject Injection Patterns

An injection pattern is a way of telling the Container that it needs to inject an object into a class.

A class can contain one or more types on injection patterns simultaneously. The Container will iterate through and try to fulfill the dependency for each type.

The 4 Zenject patterns are constructor injection, field injection, property injection, and method injection.

While each type has it’s pros and cons, learning all 4 Zenject injection patterns will help you choose the right one for each situation.


Continue learning Zenject with my series, beginning with Getting Started with Zenject.