more examples.
This commit is contained in:
parent
50b3b66595
commit
9015dc2d5f
32
Demo/Queries/ListPersonQuery.cs
Normal file
32
Demo/Queries/ListPersonQuery.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using PoweredSoft.CQRS.Abstractions;
|
||||||
|
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Demo.Queries
|
||||||
|
{
|
||||||
|
public class OnePersonQuery
|
||||||
|
{
|
||||||
|
public long PersonId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OnePersonQueryHandler : IQueryHandler<OnePersonQuery, Person>
|
||||||
|
{
|
||||||
|
private readonly IQueryableProvider<Person> provider;
|
||||||
|
|
||||||
|
public OnePersonQueryHandler(IQueryableProvider<Person> provider)
|
||||||
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Person> HandleAsync(OnePersonQuery query, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var _ = await provider.GetQueryableAsync(query, cancellationToken);
|
||||||
|
var ret = _.First(t => t.Id == query.PersonId);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
Demo/Queries/OnePerson.cs
Normal file
39
Demo/Queries/OnePerson.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using PoweredSoft.CQRS.Abstractions;
|
||||||
|
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Demo.Queries
|
||||||
|
{
|
||||||
|
public class ListPersonQuery
|
||||||
|
{
|
||||||
|
public string Search { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ListPersonQueryHandler : IQueryHandler<ListPersonQuery, List<Person>>
|
||||||
|
{
|
||||||
|
private readonly IQueryableProvider<Person> provider;
|
||||||
|
|
||||||
|
public ListPersonQueryHandler(IQueryableProvider<Person> provider)
|
||||||
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Person>> HandleAsync(ListPersonQuery query, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var _ = await provider.GetQueryableAsync(query, cancellationToken);
|
||||||
|
|
||||||
|
if (query.Search != null)
|
||||||
|
_ = _
|
||||||
|
.Where(t => t.FirstName.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
t.LastName.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
|
||||||
|
|
||||||
|
var ret = _.ToList();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ using PoweredSoft.CQRS.Abstractions.Security;
|
|||||||
using Demo.Security;
|
using Demo.Security;
|
||||||
using PoweredSoft.CQRS.FluentValidation;
|
using PoweredSoft.CQRS.FluentValidation;
|
||||||
using Microsoft.AspNetCore.OData;
|
using Microsoft.AspNetCore.OData;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Demo
|
namespace Demo
|
||||||
{
|
{
|
||||||
@ -105,6 +106,8 @@ namespace Demo
|
|||||||
private void AddQueries(IServiceCollection services)
|
private void AddQueries(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddQuery<PersonQuery, IQueryable<Person>, PersonQueryHandler>();
|
services.AddQuery<PersonQuery, IQueryable<Person>, PersonQueryHandler>();
|
||||||
|
services.AddQuery<OnePersonQuery, Person, OnePersonQueryHandler>();
|
||||||
|
services.AddQuery<ListPersonQuery, List<Person>, ListPersonQueryHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
Loading…
Reference in New Issue
Block a user