Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加一个IQuery 接口,支持自动注入,支持中介者模式 #92

Closed
witskeeper opened this issue Oct 28, 2024 · 1 comment
Closed
Labels
help wanted Extra attention is needed
Milestone

Comments

@witskeeper
Copy link
Member

  1. 提供IQuery接口,表示一个类型为Query类
  2. 提供AddQuery方法,以自动注入Query类型到容器
  3. 提供IQuery的中介者模式支持

下面为伪代码:

namespace NetCorePal.Extensions.Primitives;

public interface IQuery;



public interface IQuery<out TResponse> : IRequest<TResponse>, IQuery;


public interface IQueryHandler<in TQuery, TResponse> : IRequestHandler<TQuery, TResponse>
    where TQuery : IQuery<TResponse>
{
}


public class DbContext()
{
}



public class OrderQueryResponse
{
    public required string Title { get; set; }
    public required string Description { get; set; }
    public decimal Price { get; set; }
}

public record OrderQueryRequest(string Title) : IQuery<OrderQueryResponse>;





public class OrderQueryHandler(DbContext dbContext) : IQueryHandler<OrderQueryRequest, OrderQueryResponse>
{
    public Task<OrderQueryResponse> Handle(OrderQueryRequest request, CancellationToken cancellationToken)
    {
        return Task.FromResult(new OrderQueryResponse
        {
            Title = request.Title,
            Description = "Description",
            Price = 100
        });
    }
}

public class OrderQuery(DbContext dbcontext) : IQuery
{
    public Task<OrderQueryResponse> QueryQrder(OrderQueryRequest request, CancellationToken cancellationToken)
    {
        return Task.FromResult(new OrderQueryResponse
        {
            Title = request.Title,
            Description = "Description",
            Price = 100
        });
    }

    public Task<OrderQueryResponse> QueryOrderByTitle(string title, CancellationToken cancellationToken)
    {
        return Task.FromResult(new OrderQueryResponse
        {
            Title = request.Title,
            Description = "Description",
            Price = 100
        });
    }
}
@witskeeper
Copy link
Member Author

witskeeper commented Nov 4, 2024

在#99中实现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant