Skip to content

Commit 9b6e6f9

Browse files
committed
Cleanup projects, implicit usings, file scoped namespaces
1 parent 786fdaf commit 9b6e6f9

File tree

107 files changed

+1542
-1863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1542
-1863
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ trim_trailing_whitespace = false
1515
indent_size = 2
1616

1717
[*.cs]
18+
dotnet_sort_system_directives_first = true:warning
19+
20+
csharp_style_namespace_declarations = file_scoped:warning
21+
1822
csharp_style_var_for_built_in_types = false:warning
1923

2024
csharp_style_var_when_type_is_apparent = true:warning

Directory.Build.props

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
<Project>
2+
23
<PropertyGroup>
34
<CodeAnalysisRuleSet>$(SolutionDir)dotnet.ruleset</CodeAnalysisRuleSet>
45
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
56
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
67
<GenerateDocumentationFile>true</GenerateDocumentationFile>
78
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
89
<NoDefaultExcludes>true</NoDefaultExcludes>
10+
<ImplicitUsings>enable</ImplicitUsings>
911
</PropertyGroup>
12+
1013
<ItemGroup>
11-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
14+
<PackageReference Include="Roslynator.Analyzers" Version="3.3.0">
1215
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1317
</PackageReference>
14-
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2">
18+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
1519
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1621
</PackageReference>
17-
<AdditionalFiles Include="$(SolutionDir)stylecop.json" Link="Properties\stylecop.json" />
18-
<AdditionalFiles Include="$(SolutionDir)dotnet.ruleset" Link="Properties\dotnet.ruleset" />
19-
<AdditionalFiles Include="$(SolutionDir).editorconfig" Link="Properties\.editorconfig" />
22+
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="Properties\stylecop.json" />
23+
<AdditionalFiles Include="$(MSBuildThisFileDirectory).editorconfig" Link="Properties\.editorconfig" />
2024
</ItemGroup>
25+
2126
</Project>

Directory.Build.targets

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
4+
</PropertyGroup>
5+
</Project>

FSH.BlazorWebAssembly.sln

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client.Infrastructure", "src\Client.Infrastructure\Client.Infrastructure.csproj", "{28E5DFC7-A05B-40DB-9E35-AC1E84C008A2}"
1313
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F6BE3160-F6ED-4E11-A33F-063DD9186D84}"
15+
ProjectSection(SolutionItems) = preProject
16+
.editorconfig = .editorconfig
17+
.gitignore = .gitignore
18+
Directory.Build.props = Directory.Build.props
19+
Directory.Build.targets = Directory.Build.targets
20+
dotnet.ruleset = dotnet.ruleset
21+
global.json = global.json
22+
stylecop.json = stylecop.json
23+
EndProjectSection
24+
EndProject
1425
Global
1526
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1627
Debug|Any CPU = Debug|Any CPU

src/Client.Infrastructure/Client.Infrastructure.csproj

+3-21
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
<RootNamespace>FSH.BlazorWebAssembly.Client.Infrastructure</RootNamespace>
66
<AssemblyName>FSH.BlazorWebAssembly.Client.Infrastructure</AssemblyName>
77
</PropertyGroup>
8-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9-
<DocumentationFile>Client.Infrastructure.xml</DocumentationFile>
10-
<CodeAnalysisRuleSet>..\..\dotnet.ruleset</CodeAnalysisRuleSet>
11-
</PropertyGroup>
8+
129
<ItemGroup>
10+
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
1311
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.0" />
1412
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
1513
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
@@ -21,7 +19,6 @@
2119
<PackageReference Include="Microsoft.Extensions.Localization" Version="6.0.0" />
2220
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.0" />
2321
<PackageReference Include="MudBlazor" Version="6.0.2" />
24-
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
2522
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2623
<PackageReference Include="Toolbelt.Blazor.HttpClientInterceptor" Version="10.0.0" />
2724
</ItemGroup>
@@ -30,19 +27,4 @@
3027
<ProjectReference Include="..\Shared\Shared.csproj" />
3128
</ItemGroup>
3229

33-
<ItemGroup>
34-
<Folder Include="SignalR\" />
35-
<Folder Include="Services\Identity\User\" />
36-
</ItemGroup>
37-
<ItemGroup>
38-
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2">
39-
<PrivateAssets>all</PrivateAssets>
40-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
41-
</PackageReference>
42-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
43-
<PrivateAssets>all</PrivateAssets>
44-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
45-
</PackageReference>
46-
<AdditionalFiles Include="..\..\stylecop.json" />
47-
</ItemGroup>
48-
</Project>
30+
</Project>

src/Client.Infrastructure/Client.Infrastructure.xml

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
using Blazored.LocalStorage;
2-
using Microsoft.AspNetCore.SignalR.Client;
1+
using Microsoft.AspNetCore.SignalR.Client;
32

4-
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Extensions
3+
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Extensions;
4+
5+
public static class HubExtensions
56
{
6-
public static class HubExtensions
7+
public static HubConnection TryInitialize(this HubConnection hubConnection, ILocalStorageService localStorage, string apiBaseUri)
78
{
8-
public static HubConnection TryInitialize(this HubConnection hubConnection, ILocalStorageService localStorage, string apiBaseUri)
9+
if (hubConnection == null)
910
{
10-
if (hubConnection == null)
11-
{
12-
hubConnection = new HubConnectionBuilder()
13-
.WithUrl($"{apiBaseUri}notifications", options =>
14-
{
15-
options.AccessTokenProvider = async () => (await localStorage.GetItemAsync<string>("authToken"));
16-
})
17-
.WithAutomaticReconnect()
18-
.Build();
19-
}
20-
21-
return hubConnection;
11+
hubConnection = new HubConnectionBuilder()
12+
.WithUrl($"{apiBaseUri}notifications", options =>
13+
{
14+
options.AccessTokenProvider = async () => (await localStorage.GetItemAsync<string>("authToken"));
15+
})
16+
.WithAutomaticReconnect()
17+
.Build();
2218
}
19+
20+
return hubConnection;
2321
}
2422
}

src/Client.Infrastructure/Extensions/WebAssemblyHostBuilderExtensions.cs

+73-75
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,96 @@
1-
using FSH.BlazorWebAssembly.Client.Infrastructure.Authentication;
1+
using System.Globalization;
2+
using System.Reflection;
3+
using FSH.BlazorWebAssembly.Client.Infrastructure.Authentication;
24
using FSH.BlazorWebAssembly.Client.Infrastructure.Managers;
35
using FSH.BlazorWebAssembly.Client.Infrastructure.Managers.Preferences;
46
using Microsoft.AspNetCore.Authorization;
57
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
68
using Microsoft.Extensions.DependencyInjection;
7-
using Microsoft.Extensions.Options;
89
using MudBlazor;
910
using MudBlazor.Services;
10-
using System.Globalization;
11-
using System.Reflection;
1211
using Toolbelt.Blazor.Extensions.DependencyInjection;
1312

