It would help to see your code... but I think you are not understanding the process here.
At step 4)
, Ninject has just created InternalUserBehavior
and is injecting the properties. In step 5)
, Ninject finds that it needs to create UserRoleService
and proceeds to step 6)
to create and then populate a ModelFactory{UserRole}
.
I assume your classes look something like:
public class UserRoleService
{
public UserRoleService(ModelFactory<UserRole> factory){}
}
public class ModelFactory<T>
{
[Inject]
public IUserRepository UserRepository { get; set; }
}
You definitely have a cyclic dependency, regardless of property injection. You need to resolve the cyclic dependency.
Another route would be to use Lazy<IUserRepository>
with constructor injection to avoid the cyclic dependency. I have an answer that can help with that binding.
Effectively, your ModelFactory<>
becomes:
public class ModelFactory<T>
{
[Inject]
public Lazy<IUserRepository> UserRepository { get; set; }
}