C
C#9mo ago
Theos

❔ Zenject (Unity) doesn't fire when i do new()

Hey, I have a class which looks like this
public class Something
{
private A _a;

private B _b;

public Something(A a)
{
_a = a;
}

[Inject]
public void Construct(B b)
{
_b = b;
}
public class Something
{
private A _a;

private B _b;

public Something(A a)
{
_a = a;
}

[Inject]
public void Construct(B b)
{
_b = b;
}
public class Test : MonoBehaviour
{

public void Start()
{
var smth = new Something(_a);
}
}
public class Test : MonoBehaviour
{

public void Start()
{
var smth = new Something(_a);
}
}
and _b is null for some reason?
10 Replies
Theos
Theos9mo ago
B is binded, thats for sure
Thinker
Thinker9mo ago
Idk what Zenject is but everything here looks consistent
Thinker
Thinker9mo ago
You're calling the constructor, so only the constructor is being run. There's no magic here.
Theos
Theos9mo ago
nope, zenject should call Construct thats why there is the [Inject] thingy
Thinker
Thinker9mo ago
Does it do IL weaving or something?
Theos
Theos9mo ago
no clue tbh
Thinker
Thinker9mo ago
ah, yeah, looks like it is
Theos
Theos9mo ago
i guess i cant use [Inject] if i'm constructing classes on my own it should either be a MonoBehaviour or a class created using Zenject
Accord
Accord9mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.