Is it bad design if I create repostory with methods that returns generic types. For example in AccountsRepository if I have:
public class Repository<T> : IRepository<T>
where T : class
{
}
public class AccountsRepository<TUser> :
Repository<User>,IAccountsRepository
where TUser : class,IUser,new()
{
public TUser GetUserByUserName(string username)
{
return this.context.User.Where(s =>
s.UserName.Equals(username)).Select(c=>new TUser(){ Password =c.Password }).FirstOrDefault();
}
}
Is this the proper way of doing that. So It's something like I return DTO object but it is generic type. So my classes using repository doesn't have to know what types are the objects in database.
IRepository<T>
? What's the point in emptyRepository<T>
implementation? What'sUser
and how does it relate toIUser
andTUser
? Too much code is omitted, but if I guessed it right, it feels like this is going to be a needless level of abstraction. Your question lacks explanation on why you think this is necessary. \$\endgroup\$