Skip to content

Commit e71a9e2

Browse files
Refactoring to DI (#1243)
1 parent d698c82 commit e71a9e2

File tree

223 files changed

+13579
-12754
lines changed

Some content is hidden

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

223 files changed

+13579
-12754
lines changed

.editorconfig

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary
3939
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
4040

4141
# Modifier preferences
42-
dotnet_style_require_accessibility_modifiers = for_non_interface_members
42+
dotnet_style_require_accessibility_modifiers = never
4343

4444
# Expression-level preferences
4545
dotnet_style_coalesce_expression = true
@@ -76,17 +76,17 @@ dotnet_style_allow_statement_immediately_after_block_experimental = true
7676
#### C# Coding Conventions ####
7777

7878
# var preferences
79-
csharp_style_var_elsewhere = false
80-
csharp_style_var_for_built_in_types = false
81-
csharp_style_var_when_type_is_apparent = false
79+
csharp_style_var_elsewhere = true
80+
csharp_style_var_for_built_in_types = true
81+
csharp_style_var_when_type_is_apparent = true
8282

8383
# Expression-bodied members
8484
csharp_style_expression_bodied_accessors = true
8585
csharp_style_expression_bodied_constructors = false
8686
csharp_style_expression_bodied_indexers = true
8787
csharp_style_expression_bodied_lambdas = true
8888
csharp_style_expression_bodied_local_functions = false
89-
csharp_style_expression_bodied_methods = false
89+
csharp_style_expression_bodied_methods = when_on_single_line
9090
csharp_style_expression_bodied_operators = false
9191
csharp_style_expression_bodied_properties = true
9292

@@ -108,7 +108,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter
108108
# Code-block preferences
109109
csharp_prefer_braces = true
110110
csharp_prefer_simple_using_statement = true
111-
csharp_style_namespace_declarations = block_scoped
111+
csharp_style_namespace_declarations = file_scoped
112112
csharp_style_prefer_method_group_conversion = true
113113
csharp_style_prefer_top_level_statements = true
114114

@@ -223,3 +223,44 @@ dotnet_naming_style.begins_with_i.required_prefix = I
223223
dotnet_naming_style.begins_with_i.required_suffix =
224224
dotnet_naming_style.begins_with_i.word_separator =
225225
dotnet_naming_style.begins_with_i.capitalization = pascal_case
226+
227+
# Do not catch general exception types
228+
dotnet_diagnostic.CA1031.severity = none
229+
# URI parameters should not be strings
230+
dotnet_diagnostic.CA1054.severity = none
231+
# URI properties should not be strings
232+
dotnet_diagnostic.CA1056.severity = none
233+
# Do not pass literals as localized parameters
234+
dotnet_diagnostic.CA1303.severity = none
235+
# Normalize strings to uppercase
236+
dotnet_diagnostic.CA1308.severity = none
237+
# Avoid uninstantiated internal classes
238+
dotnet_diagnostic.CA1812.severity = none
239+
# Use the LoggerMessage delegates
240+
dotnet_diagnostic.CA1848.severity = none
241+
# Possible multiple enumerations of IEnumerable collection
242+
dotnet_diagnostic.CA1851.severity = none
243+
# Do not directly await a Task
244+
dotnet_diagnostic.CA2007.severity = none
245+
# Pass System.Uri objects instead of strings
246+
dotnet_diagnostic.CA2234.severity = none
247+
# Do not use insecure randomness
248+
dotnet_diagnostic.CA5394.severity = none
249+
# IDE0005: Using directive is unnecessary
250+
dotnet_diagnostic.IDE0005.severity = warning
251+
# Use expression body for methods
252+
dotnet_diagnostic.IDE0022.severity = none
253+
# Use conditional expression for assignment
254+
dotnet_diagnostic.IDE0045.severity = none
255+
# Use conditional expression for return
256+
dotnet_diagnostic.IDE0046.severity = none
257+
# Use GeneratedRegexAttribute to generate the regular expression implementation at compile time.
258+
dotnet_diagnostic.SYSLIB1045.severity = none
259+
# Implement internal logic asynchronously
260+
dotnet_diagnostic.VSTHRD102.severity = none
261+
# Offer async option
262+
dotnet_diagnostic.VSTHRD104.severity = none
263+
# Add .ConfigureAwait(bool) to your await expression
264+
dotnet_diagnostic.VSTHRD111.severity = none
265+
266+
dotnet_analyzer_diagnostic.severity = warning

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
* text=auto
12
*.sh text eol=lf

.github/workflows/create-release.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ jobs:
3939
if: contains(github.ref_name, '-beta')
4040
run: |
4141
pushd
42-
cd ./dev-proxy
43-
$content = Get-Content dev-proxy.csproj
44-
$content -replace '<AssemblyName>devproxy</AssemblyName>', '<AssemblyName>devproxy-beta</AssemblyName>' | Set-Content dev-proxy.csproj
42+
cd ./DevProxy
43+
$content = Get-Content DevProxy.csproj
44+
$content -replace '<AssemblyName>devproxy</AssemblyName>', '<AssemblyName>devproxy-beta</AssemblyName>' | Set-Content DevProxy.csproj
4545
popd
4646
- name: Set newVersionNotification for beta
4747
if: contains(github.ref_name, '-beta')
4848
run: |
4949
pushd
50-
cd ./dev-proxy
50+
cd ./DevProxy
5151
$content = Get-Content devproxyrc.json
5252
$content -replace '"newVersionNotification": "stable"', '"newVersionNotification": "beta"' | Set-Content devproxyrc.json
5353
popd
5454
- name: Publish ${{ matrix.architecture }}
55-
run: dotnet publish ./dev-proxy/dev-proxy.csproj -c Release -p:PublishSingleFile=true -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -r ${{ matrix.architecture }} --self-contained -o ./${{ env.release }}
55+
run: dotnet publish ./DevProxy/DevProxy.csproj -c Release -p:PublishSingleFile=true -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -r ${{ matrix.architecture }} --self-contained -o ./${{ env.release }}
5656
- name: Build plugins
57-
run: dotnet build ./dev-proxy-plugins/dev-proxy-plugins.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release -r ${{ matrix.architecture }} --no-self-contained
57+
run: dotnet build ./DevProxy.Plugins/DevProxy.Plugins.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release -r ${{ matrix.architecture }} --no-self-contained
5858
- name: Build abstractions
5959
if: matrix.architecture == 'win-x64'
60-
run: dotnet build ./dev-proxy-abstractions/dev-proxy-abstractions.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release --no-self-contained
60+
run: dotnet build ./DevProxy.Abstractions/DevProxy.Abstractions.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release --no-self-contained
6161
- name: Add plugins to output
62-
run: cp ./dev-proxy/bin/Release/net9.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r
62+
run: cp ./DevProxy/bin/Release/net9.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r
6363
- name: Remove unnecessary files
6464
run: |
6565
pushd
@@ -84,7 +84,7 @@ jobs:
8484
shell: pwsh
8585
run: >
8686
../sign code azure-key-vault
87-
**/dev*proxy*
87+
**/DevProxy*
8888
--publisher-name "${{ env.APP_PUBLISHER }}"
8989
--description "${{ env.APP_DESCRIPTION }}"
9090
--description-url "${{ env.APP_DESCRIPTION_URL }}"
@@ -112,7 +112,7 @@ jobs:
112112
shell: pwsh
113113
run: >
114114
./sign code azure-key-vault
115-
./dev-proxy-abstractions/bin/Release/net9.0/dev-proxy-abstractions.dll
115+
./DevProxy.Abstractions/bin/Release/net9.0/DevProxy.Abstractions.dll
116116
--publisher-name "${{ env.APP_PUBLISHER }}"
117117
--description "${{ env.APP_DESCRIPTION }}"
118118
--description-url "${{ env.APP_DESCRIPTION_URL }}"
@@ -126,15 +126,15 @@ jobs:
126126
if: matrix.architecture == 'win-x64'
127127
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 # master
128128
with:
129-
filename: '../../../../dev-proxy-abstractions-${{ github.ref_name }}.zip'
130-
directory: './dev-proxy-abstractions/bin/Release/net9.0'
129+
filename: '../../../../DevProxy.Abstractions-${{ github.ref_name }}.zip'
130+
directory: './DevProxy.Abstractions/bin/Release/net9.0'
131131
exclusions: '*.json'
132132
- name: Upload abstractions
133133
if: matrix.architecture == 'win-x64'
134134
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
135135
with:
136136
name: binaries-dev-proxy-abstractions-${{ github.ref_name }}
137-
path: ./dev-proxy-abstractions-${{ github.ref_name }}.zip
137+
path: ./DevProxy.Abstractions-${{ github.ref_name }}.zip
138138
- name: Add installer icon
139139
if: contains(matrix.architecture, 'win-')
140140
run: |

.github/workflows/dotnet.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
- name: Restore workloads
2727
run: dotnet workload restore
2828
- name: Restore dependencies
29-
run: dotnet restore dev-proxy.sln --locked-mode
29+
run: dotnet restore DevProxy.sln --locked-mode
3030
- name: Build
31-
run: dotnet build dev-proxy.sln --no-restore
31+
run: dotnet build DevProxy.sln --no-restore
3232
# We really should have tests, putting these steps here for when we have a build process
3333
# - name: Test
34-
# run: dotnet test dev-proxy.sln --no-build --verbosity normal --collect:"XPlat Code Coverage"
34+
# run: dotnet test DevProxy.sln --no-build --verbosity normal --collect:"XPlat Code Coverage"
3535
# - name: Install report generator
3636
# run: dotnet tool install --global dotnet-reportgenerator-globaltool
3737
# - name: Generate coverage report

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/dev-proxy/bin/Debug/net9.0/devproxy.dll",
13+
"program": "${workspaceFolder}/DevProxy/bin/Debug/net9.0/devproxy.dll",
1414
"args": [],
15-
"cwd": "${workspaceFolder}/dev-proxy/bin/Debug/net9.0",
15+
"cwd": "${workspaceFolder}/DevProxy/bin/Debug/net9.0",
1616
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
1717
"console": "integratedTerminal",
1818
"stopAtEntry": false,

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "process",
88
"args": [
99
"build",
10-
"${workspaceFolder}/dev-proxy.sln",
10+
"${workspaceFolder}/DevProxy.sln",
1111
"/property:GenerateFullPaths=true",
1212
"/consoleloggerparameters:NoSummary"
1313
],
@@ -23,7 +23,7 @@
2323
"type": "process",
2424
"args": [
2525
"publish",
26-
"${workspaceFolder}/dev-proxy.sln",
26+
"${workspaceFolder}/DevProxy.sln",
2727
"/property:GenerateFullPaths=true",
2828
"/consoleloggerparameters:NoSummary"
2929
],
@@ -37,7 +37,7 @@
3737
"watch",
3838
"run",
3939
"--project",
40-
"${workspaceFolder}/dev-proxy.sln"
40+
"${workspaceFolder}/DevProxy.sln"
4141
],
4242
"problemMatcher": "$msCompile"
4343
}

