Menu
VContainer
Getting Startedv1.7.2GitHub
VContainer
  • Getting Started
  • v1.7.2
  • GitHub
  • ABOUT
    • What is VContainer
    • What is DI ?
  • Getting Started
    • Installation
    • Hello World
  • Resolving
    • Constructor Injection
    • Method Injection
    • Property/Field Injection
    • MonoBehaviour
  • Registering
    • Register Plain C# Type
    • Register Factory
    • Register MonoBehaviour
    • Register ScriptableObject
    • Register Callbacks
  • Integrations
    • Plain C# Entry point
    • UniTask
    • UniRx
    • ECS (beta)
  • Scoping
    • Lifetime Overview
    • Generate child scope via scene or prefab
    • Generate child scope with code first
    • Project root LifetimeScope
  • Container API
    • Use Container Directory
    • Implicit Relationship Types
  • 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
Inject into MonoBehaviour