It is used to specify a binded object according to its id. In this way, more than one object from the same class can be binded with different ids. While injecting, the object is resolved according to the specified id.
Copy public class AppInstaller : GameObjectInstaller
{
public override void Install ( DIContainer container)
{
container .Bind < InventoryData > ().WithId( "inventory1" );
container .Bind < InventoryData > ().WithId( "inventory2" );
}
}
public class FooMono : MonoBehaviour
{
[ Inject ( "inventory1" )]
private readonly InventoryData _inventoryDataFirst;
[ Inject ( "inventory2" )]
private readonly InventoryData _inventoryDataSecond;
}
public class Foo
{
private readonly InventoryData _inventoryDataFirst;
private readonly InventoryData _inventoryDataSecond;
public Foo ([ Inject ( "inventory1" )] InventoryData inventoryDataFirst , [ Inject ( "inventory2" )] InventoryData inventoryDataSecond)
{
_inventoryDataFirst = inventoryDataFirst;
_inventoryDataSecond = inventoryDataSecond;
}
}