diff --git a/Directory.Packages.props b/Directory.Packages.props index b80222fa..f0d99b0f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -20,6 +20,7 @@ + diff --git a/src/PublicApi/AuthEndpoints/AuthenticateEndpoint.cs b/src/PublicApi/AuthEndpoints/AuthenticateEndpoint.cs index c5cce657..e6f25cea 100644 --- a/src/PublicApi/AuthEndpoints/AuthenticateEndpoint.cs +++ b/src/PublicApi/AuthEndpoints/AuthenticateEndpoint.cs @@ -1,20 +1,18 @@ using System.Threading; using System.Threading.Tasks; -using Ardalis.ApiEndpoints; +using FastEndpoints; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.Infrastructure.Identity; -using Swashbuckle.AspNetCore.Annotations; namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints; /// /// Authenticates a user /// -public class AuthenticateEndpoint : EndpointBaseAsync - .WithRequest - .WithActionResult +public class AuthenticateEndpoint : Endpoint { private readonly SignInManager _signInManager; private readonly ITokenClaimsService _tokenClaimsService; @@ -26,14 +24,18 @@ public AuthenticateEndpoint(SignInManager signInManager, _tokenClaimsService = tokenClaimsService; } - [HttpPost("api/authenticate")] - [SwaggerOperation( - Summary = "Authenticates a user", - Description = "Authenticates a user", - OperationId = "auth.authenticate", - Tags = new[] { "AuthEndpoints" }) - ] - public override async Task> HandleAsync(AuthenticateRequest request, + public override void Configure() + { + Post("api/authenticate"); + AllowAnonymous(); + Description(d => + d.WithSummary("Authenticates a user") + .WithDescription("Authenticates a user") + .WithName("auth.authenticate") + .WithTags("AuthEndpoints")); + } + + public override async Task ExecuteAsync(AuthenticateRequest request, CancellationToken cancellationToken = default) { var response = new AuthenticateResponse(request.CorrelationId()); diff --git a/src/PublicApi/CatalogBrandEndpoints/CatalogBrandListEndpoint.cs b/src/PublicApi/CatalogBrandEndpoints/CatalogBrandListEndpoint.cs index 32b3d0b9..8444dcdc 100644 --- a/src/PublicApi/CatalogBrandEndpoints/CatalogBrandListEndpoint.cs +++ b/src/PublicApi/CatalogBrandEndpoints/CatalogBrandListEndpoint.cs @@ -1,46 +1,44 @@ using System.Linq; +using System.Threading; using System.Threading.Tasks; -using AutoMapper; -using Microsoft.AspNetCore.Builder; +using FastEndpoints; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints; /// /// List Catalog Brands /// -public class CatalogBrandListEndpoint : IEndpoint> +public class CatalogBrandListEndpoint : EndpointWithoutRequest { - private readonly IMapper _mapper; + private readonly IRepository _catalogBrandRepository; + private readonly AutoMapper.IMapper _mapper; - public CatalogBrandListEndpoint(IMapper mapper) + public CatalogBrandListEndpoint(IRepository catalogBrandRepository, AutoMapper.IMapper mapper) { + _catalogBrandRepository = catalogBrandRepository; _mapper = mapper; } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapGet("api/catalog-brands", - async (IRepository catalogBrandRepository) => - { - return await HandleAsync(catalogBrandRepository); - }) - .Produces() - .WithTags("CatalogBrandEndpoints"); + Get("api/catalog-brands"); + AllowAnonymous(); + Description(d => + d.Produces() + .WithTags("CatalogBrandEndpoints")); } - public async Task HandleAsync(IRepository catalogBrandRepository) + public override async Task ExecuteAsync(CancellationToken ct) { var response = new ListCatalogBrandsResponse(); - var items = await catalogBrandRepository.ListAsync(); + var items = await _catalogBrandRepository.ListAsync(ct); response.CatalogBrands.AddRange(items.Select(_mapper.Map)); - return Results.Ok(response); + return response; } } diff --git a/src/PublicApi/CatalogItemEndpoints/CatalogItemGetByIdEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/CatalogItemGetByIdEndpoint.cs index 9f15c72a..d2b8c303 100644 --- a/src/PublicApi/CatalogItemEndpoints/CatalogItemGetByIdEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/CatalogItemGetByIdEndpoint.cs @@ -1,43 +1,44 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using System.Threading; +using System.Threading.Tasks; +using FastEndpoints; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// /// Get a Catalog Item by Id /// -public class CatalogItemGetByIdEndpoint : IEndpoint> +public class CatalogItemGetByIdEndpoint + : Endpoint, NotFound>> { + private readonly IRepository _itemRepository; private readonly IUriComposer _uriComposer; - public CatalogItemGetByIdEndpoint(IUriComposer uriComposer) + public CatalogItemGetByIdEndpoint(IRepository itemRepository, IUriComposer uriComposer) { + _itemRepository = itemRepository; _uriComposer = uriComposer; } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapGet("api/catalog-items/{catalogItemId}", - async (int catalogItemId, IRepository itemRepository) => - { - return await HandleAsync(new GetByIdCatalogItemRequest(catalogItemId), itemRepository); - }) - .Produces() - .WithTags("CatalogItemEndpoints"); + Get("api/catalog-items/{catalogItemId}"); + AllowAnonymous(); + Description(d => + d.Produces() + .WithTags("CatalogItemEndpoints")); } - public async Task HandleAsync(GetByIdCatalogItemRequest request, IRepository itemRepository) + public override async Task, NotFound>> ExecuteAsync(GetByIdCatalogItemRequest request, CancellationToken ct) { var response = new GetByIdCatalogItemResponse(request.CorrelationId()); - var item = await itemRepository.GetByIdAsync(request.CatalogItemId); + var item = await _itemRepository.GetByIdAsync(request.CatalogItemId, ct); if (item is null) - return Results.NotFound(); + return TypedResults.NotFound(); response.CatalogItem = new CatalogItemDto { @@ -49,6 +50,6 @@ public async Task HandleAsync(GetByIdCatalogItemRequest request, IRepos PictureUri = _uriComposer.ComposePicUri(item.PictureUri), Price = item.Price }; - return Results.Ok(response); + return TypedResults.Ok(response); } } diff --git a/src/PublicApi/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs index 3e36d2f4..eb894336 100644 --- a/src/PublicApi/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs @@ -1,49 +1,48 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; -using AutoMapper; -using Microsoft.AspNetCore.Builder; +using FastEndpoints; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Specifications; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// /// List Catalog Items (paged) /// -public class CatalogItemListPagedEndpoint : IEndpoint> +public class CatalogItemListPagedEndpoint : Endpoint { + private readonly IRepository _itemRepository; private readonly IUriComposer _uriComposer; - private readonly IMapper _mapper; + private readonly AutoMapper.IMapper _mapper; - public CatalogItemListPagedEndpoint(IUriComposer uriComposer, IMapper mapper) + public CatalogItemListPagedEndpoint(IRepository itemRepository, IUriComposer uriComposer, AutoMapper.IMapper mapper) { + _itemRepository = itemRepository; _uriComposer = uriComposer; _mapper = mapper; } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapGet("api/catalog-items", - async (int? pageSize, int? pageIndex, int? catalogBrandId, int? catalogTypeId, IRepository itemRepository) => - { - return await HandleAsync(new ListPagedCatalogItemRequest(pageSize, pageIndex, catalogBrandId, catalogTypeId), itemRepository); - }) - .Produces() - .WithTags("CatalogItemEndpoints"); + Get("api/catalog-items"); + AllowAnonymous(); + Description(d => + d.Produces() + .WithTags("CatalogItemEndpoints")); } - public async Task HandleAsync(ListPagedCatalogItemRequest request, IRepository itemRepository) + public override async Task ExecuteAsync(ListPagedCatalogItemRequest request, CancellationToken ct) { - await Task.Delay(1000); + await Task.Delay(1000, ct); + var response = new ListPagedCatalogItemResponse(request.CorrelationId()); var filterSpec = new CatalogFilterSpecification(request.CatalogBrandId, request.CatalogTypeId); - int totalItems = await itemRepository.CountAsync(filterSpec); + int totalItems = await _itemRepository.CountAsync(filterSpec, ct); var pagedSpec = new CatalogFilterPaginatedSpecification( skip: request.PageIndex * request.PageSize, @@ -51,7 +50,7 @@ public async Task HandleAsync(ListPagedCatalogItemRequest request, IRep brandId: request.CatalogBrandId, typeId: request.CatalogTypeId); - var items = await itemRepository.ListAsync(pagedSpec); + var items = await _itemRepository.ListAsync(pagedSpec, ct); response.CatalogItems.AddRange(items.Select(_mapper.Map)); foreach (CatalogItemDto item in response.CatalogItems) @@ -68,6 +67,6 @@ public async Task HandleAsync(ListPagedCatalogItemRequest request, IRep response.PageCount = totalItems > 0 ? 1 : 0; } - return Results.Ok(response); + return response; } } diff --git a/src/PublicApi/CatalogItemEndpoints/CreateCatalogItemEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/CreateCatalogItemEndpoint.cs index c15346ff..12ee6dc0 100644 --- a/src/PublicApi/CatalogItemEndpoints/CreateCatalogItemEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/CreateCatalogItemEndpoint.cs @@ -1,54 +1,52 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; +using FastEndpoints; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Exceptions; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Specifications; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// /// Creates a new Catalog Item /// -public class CreateCatalogItemEndpoint : IEndpoint> +public class CreateCatalogItemEndpoint : Endpoint { + private readonly IRepository _itemRepository; private readonly IUriComposer _uriComposer; - public CreateCatalogItemEndpoint(IUriComposer uriComposer) + public CreateCatalogItemEndpoint(IRepository itemRepository, IUriComposer uriComposer) { + _itemRepository = itemRepository; _uriComposer = uriComposer; } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapPost("api/catalog-items", - [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] async - (CreateCatalogItemRequest request, IRepository itemRepository) => - { - return await HandleAsync(request, itemRepository); - }) - .Produces() - .WithTags("CatalogItemEndpoints"); + Post("api/catalog-items"); + Roles(BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Description(d => + d.Produces() + .WithTags("CatalogItemEndpoints")); } - public async Task HandleAsync(CreateCatalogItemRequest request, IRepository itemRepository) + public override async Task HandleAsync(CreateCatalogItemRequest request, CancellationToken ct) { var response = new CreateCatalogItemResponse(request.CorrelationId()); var catalogItemNameSpecification = new CatalogItemNameSpecification(request.Name); - var existingCataloogItem = await itemRepository.CountAsync(catalogItemNameSpecification); + var existingCataloogItem = await _itemRepository.CountAsync(catalogItemNameSpecification, ct); if (existingCataloogItem > 0) { throw new DuplicateException($"A catalogItem with name {request.Name} already exists"); } var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); - newItem = await itemRepository.AddAsync(newItem); + newItem = await _itemRepository.AddAsync(newItem, ct); if (newItem.Id != 0) { @@ -57,7 +55,7 @@ public async Task HandleAsync(CreateCatalogItemRequest request, IReposi // In production, we recommend uploading to a blob storage and deliver the image via CDN after a verification process. newItem.UpdatePictureUri("eCatalog-item-default.png"); - await itemRepository.UpdateAsync(newItem); + await _itemRepository.UpdateAsync(newItem, ct); } var dto = new CatalogItemDto @@ -71,6 +69,7 @@ public async Task HandleAsync(CreateCatalogItemRequest request, IReposi Price = newItem.Price }; response.CatalogItem = dto; - return Results.Created($"api/catalog-items/{dto.Id}", response); + + await SendCreatedAtAsync(new{ CatalogItemId = dto.Id }, response, cancellation: ct); } } diff --git a/src/PublicApi/CatalogItemEndpoints/DeleteCatalogItemEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/DeleteCatalogItemEndpoint.cs index 0e37f445..1dc992eb 100644 --- a/src/PublicApi/CatalogItemEndpoints/DeleteCatalogItemEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/DeleteCatalogItemEndpoint.cs @@ -1,42 +1,46 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; +using FastEndpoints; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// /// Deletes a Catalog Item /// -public class DeleteCatalogItemEndpoint : IEndpoint> +public class DeleteCatalogItemEndpoint : Endpoint, NotFound>> { - public void AddRoute(IEndpointRouteBuilder app) + private readonly IRepository _itemRepository; + + public DeleteCatalogItemEndpoint(IRepository itemRepository) + { + _itemRepository = itemRepository; + } + + public override void Configure() { - app.MapDelete("api/catalog-items/{catalogItemId}", - [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] async - (int catalogItemId, IRepository itemRepository) => - { - return await HandleAsync(new DeleteCatalogItemRequest(catalogItemId), itemRepository); - }) - .Produces() - .WithTags("CatalogItemEndpoints"); + Delete("api/catalog-items/{catalogItemId}"); + Roles(BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Description(d => + d.Produces() + .WithTags("CatalogItemEndpoints")); } - public async Task HandleAsync(DeleteCatalogItemRequest request, IRepository itemRepository) + public override async Task, NotFound>> ExecuteAsync(DeleteCatalogItemRequest request, CancellationToken ct) { var response = new DeleteCatalogItemResponse(request.CorrelationId()); - var itemToDelete = await itemRepository.GetByIdAsync(request.CatalogItemId); + var itemToDelete = await _itemRepository.GetByIdAsync(request.CatalogItemId, ct); if (itemToDelete is null) - return Results.NotFound(); + return TypedResults.NotFound(); - await itemRepository.DeleteAsync(itemToDelete); + await _itemRepository.DeleteAsync(itemToDelete, ct); - return Results.Ok(response); + return TypedResults.Ok(response); } } diff --git a/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs index 15efa684..ff23009b 100644 --- a/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs @@ -1,47 +1,46 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; +using FastEndpoints; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// /// Updates a Catalog Item /// -public class UpdateCatalogItemEndpoint : IEndpoint> -{ +public class UpdateCatalogItemEndpoint : Endpoint, NotFound>> +{ + private readonly IRepository _itemRepository; private readonly IUriComposer _uriComposer; - public UpdateCatalogItemEndpoint(IUriComposer uriComposer) + public UpdateCatalogItemEndpoint(IRepository itemRepository, IUriComposer uriComposer) { + _itemRepository = itemRepository; _uriComposer = uriComposer; } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapPut("api/catalog-items", - [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] async - (UpdateCatalogItemRequest request, IRepository itemRepository) => - { - return await HandleAsync(request, itemRepository); - }) - .Produces() - .WithTags("CatalogItemEndpoints"); + Put("api/catalog-items"); + Roles(BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Description(d => + d.Produces() + .WithTags("CatalogItemEndpoints")); } - public async Task HandleAsync(UpdateCatalogItemRequest request, IRepository itemRepository) + public override async Task, NotFound>> ExecuteAsync(UpdateCatalogItemRequest request, CancellationToken ct) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); - var existingItem = await itemRepository.GetByIdAsync(request.Id); + var existingItem = await _itemRepository.GetByIdAsync(request.Id, ct); if (existingItem == null) { - return Results.NotFound(); + return TypedResults.NotFound(); } CatalogItem.CatalogItemDetails details = new(request.Name, request.Description, request.Price); @@ -49,7 +48,7 @@ public async Task HandleAsync(UpdateCatalogItemRequest request, IReposi existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); - await itemRepository.UpdateAsync(existingItem); + await _itemRepository.UpdateAsync(existingItem, ct); var dto = new CatalogItemDto { @@ -62,6 +61,6 @@ public async Task HandleAsync(UpdateCatalogItemRequest request, IReposi Price = existingItem.Price }; response.CatalogItem = dto; - return Results.Ok(response); + return TypedResults.Ok(response); } } diff --git a/src/PublicApi/CatalogTypeEndpoints/CatalogTypeListEndpoint.cs b/src/PublicApi/CatalogTypeEndpoints/CatalogTypeListEndpoint.cs index 3e36735b..f0e21c53 100644 --- a/src/PublicApi/CatalogTypeEndpoints/CatalogTypeListEndpoint.cs +++ b/src/PublicApi/CatalogTypeEndpoints/CatalogTypeListEndpoint.cs @@ -1,46 +1,45 @@ using System.Linq; +using System.Threading; using System.Threading.Tasks; -using AutoMapper; -using Microsoft.AspNetCore.Builder; +using FastEndpoints; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using MinimalApi.Endpoint; namespace Microsoft.eShopWeb.PublicApi.CatalogTypeEndpoints; /// /// List Catalog Types /// -public class CatalogTypeListEndpoint : IEndpoint> +public class CatalogTypeListEndpoint : EndpointWithoutRequest { - private readonly IMapper _mapper; + private readonly IRepository _catalogTypeRepository; + private readonly AutoMapper.IMapper _mapper; - public CatalogTypeListEndpoint(IMapper mapper) + public CatalogTypeListEndpoint(IRepository catalogTypeRepository, AutoMapper.IMapper mapper) { + _catalogTypeRepository = catalogTypeRepository; _mapper = mapper; + } - public void AddRoute(IEndpointRouteBuilder app) + public override void Configure() { - app.MapGet("api/catalog-types", - async (IRepository catalogTypeRepository) => - { - return await HandleAsync(catalogTypeRepository); - }) - .Produces() - .WithTags("CatalogTypeEndpoints"); + Get("api/catalog-types"); + AllowAnonymous(); + Description(d => + d.Produces() + .WithTags("CatalogTypeEndpoints")); } - public async Task HandleAsync(IRepository catalogTypeRepository) + public override async Task ExecuteAsync(CancellationToken ct) { var response = new ListCatalogTypesResponse(); - var items = await catalogTypeRepository.ListAsync(); + var items = await _catalogTypeRepository.ListAsync(ct); response.CatalogTypes.AddRange(items.Select(_mapper.Map)); - return Results.Ok(response); + return response; } } diff --git a/src/PublicApi/Extensions/ConfigurationManagerExtensions.cs b/src/PublicApi/Extensions/ConfigurationManagerExtensions.cs new file mode 100644 index 00000000..b5aef499 --- /dev/null +++ b/src/PublicApi/Extensions/ConfigurationManagerExtensions.cs @@ -0,0 +1,15 @@ +using System.IO; +using System; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.eShopWeb.PublicApi.Extensions; + +public static class ConfigurationManagerExtensions +{ + public static ConfigurationManager AddConfigurationFile(this ConfigurationManager configurationManager, string path) + { + var configPath = Path.Combine(AppContext.BaseDirectory, path); + configurationManager.AddJsonFile(configPath, true, false); + return configurationManager; + } +} diff --git a/src/PublicApi/Program.cs b/src/PublicApi/Program.cs index c8b8543f..4d15ca74 100644 --- a/src/PublicApi/Program.cs +++ b/src/PublicApi/Program.cs @@ -1,4 +1,5 @@ using BlazorShared; +using FastEndpoints; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Identity; using Microsoft.eShopWeb.Infrastructure; @@ -10,12 +11,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using MinimalApi.Endpoint.Configurations.Extensions; -using MinimalApi.Endpoint.Extensions; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddEndpoints(); +builder.Services.AddFastEndpoints(); // Use to force loading of appsettings.json of test project builder.Configuration.AddConfigurationFile("appsettings.test.json"); @@ -77,8 +76,7 @@ c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); -app.MapControllers(); -app.MapEndpoints(); +app.UseFastEndpoints(); app.Logger.LogInformation("LAUNCHING PublicApi"); app.Run(); diff --git a/src/PublicApi/PublicApi.csproj b/src/PublicApi/PublicApi.csproj index 965ea6d2..c6644a33 100644 --- a/src/PublicApi/PublicApi.csproj +++ b/src/PublicApi/PublicApi.csproj @@ -9,9 +9,8 @@ - - + @@ -21,7 +20,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive