Setting aside that you won't go with a Mapping framework like Jeroen Vannevel Jeroen Vannevel suggested in his comment comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public T Query(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public T Query(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public T Query(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public TQueryT Query(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public TQuery(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public T Query(int id)
{
..........
return mapper.Map(reader)
...
}
}
Setting aside that you won't go with a Mapping framework like Jeroen Vannevel suggested in his comment, this basically looks good but can still be improved.
I don't see any value added by creating an abstract class which implements the IMapper<T>
interface. So you better just do it like
public class UserDtoMapper : IMapper<UserDto>
{
public UserDto Map(SqlMapper.GridReader reader)
{
return reader.Read().Select(x => new UserDto()
{
Id = x.Id,
Name = x.Name
}).SingleOrDefault();
}
}
But if you travel this route you should do it right and also make QueryObject
class generic like
public class QueryObject<T>
{
private IMapper<T> mapper;
public QueryObject(IMapper<T> mapper)
{
this.mapper = mapper;
}
public TQuery(int id)
{
..........
return mapper.Map(reader)
...
}
}