Skip to content

Commit

Permalink
Fix comment typo
Browse files Browse the repository at this point in the history
Add some formatting
  • Loading branch information
ardalis committed Jan 22, 2024
1 parent 924a68c commit 7181663
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions sample/Ardalis.Sample.App3/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;

// Sample Application 2
// Sample Application 3
// The focus of this library are not the repositories. We're providing the built-in repository implementations just as a convenience.
// You can certainly have your own repository implementations and tweak them per your needs.
// In this sample we demonstrate how to do that, and some other more advanced features.
// - Defined custom RepositoryBase implementation (also added an additional evaluator)
// - Defined separate IRepository and IReadRepository interfaces. IRepository requires IAggregateRoot.
// - Defined pagination constructs.
// - We're utilizing Automapper projections in our repository and defined ProjectTo methods for the IReadRepository. These methods return paginated response automatically.
// - We're utilizing Automapper projections in our repository and defined ProjectTo methods for the IReadRepository.
// These methods return paginated responses automatically.

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -31,23 +32,30 @@


// Projecting directly to response DTOs. In addition the response is paginated and wrapped in PagedResponse<T>.
app.MapGet("/customers", async (IReadRepository<Customer> repo, [AsParameters] CustomerFilter filter, CancellationToken cancellationToken) =>
app.MapGet("/customers", async (IReadRepository<Customer> repo,
[AsParameters] CustomerFilter filter,
CancellationToken cancellationToken) =>
{
var spec = new CustomerSpec(filter);
var result = await repo.ProjectToListAsync<CustomerDto>(spec, filter, cancellationToken);
return Results.Ok(result);
});

// Projecting directly to response DTOs.
app.MapGet("/customers/{id}", async (IReadRepository<Customer> repo, int id, CancellationToken cancellationToken) =>
app.MapGet("/customers/{id}", async (IReadRepository<Customer> repo,
int id,
CancellationToken cancellationToken) =>
{
var spec = new CustomerByIdSpec(id);
var result = await repo.ProjectToFirstOrDefaultAsync<CustomerDto>(spec, cancellationToken);
if (result is null) return Results.NotFound();
return Results.Ok(result);
});

app.MapPost("/customers", async (IRepository<Customer> repo, IMapper mapper, CustomerCreateDto customerCreateDto, CancellationToken cancellationToken) =>
app.MapPost("/customers", async (IRepository<Customer> repo,
IMapper mapper,
CustomerCreateDto customerCreateDto,
CancellationToken cancellationToken) =>
{
var customer = new Customer
{
Expand All @@ -60,7 +68,11 @@
return Results.Ok(customerDto);
});

app.MapPut("/customers/{id}", async (IRepository<Customer> repo, IMapper mapper, int id, CustomerUpdateDto customerUpdate, CancellationToken cancellationToken) =>
app.MapPut("/customers/{id}", async (IRepository<Customer> repo,
IMapper mapper,
int id,
CustomerUpdateDto customerUpdate,
CancellationToken cancellationToken) =>
{
var spec = new CustomerByIdSpec(id);
var customer = await repo.FirstOrDefaultAsync(spec, cancellationToken);
Expand Down

0 comments on commit 7181663

Please sign in to comment.