refactor(svcs): ♻️🎨 Rider cleanup

This commit is contained in:
Collin Barrett 2024-06-01 14:21:52 -05:00
parent fc9e1577df
commit 3b20b86146
23 changed files with 187 additions and 178 deletions

View file

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ServiceDefaults\FilterLists.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ServiceDefaults\FilterLists.ServiceDefaults.csproj"/>
</ItemGroup>
</Project>

View file

@ -19,12 +19,12 @@
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
});
@ -33,7 +33,7 @@
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View file

@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>c7967ef0-ced7-4e18-8282-7302b3c0002b</UserSecretsId>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>c7967ef0-ced7-4e18-8282-7302b3c0002b</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ApiService\FilterLists.ApiService.csproj" />
<ProjectReference Include="..\FilterLists.Web\FilterLists.Web.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ApiService\FilterLists.ApiService.csproj"/>
<ProjectReference Include="..\FilterLists.Web\FilterLists.Web.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.0.1"/>
</ItemGroup>
</Project>

View file

@ -1,9 +1,11 @@
using Projects;
var builder = DistributedApplication.CreateBuilder(args);
var apiService = builder.AddProject<Projects.FilterLists_ApiService>("apiservice");
var apiService = builder.AddProject<FilterLists_ApiService>("apiservice");
builder.AddProject<Projects.FilterLists_Web>("webfrontend")
builder.AddProject<FilterLists_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService);
builder.Build().Run();
builder.Build().Run();

View file

@ -7,6 +7,8 @@
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
// ReSharper disable All
namespace Microsoft.Extensions.Hosting;
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
@ -108,4 +110,4 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
return app;
}
}
}

View file

@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
</ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0"/>
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1"/>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0"/>
</ItemGroup>
</Project>

View file

@ -1,28 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="8.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="8.0.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.AppHost\FilterLists.AppHost.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.AppHost\FilterLists.AppHost.csproj"/>
</ItemGroup>
<ItemGroup>
<Using Include="Aspire.Hosting.Testing" />
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<Using Include="Aspire.Hosting.Testing"/>
<Using Include="Xunit"/>
</ItemGroup>
</Project>

View file

@ -1,4 +1,5 @@
using System.Net;
using Projects;
namespace FilterLists.Tests;
@ -8,7 +9,7 @@ public class WebTests
public async Task GetWebResourceRootReturnsOkStatusCode()
{
// Arrange
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.FilterLists_AppHost>();
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<FilterLists_AppHost>();
await using var app = await appHost.BuildAsync();
await app.StartAsync();
@ -19,4 +20,4 @@ public async Task GetWebResourceRootReturnsOkStatusCode()
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
}

View file

@ -2,19 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="FilterLists.Web.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"/>
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="FilterLists.Web.styles.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<HeadOutlet/>
</head>
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
<Routes/>
<script src="_framework/blazor.web.js"></script>
</body>
</html>
</html>

View file

@ -2,7 +2,7 @@
<div class="page">
<div class="sidebar">
<NavMenu />
<NavMenu/>
</div>
<main>
@ -20,4 +20,4 @@
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
</div>

View file

@ -21,20 +21,20 @@ main {
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
@ -88,9 +88,9 @@ main {
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}

View file

@ -4,7 +4,7 @@
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<input type="checkbox" title="Navigation menu" class="navbar-toggler"/>
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
@ -26,4 +26,4 @@
</NavLink>
</div>
</nav>
</div>
</div>

View file

@ -17,7 +17,7 @@
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
background-color: rgba(0, 0, 0, 0.4);
}
.navbar-brand {
@ -51,30 +51,30 @@
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep a {
color: #d7d7d7;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
}
.nav-item ::deep a {
color: #d7d7d7;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
background-color: rgba(255, 255, 255, 0.37);
color: white;
}
.nav-item ::deep a:hover {
background-color: rgba(255,255,255,0.1);
background-color: rgba(255, 255, 255, 0.1);
color: white;
}

View file

@ -10,10 +10,11 @@
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private int currentCount;
private void IncrementCount()
{
currentCount++;
}
}
}

View file

@ -25,8 +25,7 @@
</p>
@code{
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
[CascadingParameter] public HttpContext? HttpContext { get; set; }
private string? requestId;
private bool ShowRequestId => !string.IsNullOrEmpty(requestId);
@ -35,4 +34,5 @@
{
requestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
}
}

View file

@ -4,4 +4,4 @@
<h1>Hello, world!</h1>
Welcome to your new app.
Welcome to your new app.

View file

@ -1,5 +1,5 @@
@page "/weather"
@attribute [StreamRendering(true)]
@attribute [StreamRendering]
@attribute [OutputCache(Duration = 5)]
@inject WeatherApiClient WeatherApi
@ -12,29 +12,31 @@
@if (forecasts == null)
{
<p><em>Loading...</em></p>
<p>
<em>Loading...</em>
</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@ -46,4 +48,5 @@ else
{
forecasts = await WeatherApi.GetWeatherAsync();
}
}
}

View file

@ -1,6 +1,7 @@
<Router AppAssembly="@typeof(Program).Assembly">
@using FilterLists.Web.Components.Layout
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
</Router>
</Router>

View file

@ -8,4 +8,4 @@
@using Microsoft.AspNetCore.OutputCaching
@using Microsoft.JSInterop
@using FilterLists.Web
@using FilterLists.Web.Components
@using FilterLists.Web.Components

View file

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ServiceDefaults\FilterLists.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FilterLists.ServiceDefaults\FilterLists.ServiceDefaults.csproj"/>
</ItemGroup>
</Project>

View file

@ -13,17 +13,17 @@
builder.Services.AddOutputCache();
builder.Services.AddHttpClient<WeatherApiClient>(client =>
{
// This URL uses "https+http://" to indicate HTTPS is preferred over HTTP.
// Learn more about service discovery scheme resolution at https://aka.ms/dotnet/sdschemes.
client.BaseAddress = new("https+http://apiservice");
});
{
// This URL uses "https+http://" to indicate HTTPS is preferred over HTTP.
// Learn more about service discovery scheme resolution at https://aka.ms/dotnet/sdschemes.
client.BaseAddress = new Uri("https+http://apiservice");
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseExceptionHandler("/Error", true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
@ -40,4 +40,4 @@
app.MapDefaultEndpoints();
app.Run();
app.Run();

View file

@ -2,16 +2,15 @@ namespace FilterLists.Web;
public class WeatherApiClient(HttpClient httpClient)
{
public async Task<WeatherForecast[]> GetWeatherAsync(int maxItems = 10, CancellationToken cancellationToken = default)
public async Task<WeatherForecast[]> GetWeatherAsync(int maxItems = 10,
CancellationToken cancellationToken = default)
{
List<WeatherForecast>? forecasts = null;
await foreach (var forecast in httpClient.GetFromJsonAsAsyncEnumerable<WeatherForecast>("/weatherforecast", cancellationToken))
await foreach (var forecast in httpClient.GetFromJsonAsAsyncEnumerable<WeatherForecast>("/weatherforecast",
cancellationToken))
{
if (forecasts?.Count >= maxItems)
{
break;
}
if (forecasts?.Count >= maxItems) break;
if (forecast is not null)
{
forecasts ??= [];
@ -26,4 +25,4 @@ public async Task<WeatherForecast[]> GetWeatherAsync(int maxItems = 10, Cancella
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View file

@ -20,6 +20,6 @@ h1:focus {
color: white;
}
.blazor-error-boundary::after {
content: "An error has occurred."
}
.blazor-error-boundary::after {
content: "An error has occurred."
}