I have a service called as IDataService which has implementations like IUserDataService , IOrderDataService which are used to get the data from an Api Controller.
All of these are generic, so if I have a controller like the one below,
public class DataController
{
private readonly IDataService _dataSvc;
public DataController(IDataService dataSvc)
{
_dataSvc = dataSvc;
}
public void GetData(int limit = 1000)
{
return _dataSvc.GetData(limit);
}
}
public interface IDataService
{
IEnumerable<T> GetData<T>(int limit = 1000);
}
public class UserDataService : IDataService
{
IEnumerable<User> GetData<User>(int limit = 1000)
{
return Set<User>().Take(limit); //this is just a placeholder
}
}
public class ProjectDataService : IDataService
{
IEnumerable<Project> GetData<Project>(int limit = 1000)
{
return Set<Project>().Take(limit); //this is just a placeholder
}
}
I am reading about the usage of the HttpRequest so that if i am able to take the value from header and use it to resolve somehow the service, all the flow will be purely dynamic.
Please let me know if any options is possible on this scenario.