I understand interface segregation and single responsibility principles guide against a class implementing methods or property it doesn't need. However, for the scenario described below where I have a User service with Login and Register methods, my Login Controller needs access to a single method (the login method). I have tried to hide the Register method by injecting a UserService object exposed through the ILogin interface.
Interfaces
public interface ILogin
{
Task Login();
}
public interface IRegister
{
Task Register();
}
and the UserService class;
public class UserService: IRegister, ILogin
{
public Task Login()
{
//implementation logic here
}
public Task Register()
{
//implementation logic here
}
}
the Login Controller client
public class LoginController : Controller
{
private ILogin login;
public Login Controller(ILogin login)
{
this.login = login;
}
[HttpPost]
public IActionResult Login()
{
//implementation logic here for login.post
}
}
I would like to know if this implementation breaks any design principle or if it is an anti-pattern.