C
C#14mo ago
Theos

❔ Unity Zenject qustion

Hey, I have a question about Zenject. So I have a class
public class Test
{
public Something _Smth;
public Foo _Foo;
private int Id;

public Test(Somethnig smth, Foo foo)
{
_Smth = smth;
_Foo = foo;
}
}
public class Test
{
public Something _Smth;
public Foo _Foo;
private int Id;

public Test(Somethnig smth, Foo foo)
{
_Smth = smth;
_Foo = foo;
}
}
and I install it like this
Container.RegisterNewInstance<Foo>();
Container.RegisterNewInstance<Something>();
Container.RegisterNewInstance<Foo>();
Container.RegisterNewInstance<Something>();
then I have a list List<Test> Tests What I want to do is somehow make a for-loop that will create and add Test to Tests list. I want to make sure that _Smth and _Foo are installed using Zenject and I want to pass Id when I create this object. From my understanding of zenject if i do var test = new Test() it wont work cuz Something and Foo wont be installed right?
2 Replies
Theos
Theos14mo ago
can I do something like
public class Test
{
[Inject] public Something _Smth;
[Inject] public Foo _Foo;
private int Id;

public Test(int id)
{
Id = id;
}
}
public class Test
{
[Inject] public Something _Smth;
[Inject] public Foo _Foo;
private int Id;

public Test(int id)
{
Id = id;
}
}
var test = new Test(1)
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server