Skip to content

Commit

Permalink
net6conversion (dotnet-architecture#642)
Browse files Browse the repository at this point in the history
* Converting to net6 startup and integration test formats

* Update to minimal api and using pagetitle

* Adjust functional test fixtures
Update ApiEndpoints package version

* Finish migration to minimal api startup
  • Loading branch information
ardalis authored Dec 6, 2021
1 parent 20b060a commit ce63e38
Show file tree
Hide file tree
Showing 34 changed files with 485 additions and 714 deletions.
12 changes: 11 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,23 @@ dotnet_style_prefer_conditional_expression_over_return = true:silent
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

# Instance fields are camelCase and start with _
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style

dotnet_naming_symbols.instance_fields.applicable_kinds = field

dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
###############################
# C# Coding Conventions #
###############################
Expand Down
5 changes: 3 additions & 2 deletions eShopOnWeb.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29102.190
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{419A6ACE-0419-4315-A6FB-B0E63D39432E}"
EndProject
Expand All @@ -23,6 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "tests\Fu
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0BD72BEA-EF42-4B72-8B69-12A39EC76FBA}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
docker-compose.override.yml = docker-compose.override.yml
docker-compose.yml = docker-compose.yml
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorAdmin/Pages/CatalogItemPage/List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@inherits BlazorAdmin.Helpers.BlazorComponent
@namespace BlazorAdmin.Pages.CatalogItemPage

<PageTitle>eShopOnWeb Admin: Manage Product Catalog</PageTitle>

<h1>Manage Product Catalog</h1>

@if (catalogItems == null)
Expand Down
53 changes: 24 additions & 29 deletions src/BlazorAdmin/Program.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,49 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using BlazorAdmin;
using BlazorAdmin.Services;
using Blazored.LocalStorage;
using BlazorShared;
using BlazorShared.Models;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace BlazorAdmin;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#admin");
builder.RootComponents.Add<HeadOutlet>("head::after");

public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#admin");

var configSection = builder.Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
builder.Services.Configure<BaseUrlConfiguration>(configSection);
var configSection = builder.Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
builder.Services.Configure<BaseUrlConfiguration>(configSection);

builder.Services.AddScoped(sp => new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(sp => new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddScoped<ToastService>();
builder.Services.AddScoped<HttpService>();
builder.Services.AddScoped<ToastService>();
builder.Services.AddScoped<HttpService>();

builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredLocalStorage();

builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
builder.Services.AddScoped(sp => (CustomAuthStateProvider)sp.GetRequiredService<AuthenticationStateProvider>());
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
builder.Services.AddScoped(sp => (CustomAuthStateProvider)sp.GetRequiredService<AuthenticationStateProvider>());

builder.Services.AddBlazorServices();
builder.Services.AddBlazorServices();

builder.Logging.AddConfiguration(builder.Configuration.GetRequiredSection("Logging"));
builder.Logging.AddConfiguration(builder.Configuration.GetRequiredSection("Logging"));

await ClearLocalStorageCache(builder.Services);
await ClearLocalStorageCache(builder.Services);

await builder.Build().RunAsync();
}
await builder.Build().RunAsync();

private static async Task ClearLocalStorageCache(IServiceCollection services)
{
var sp = services.BuildServiceProvider();
var localStorageService = sp.GetRequiredService<ILocalStorageService>();
static async Task ClearLocalStorageCache(IServiceCollection services)
{
var sp = services.BuildServiceProvider();
var localStorageService = sp.GetRequiredService<ILocalStorageService>();

await localStorageService.RemoveItemAsync(typeof(CatalogBrand).Name);
await localStorageService.RemoveItemAsync(typeof(CatalogType).Name);
}
await localStorageService.RemoveItemAsync(typeof(CatalogBrand).Name);
await localStorageService.RemoveItemAsync(typeof(CatalogType).Name);
}
9 changes: 5 additions & 4 deletions src/Infrastructure/Data/CatalogContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data;
public class CatalogContextSeed
{
public static async Task SeedAsync(CatalogContext catalogContext,
ILoggerFactory loggerFactory, int retry = 0)
ILogger logger,
int retry = 0)
{
var retryForAvailability = retry;
try
Expand Down Expand Up @@ -49,9 +50,9 @@ await catalogContext.CatalogItems.AddRangeAsync(
if (retryForAvailability >= 10) throw;

retryForAvailability++;
var log = loggerFactory.CreateLogger<CatalogContextSeed>();
log.LogError(ex.Message);
await SeedAsync(catalogContext, loggerFactory, retryForAvailability);

logger.LogError(ex.Message);
await SeedAsync(catalogContext, logger, retryForAvailability);
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/AuthEndpoints/Authenticate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints;

public class Authenticate : BaseAsyncEndpoint
public class Authenticate : EndpointBaseAsync
.WithRequest<AuthenticateRequest>
.WithResponse<AuthenticateResponse>
.WithActionResult<AuthenticateResponse>
{
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly ITokenClaimsService _tokenClaimsService;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogBrandEndpoints/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints;

public class List : BaseAsyncEndpoint
public class List : EndpointBaseAsync
.WithoutRequest
.WithResponse<ListCatalogBrandsResponse>
.WithActionResult<ListCatalogBrandsResponse>
{
private readonly IRepository<CatalogBrand> _catalogBrandRepository;
private readonly IMapper _mapper;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogItemEndpoints/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;

[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Create : BaseAsyncEndpoint
public class Create : EndpointBaseAsync
.WithRequest<CreateCatalogItemRequest>
.WithResponse<CreateCatalogItemResponse>
.WithActionResult<CreateCatalogItemResponse>
{
private readonly IRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogItemEndpoints/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;

[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Delete : BaseAsyncEndpoint
public class Delete : EndpointBaseAsync
.WithRequest<DeleteCatalogItemRequest>
.WithResponse<DeleteCatalogItemResponse>
.WithActionResult<DeleteCatalogItemResponse>
{
private readonly IRepository<CatalogItem> _itemRepository;

Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogItemEndpoints/GetById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;

public class GetById : BaseAsyncEndpoint
public class GetById : EndpointBaseAsync
.WithRequest<GetByIdCatalogItemRequest>
.WithResponse<GetByIdCatalogItemResponse>
.WithActionResult<GetByIdCatalogItemResponse>
{
private readonly IRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogItemEndpoints/ListPaged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;

public class ListPaged : BaseAsyncEndpoint
public class ListPaged : EndpointBaseAsync
.WithRequest<ListPagedCatalogItemRequest>
.WithResponse<ListPagedCatalogItemResponse>
.WithActionResult<ListPagedCatalogItemResponse>
{
private readonly IRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogItemEndpoints/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;

[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Update : BaseAsyncEndpoint
public class Update : EndpointBaseAsync
.WithRequest<UpdateCatalogItemRequest>
.WithResponse<UpdateCatalogItemResponse>
.WithActionResult<UpdateCatalogItemResponse>
{
private readonly IRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer;
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApi/CatalogTypeEndpoints/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace Microsoft.eShopWeb.PublicApi.CatalogTypeEndpoints;

public class List : BaseAsyncEndpoint
public class List : EndpointBaseAsync
.WithoutRequest
.WithResponse<ListCatalogTypesResponse>
.WithActionResult<ListCatalogTypesResponse>
{
private readonly IRepository<CatalogType> _catalogTypeRepository;
private readonly IMapper _mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.eShopWeb.ApplicationCore.Exceptions;

namespace Microsoft.eShopWeb.PublicApi.MiddleWares;
namespace Microsoft.eShopWeb.PublicApi.Middleware;

public class ExceptionMiddleware
{
Expand Down
Loading

0 comments on commit ce63e38

Please sign in to comment.