Menu
VContainer
Getting Startedv1.4.4GitHub
VContainer
  • Getting Started
  • v1.4.4
  • GitHub
  • ABOUT
    • What is VContainer
    • What is DI ?
  • GETTING STARTED
    • Installation
    • Hello World
  • RESOLVING
    • Constructor Injection
    • Method Injection
    • Property / Field Injection
    • Auto inject GameObject in the scene
    • Implicit Relationship Types
    • Use Container Directory
  • REGISTERING
    • Register Type
    • Register Factory
    • Register MonoBehaviour
    • ScriptableObject Integration
    • Register Callbacks
  • SCOPING
    • Lifetime Overview
    • Loading additional child scope via scene or prefab
    • Generate child scope with code first
    • Project root LifetimeScope
  • UNITY INTEGRATION
    • Dispatching Unity's Lifecycle events
    • Integrating with ECS (beta)
  • OPTIMIZATION
    • Pre IL Code Generation
    • Async Container Build
    • Parallel Container Build
  • Comparing to other libraries
    • Zenject

Property / Field Injection

If the object has a local default and Inject is optional, Property/Field Injection can be used.

class ClassA
{
[Inject]
IServiceA serviceA { get; set; } // Will be overwritten if something is registered.
public ClassA()
{
serviceA = ServiceA.GoodLocalDefault;
}
}

It can resolve like this:

[Inject]
IServiceA serviceA;
Edit this page
Previous
Method Injection
Next
Auto inject GameObject in the scene