Registry:
container.Register<IAuthenticationHandler, AuthenticationHandler>(Lifestyle.Transient);
container.Register<IUserHandler, UserHandler>(Lifestyle.Transient);
Class 1:
public UserHandler(IAuthenticationHandler authenticationHandler)
{
_authenticationHandler = authenticationHandler;
}
Class 2:
public AuthenticationHandler(IUserHandler userHandler)
{
_userHandler = userHandler;
}
I understand what the cyclic issue is. When the UserHandler is initialized, it is injecting the AuthenticationHandler implementation and then that is trying to create the UserHandler instance and the cycle begins...
My question is how do I solve this in (SIMPLE INJECTOR) this situation and others where I need to inject like this?
Thank you!
UPDATE:
function AddUser(User user){ // User Handler
_authenticationHandler.GenerateRandomSalt();
string hashedPassword = _authenticationHandler.HashPassword(user.Password.HashedPassword, salt);
}
function Authenticate(string username, string password){ // Authentication Handler
_userHandler.GetUserByUsername(username?.Trim());
}
Bascially I need to call the UserHandler in the AuthenticationHandler to get the user and verify there is a user.
I need to call the AuthenticationHandler in the UserHandler to get functions to salt and hash the password.
I guess I could call the Repository to get the user but shouldn't I go through the service handler in case more stuff is done in the user service