14-
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Extensions
13+
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Extensions;
14+
15+
public static class WebAssemblyHostBuilderExtensions
1516
{
16-
public static class WebAssemblyHostBuilderExtensions
17+
private const string ClientName = "FullStackHero.API";
18+
public static WebAssemblyHostBuilder AddClientServices(this WebAssemblyHostBuilder builder, WebAssemblyHostConfiguration configs)
1719
{
18-
private const string ClientName = "FullStackHero.API";
19-
public static WebAssemblyHostBuilder AddClientServices(this WebAssemblyHostBuilder builder, WebAssemblyHostConfiguration configs)
20-
{
21-
builder
22-
.Services
23-
.AddDistributedMemoryCache()
24-
.AddLocalization(options =>
25-
{
26-
options.ResourcesPath = "Resources";
27-
})
28-
.AddAuthorizationCore(options =>
29-
{
30-
RegisterPermissionClaims(options);
31-
})
32-
.AddBlazoredLocalStorage()
33-
.AddMudServices(configuration =>
34-
{
35-
configuration.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomRight;
36-
configuration.SnackbarConfiguration.HideTransitionDuration = 100;
37-
configuration.SnackbarConfiguration.ShowTransitionDuration = 100;
38-
configuration.SnackbarConfiguration.VisibleStateDuration = 3000;
39-
configuration.SnackbarConfiguration.ShowCloseIcon = false;
40-
})
41-
.AddScoped<ClientPreferenceManager>()
42-
.AddScoped<ApplicationAuthenticationStateProvider>()
43-
.AddScoped<AuthenticationStateProvider, ApplicationAuthenticationStateProvider>()
44-
.AddTransient<AuthenticationHeaderHandler>()
45-
.AutoRegisterInterfaces<IManager>()
46-
.AutoRegisterInterfaces<IApiService>()
47-
.AddScoped(sp => sp
48-
.GetRequiredService<IHttpClientFactory>()
49-
.CreateClient(ClientName).EnableIntercept(sp))
50-
.AddHttpClient(ClientName, client =>
51-
{
52-
client.DefaultRequestHeaders.AcceptLanguage.Clear();
53-
client.DefaultRequestHeaders.AcceptLanguage.ParseAdd(CultureInfo.DefaultThreadCurrentCulture?.TwoLetterISOLanguageName);
54-
client.BaseAddress = new Uri(configs.GetValue<string>(ClientName));
55-
})
56-
.AddHttpMessageHandler<AuthenticationHeaderHandler>();
57-
builder.Services.AddHttpClientInterceptor();
58-
return builder;
59-
}
20+
builder
21+
.Services
22+
.AddDistributedMemoryCache()
23+
.AddLocalization(options =>
24+
{
25+
options.ResourcesPath = "Resources";
26+
})
27+
.AddAuthorizationCore(options =>
28+
{
29+
RegisterPermissionClaims(options);
30+
})
31+
.AddBlazoredLocalStorage()
32+
.AddMudServices(configuration =>
33+
{
34+
configuration.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomRight;
35+
configuration.SnackbarConfiguration.HideTransitionDuration = 100;
36+
configuration.SnackbarConfiguration.ShowTransitionDuration = 100;
37+
configuration.SnackbarConfiguration.VisibleStateDuration = 3000;
38+
configuration.SnackbarConfiguration.ShowCloseIcon = false;
39+
})
40+
.AddScoped<ClientPreferenceManager>()
41+
.AddScoped<ApplicationAuthenticationStateProvider>()
42+
.AddScoped<AuthenticationStateProvider, ApplicationAuthenticationStateProvider>()
43+
.AddTransient<AuthenticationHeaderHandler>()
44+
.AutoRegisterInterfaces<IManager>()
45+
.AutoRegisterInterfaces<IApiService>()
46+
.AddScoped(sp => sp
47+
.GetRequiredService<IHttpClientFactory>()
48+
.CreateClient(ClientName).EnableIntercept(sp))
49+
.AddHttpClient(ClientName, client =>
50+
{
51+
client.DefaultRequestHeaders.AcceptLanguage.Clear();
52+
client.DefaultRequestHeaders.AcceptLanguage.ParseAdd(CultureInfo.DefaultThreadCurrentCulture?.TwoLetterISOLanguageName);
53+
client.BaseAddress = new Uri(configs.GetValue<string>(ClientName));
54+
})
55+
.AddHttpMessageHandler<AuthenticationHeaderHandler>();
56+
builder.Services.AddHttpClientInterceptor();
57+
return builder;
58+
}
6059

61-
public static IServiceCollection AutoRegisterInterfaces<T>(this IServiceCollection services)
62-
{
63-
var @interface = typeof(T);
60+
public static IServiceCollection AutoRegisterInterfaces<T>(this IServiceCollection services)
61+
{
62+
var @interface = typeof(T);
6463

65-
var types = @interface
66-
.Assembly
67-
.GetExportedTypes()
68-
.Where(t => t.IsClass && !t.IsAbstract)
69-
.Select(t => new
70-
{
71-
Service = t.GetInterface($"I{t.Name}"),
72-
Implementation = t
73-
})
74-
.Where(t => t.Service != null);
64+
var types = @interface
65+
.Assembly
66+
.GetExportedTypes()
67+
.Where(t => t.IsClass && !t.IsAbstract)
68+
.Select(t => new
69+
{
70+
Service = t.GetInterface($"I{t.Name}"),
71+
Implementation = t
72+
})
73+
.Where(t => t.Service != null);
7574

76-
foreach (var type in types)
75+
foreach (var type in types)
76+
{
77+
if (@interface.IsAssignableFrom(type.Service))
7778
{
78-
if (@interface.IsAssignableFrom(type.Service))
79-
{
80-
services.AddTransient(type.Service, type.Implementation);
81-
}
79+
services.AddTransient(type.Service, type.Implementation);
8280
}
83-
84-
return services;
8581
}
8682

87-
private static void RegisterPermissionClaims(AuthorizationOptions options)
83+
return services;
84+
}
85+
86+
private static void RegisterPermissionClaims(AuthorizationOptions options)
87+
{
88+
foreach (var prop in typeof(PermissionConstants).GetNestedTypes().SelectMany(c => c.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)))
8889
{
89-
foreach (var prop in typeof(PermissionConstants).GetNestedTypes().SelectMany(c => c.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)))
90+
object propertyValue = prop.GetValue(null);
91+
if (propertyValue is not null)
9092
{
91-
object propertyValue = prop.GetValue(null);
92-
if (propertyValue is not null)
93-
{
94-
options.AddPolicy(propertyValue.ToString(), policy => policy.RequireClaim(ClaimConstants.Permission, propertyValue.ToString()));
95-
}
93+
options.AddPolicy(propertyValue.ToString(), policy => policy.RequireClaim(ClaimConstants.Permission, propertyValue.ToString()));
9694
}
9795
}
9896
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
global using Blazored.LocalStorage;
2-
global using FSH.BlazorWebAssembly.Shared.Catalog;
3-
global using FSH.BlazorWebAssembly.Shared.Constants;
4-
global using FSH.BlazorWebAssembly.Shared.Routes;
5-
global using FSH.BlazorWebAssembly.Shared.Wrapper;
6-
global using Microsoft.AspNetCore.Components.Authorization;
7-
global using System;
1+
global using System;
82
global using System.Collections.Generic;
93
global using System.Linq;
104
global using System.Net.Http;
@@ -14,5 +8,11 @@
148
global using System.Text.Json;
159
global using System.Threading;
1610
global using System.Threading.Tasks;
11+
global using Blazored.LocalStorage;
12+
global using FSH.BlazorWebAssembly.Shared.Catalog;
13+
global using FSH.BlazorWebAssembly.Shared.Constants;
14+
global using FSH.BlazorWebAssembly.Shared.Routes;
15+
global using FSH.BlazorWebAssembly.Shared.Wrapper;
1716
global using Microsoft.AspNetCore.Builder;
17+
global using Microsoft.AspNetCore.Components.Authorization;
1818
global using Microsoft.Extensions.Configuration;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Managers
1+
namespace FSH.BlazorWebAssembly.Client.Infrastructure.Managers;
2+
3+
public interface IManager
24
{
3-
public interface IManager
4-
{
5-
}
65
}

0 commit comments

Comments
 (0)