While learning Unity (DI framework in C#
) I came across a situation where one class has a setter injection of ClassB
class ClassA :
I agree with @Haney that this is a code smell, but it is technically possible...
Just change one of the referenced types to be resolved via Lazy
. Then it does not actually resolve that type until it is used which will break out of the infinite recursion loop.
i.e.
class ClassB : IClassB
{
...
[InjectionConstructor]
public ClassB(Lazy classA)
{
_classA = classA;
}
}