Please educate me if I have code smell (violating SOLID principles, etc) Also how can I make use of IoC to make dependency injection better? Any help, tips, feedback is REALLY appreciated :)
EDIT: Should all dependencies be injected from the constructor in the form of strings or should they be interfaces, if possible? For example, Login concrete class. It COULD take IAuthentication object rather than bunch of strings.
public interface ILogin
{
IUserSession GetUserSession();
}
public interface IAuthentication
{
bool IsValidUser();
}
public interface IUserSession
{
string GetUsername();
bool IsValid();
}
internal class Login : ILogin
{
private readonly string _username;
private readonly string _password;
private readonly IAuthentication _authentication;
public Login(string username, string password)
{
_username = username;
_password = password;
_authentication = new Authentication(username, password);
}
public IUserSession GetUserSession()
{
return new UserSession(_username, _authentication.IsValidUser());
}
}
internal class Authentication : IAuthentication
{
private readonly string _username;
private readonly string _password;
public Authentication(string username, string password)
{
_username = username;
_password = password;
}
public bool IsValidUser()
{
//authentication logic here
return true;
}
}
internal class UserSession : IUserSession
{
private readonly string _username;
private readonly bool _isValid;
public UserSession(string username, bool isValid)
{
_username = username;
_isValid = isValid;
}
public string GetUsername()
{
return _username;
}
public bool IsValid()
{
return _isValid;
}
}