In my existing code, I have an interface like so:
public interface IStudentService
{
T GetStudent(int userId);
}
This interface is called in many places, and the concrete implementation, let's call it StudentServiceDb
, reads the student from the database.
Then I have a new requirement, which is to get the student info from an API, so now I need not only the userId, but I need to pass in the token from the caller as well.
Should I change the interface to
public interface IStudentService
{
T GetStudent(int userId, string token);
}
And create StudentServiceAPI
concrete implementation, and ignore token in the existing StudentServiceDb
?
There is also an additional requirement that whether it reads from the database or from the API is determined by the feature flag, how should I handle it? Should I change all occurrences of IStudentService
to IStudentServiceChooser
which will register the both concrete implementations and evaluate which to use?
GetStudent
? Shouldn'tStudentServiceAPI
allow to keep the token as internal state and provide this for several calls of "GetStudent"?