We have seen the GetAllPosts method, which includes related data for all implementations. Since we are creating a common query, which could be consumed in multiple places, we need to include this as a filter in the GetAllPostsQuery object:
public class GetAllPostsQuery { public GetAllPostsQuery(bool includeData) { this.IncludeData = includeData; } public bool IncludeData { get; set; } }
The GetAllPostsQuery consumes only the IncludeData filter in the type, which doesn't filter any data from the result set, but only excludes/includes related data. The following code would create a contract to enforce consumers to implement handle methods:
public interface IPostQueryHandler<T> where T : class { ...