dev-proxy-abstractions/dev-proxy-abstractions.csproj renamed to DevProxy.Abstractions/DevProxy.Abstractions.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<Version>0.28.0</Version>
99
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1010
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
1113
</PropertyGroup>
1214

1315
<ItemGroup>
Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,56 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
3-
// See the LICENSE file in the project root for more information.
4-
5-
using System.CommandLine;
6-
using System.CommandLine.Parsing;
7-
8-
namespace DevProxy.Abstractions;
9-
10-
public static class CommandLineExtensions
11-
{
12-
public static T? GetValueForOption<T>(this ParseResult parseResult, string optionName, Option[] options)
13-
{
14-
// we need to remove the leading - because CommandLine stores the option
15-
// name without them
16-
if (options
17-
.FirstOrDefault(o => o.Name == optionName.TrimStart('-')) is not Option<T> option)
18-
{
19-
throw new InvalidOperationException($"Could not find option with name {optionName} and value type {typeof(T).Name}");
20-
}
21-
22-
return parseResult.GetValueForOption(option);
23-
}
24-
25-
private static string ByName<T>(T symbol) where T : Symbol => symbol.Name;
26-
27-
public static IEnumerable<T> OrderByName<T>(this IEnumerable<T> symbols) where T : Symbol
28-
{
29-
ArgumentNullException.ThrowIfNull(symbols);
30-
31-
return symbols.OrderBy(ByName, StringComparer.Ordinal);
32-
}
33-
34-
public static Command AddCommands(this Command command, IEnumerable<Command> subcommands)
35-
{
36-
ArgumentNullException.ThrowIfNull(command);
37-
ArgumentNullException.ThrowIfNull(subcommands);
38-
39-
foreach (var subcommand in subcommands)
40-
{
41-
command.AddCommand(subcommand);
42-
}
43-
return command;
44-
}
45-
46-
public static Command AddOptions(this Command command, IEnumerable<Option> options)
47-
{
48-
ArgumentNullException.ThrowIfNull(command);
49-
ArgumentNullException.ThrowIfNull(options);
50-
51-
foreach (var option in options)
52-
{
53-
command.AddOption(option);
54-
}
55-
return command;
56-
}
57-
}
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#pragma warning disable IDE0130
6+
namespace System.CommandLine.Parsing;
7+
#pragma warning restore IDE0130
8+
9+
public static class CommandLineExtensions
10+
{
11+
public static T? GetValueForOption<T>(this ParseResult parseResult, string optionName, IReadOnlyList<Option> options)
12+
{
13+
ArgumentNullException.ThrowIfNull(parseResult);
14+
15+
// we need to remove the leading - because CommandLine stores the option
16+
// name without them
17+
if (options
18+
.FirstOrDefault(o => o.Name == optionName.TrimStart('-')) is not Option<T> option)
19+
{
20+
throw new InvalidOperationException($"Could not find option with name {optionName} and value type {typeof(T).Name}");
21+
}
22+
23+
return parseResult.GetValueForOption(option);
24+
}
25+
26+
public static IEnumerable<T> OrderByName<T>(this IEnumerable<T> symbols) where T : Symbol
27+
{
28+
ArgumentNullException.ThrowIfNull(symbols);
29+
30+
return symbols.OrderBy(ByName, StringComparer.Ordinal);
31+
}
32+
33+
public static void AddCommands(this Command command, IEnumerable<Command> subcommands)
34+
{
35+
ArgumentNullException.ThrowIfNull(command);
36+
ArgumentNullException.ThrowIfNull(subcommands);
37+
38+
foreach (var subcommand in subcommands)
39+
{
40+
command.AddCommand(subcommand);
41+
}
42+
}
43+
44+
public static void AddOptions(this Command command, IEnumerable<Option> options)
45+
{
46+
ArgumentNullException.ThrowIfNull(command);
47+
ArgumentNullException.ThrowIfNull(options);
48+
49+
foreach (var option in options)
50+
{
51+
command.AddOption(option);
52+
}
53+
}
54+
55+
private static string ByName<T>(T symbol) where T : Symbol => symbol.Name;
56+
}

0 commit comments

Comments
 (0)