mercredi 4 mars 2015

CQRS Query handler with no parameter


public interface IQueryHandler<in TQuery, out TResult>
where TQuery : IQuery<TResult>
{
TResult Handle(TQuery query);
}


This is a query handler interface that requires a parameter to execute query.



public class PlaceByIdHandler : IQueryHandler<PlaceById, PlaceModel>
{
...........

public PlaceModel Execute(PlaceById query)
{
return repository.Query<PlaceModel>("select * from places where id="+ query.id);
}
}


But some queryies does not need parameter. For example Get all places:



public class PlaceAllHandler : IQueryHandler<PlaceAll, PlaceModel>
{
..........

public PlaceModel Execute(PlaceAll query)
{
return return repository.Query<PlaceModel>("select * from places");
}
}


But now PlaceAll is a class that has no Member.



public class PlaceAll{}


Is this a true approach? Is there any order?


Aucun commentaire:

Enregistrer un commentaire