public interface ILogin
{
Task Login();
}
public class LoginStrategyA : ILogin
{
Site site;
public LoginStrategyA(Site site) => this.site = site;
public Task Login()
{
}
}
public class Site : ILogin
{
ILogin loginStrategy;
public Site(ILogin loginStrategy) => this.loginStrategy = loginStrategy;
public Task Login() => loginStrategy.Login();
}
I would like to abstract core pieces of functionality into separate classes. In the example above, the Login functionality is abstracted out to an ILogin implementation. This ILogin implementation will need to access Site members. It seems redundant and bizarre to define a separate ILogin that will take a Site as a parameter. On the other hand, I am not sure how to handle the instantiation of these classes in a way that allows for dependency injection. Is there a better way to approach these types of situations?