Uploaded by Çağatay Durna

Constructor%2C+Method%2C+Field+and+Property+injection

advertisement
Constructor, Method,
Field and Property
injection
Injection types:
- Constructor
- Field
- Property
- Method
Field Injection
public class Player
{
[Inject] private Health _health;
[Inject] private Inventory _inventory;
}
Property Injection
public class Player
{
[Inject] private Health _health { get; set; }
[Inject] private Inventory _inventory { get; set; }
}
Method Injection
public class Player
{
private Health _health;
private Inventory _inventory;
[Inject]
public void Construct(Health health, Inventory inventory)
{
_health = health;
_inventory = inventory;
}
}
Method Injection
public class Player
{
private Health _health;
private Inventory _inventory;
[Inject]
public IEnumerator Construct(Health health, Inventory inventory)
{
_health = health;
_inventory = inventory;
}
}
Static field injection
public class Player
{
private static Health _health;
private Inventory _inventory;
[Inject]
public void Construct(Health health, Inventory inventory)
{
_health = health;
_inventory = inventory;
}
}
Download