ProFile-org / ProFile-BE

4 stars 1 forks source link

ProFile - Backend

To create new repository

Steps

public interface IUnitOfWork : IDisposable
{
    ...
    ISampleRepository SampleRepository { get; }
    ...
}

To use repository with MediatR and CQRS

Steps

}

- A command/query implements an IRequest< TResult> with TResult being the result of the operation you want
- You can use either record or class, but record is more preferred
- Add any properties needed for the operation
- Add a request handler to the same file:
```c#
public record GetTestsCommand : IRequest<int>
{

}

public class GetTestsCommandHandler : IRequestHandler<GetTestsCommand, int>
{
    private readonly IUnitOfWork _uow;

    public GetTestsCommandHandler(IUnitOfWork uow)
    {
        _uow = uow;
    }

    public async Task<int> Handle(GetTestsCommand request, CancellationToken cancellationToken)
    {
        // Handle
    }
}