diff --git a/.editorconfig b/.editorconfig index 134e57859..57b2d5ae6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,8 +1,5 @@ -; EditorConfig to support per-solution formatting. -; Use the EditorConfig VS add-in to make this work. -; http://editorconfig.org/ - -; This is the default for the codeline. +# EditorConfig to support per-solution formatting. +# http://editorconfig.org/ root = true [*] @@ -10,13 +7,187 @@ indent_style = space trim_trailing_whitespace = true insert_final_newline = true -; .NET Code - almost, but not exactly, the same suggestions as corefx -; https://github.com/dotnet/corefx/blob/master/.editorconfig +# .NET Code [*.cs] indent_size = 4 charset = utf-8-bom -; New line preferences +# .NET project files and MSBuild - match defaults for VS +[*.{csproj,nuspec,proj,projitems,props,shproj,targets,vbproj,vcxproj,vcxproj.filters,vsixmanifest,vsct}] +indent_size = 2 + +# .NET solution files - match defaults for VS +[*.sln] +end_of_line = crlf +indent_style = tab + +# .NET XML solution files - match dotnet new sln defaults +[*.slnx] +indent_size = 2 + + +# Config - match XML and default nuget.config template +[*.config] +indent_size = 2 + +# Resources - match defaults for VS +[*.resx] +indent_size = 2 + +# Static analysis rulesets - match defaults for VS +[*.ruleset] +indent_size = 2 + +# HTML, XML - match defaults for VS +[*.{cshtml,html,xml}] +indent_size = 4 + +# JavaScript and JS mixes - match eslint settings; JSON also matches .NET Core templates +[*.{js,json,mjs,ts,vue}] +indent_size = 2 + +# Markdown - match markdownlint settings +[*.{md,markdown}] +indent_size = 2 + +# PowerShell - match defaults for New-ModuleManifest and PSScriptAnalyzer Invoke-Formatter +[*.{ps1,psd1,psm1}] +indent_size = 4 +charset = utf-8-bom + +# YAML - match standard YAML like Kubernetes and GitHub Actions +[*.{yaml,yml}] +indent_size = 2 + +# ReStructuredText - standard indentation format from examples +[*.rst] +indent_size = 2 + +# +# dotnet code style +# +[*.cs] + +# Sort using and Import directives with System.* appearing first +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = false + +# Avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Use language keywords instead of framework type names for type references +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# Suggest more modern language features when available +dotnet_style_object_initializer = true:warning +dotnet_style_collection_initializer = true:warning +dotnet_style_coalesce_expression = true:warning +dotnet_style_null_propagation = true:warning +dotnet_style_explicit_tuple_names = true:warning + +# Whitespace options +dotnet_style_allow_multiple_blank_lines_experimental = false + +# Non-private static fields are PascalCase +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = warning +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style + +dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected +dotnet_naming_symbols.non_private_static_fields.required_modifiers = static + +dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case + +# Non-private readonly fields are PascalCase +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = warning +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style + +dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field +dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected +dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly + +dotnet_naming_style.non_private_readonly_field_style.capitalization = pascal_case + +# Constants are PascalCase +dotnet_naming_rule.constants_should_be_pascal_case.severity = warning +dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants +dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style + +dotnet_naming_symbols.constants.applicable_kinds = field, local +dotnet_naming_symbols.constants.required_modifiers = const + +dotnet_naming_style.constant_style.capitalization = pascal_case + +# Static fields should be _camelCase +dotnet_naming_rule.static_fields_should_be_camel_case.severity = warning +dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields +dotnet_naming_rule.static_fields_should_be_camel_case.style = camel_case_underscore_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static + +dotnet_naming_style.static_field_style.capitalization = camel_case + +# Instance fields are camelCase and start with _ +dotnet_naming_rule.instance_fields_should_be_camel_case.severity = warning +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 = _ + +# Locals and parameters are camelCase +dotnet_naming_rule.locals_should_be_camel_case.severity = warning +dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters +dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style + +dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local + +dotnet_naming_style.camel_case_style.capitalization = camel_case + +# Local functions are PascalCase +dotnet_naming_rule.local_functions_should_be_pascal_case.severity = warning +dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions +dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style + +dotnet_naming_symbols.local_functions.applicable_kinds = local_function + +dotnet_naming_style.local_function_style.capitalization = pascal_case + +# By default, name items with PascalCase +dotnet_naming_rule.members_should_be_pascal_case.severity = warning +dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members +dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style + +dotnet_naming_symbols.all_members.applicable_kinds = * + +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# IDE0035: Remove unreachable code +dotnet_diagnostic.IDE0035.severity = warning + +# IDE0036: Order modifiers +dotnet_diagnostic.IDE0036.severity = warning + +# IDE0043: Format string contains invalid placeholder +dotnet_diagnostic.IDE0043.severity = warning + +# IDE0044: Make field readonly +dotnet_diagnostic.IDE0044.severity = warning + +# IDE0055: Fix formatting +dotnet_diagnostic.IDE0055.severity = warning + +# C# code style +# +# Newline settings csharp_new_line_before_open_brace = all csharp_new_line_before_else = true csharp_new_line_before_catch = true @@ -25,90 +196,34 @@ csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_between_query_expression_clauses = true -; Indentation preferences +# Indentation preferences csharp_indent_block_contents = true csharp_indent_braces = false csharp_indent_case_contents = true csharp_indent_case_contents_when_block = true csharp_indent_switch_labels = true -csharp_indent_labels = one_less_than_current +csharp_indent_labels = flush_left -; Modifier preferences -csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:warning - -; Avoid this. unless absolutely necessary -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_property = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_event = false:suggestion +# Whitespace options +# Each of the *_experimental rules has a corresponding IDE* setting. +csharp_style_allow_embedded_statements_on_same_line_experimental = false +dotnet_diagnostic.IDE2001.severity = warning +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false +dotnet_diagnostic.IDE2002.severity = warning +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false +dotnet_diagnostic.IDE2004.severity = warning +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false +dotnet_diagnostic.IDE2005.severity = warning +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false +dotnet_diagnostic.IDE2006.severity = warning -; Types: use keywords instead of BCL types, using var is fine. -csharp_style_var_when_type_is_apparent = false:none -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion - -; Name all constant fields using PascalCase -dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning -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.required_modifiers = const -dotnet_naming_style.pascal_case_style.capitalization = pascal_case +# Prefer "var" everywhere +dotnet_diagnostic.IDE0007.severity = warning +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_elsewhere = true:warning -; Static fields should be _camelCase -dotnet_naming_rule.static_fields_should_be_camel_case.severity = warning -dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields -dotnet_naming_rule.static_fields_should_be_camel_case.style = camel_case_underscore_style -dotnet_naming_symbols.static_fields.applicable_kinds = field -dotnet_naming_symbols.static_fields.required_modifiers = static -dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected - -; Static readonly fields should be PascalCase -dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.severity = warning -dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.symbols = static_readonly_fields -dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.style = pascal_case_style -dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field -dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly -dotnet_naming_symbols.static_readonly_fields.applicable_accessibilities = private, internal, private_protected - -; Internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case - -; Code style defaults -csharp_using_directive_placement = outside_namespace:suggestion -dotnet_sort_system_directives_first = true -csharp_prefer_braces = true:refactoring -csharp_preserve_single_line_blocks = true:none -csharp_preserve_single_line_statements = false:none -csharp_prefer_static_local_function = true:suggestion -csharp_prefer_simple_using_statement = false:none -csharp_style_prefer_switch_expression = true:suggestion - -; Code quality -dotnet_style_readonly_field = true:suggestion -dotnet_code_quality_unused_parameters = non_public:suggestion - -; Expression-level preferences -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_coalesce_expression = true:suggestion -dotnet_style_null_propagation = true:suggestion -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_style_prefer_inferred_tuple_names = true:suggestion -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion -dotnet_style_prefer_auto_properties = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring -dotnet_style_prefer_conditional_expression_over_return = true:refactoring -csharp_prefer_simple_default_expression = true:suggestion - -# Expression-bodied members +# Prefer method-like constructs to have a block body csharp_style_expression_bodied_methods = true:refactoring csharp_style_expression_bodied_constructors = true:refactoring csharp_style_expression_bodied_operators = true:refactoring @@ -118,20 +233,15 @@ csharp_style_expression_bodied_accessors = true:refactoring csharp_style_expression_bodied_lambdas = true:refactoring csharp_style_expression_bodied_local_functions = true:refactoring -# Pattern matching -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_inlined_variable_declaration = true:suggestion - -# Null checking preferences -csharp_style_throw_expression = true:suggestion -csharp_style_conditional_delegate_call = true:suggestion - -# Other features -csharp_style_namespace_declarations = file_scoped:suggestion -csharp_style_prefer_index_operator = false:none -csharp_style_prefer_range_operator = false:none -csharp_style_pattern_local_over_anonymous_function = false:none +# Suggest more modern language features when available +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_inlined_variable_declaration = true:warning +csharp_style_throw_expression = true:warning +csharp_style_conditional_delegate_call = true:warning +csharp_style_prefer_extended_property_pattern = true:warning +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_parameter_null_checking = false # Space preferences csharp_space_after_cast = false @@ -157,48 +267,30 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false csharp_space_between_square_brackets = false -; .NET project files and MSBuild - match defaults for VS -[*.{csproj,nuspec,proj,projitems,props,shproj,targets,vbproj,vcxproj,vcxproj.filters,vsixmanifest,vsct}] -indent_size = 2 +# Blocks required +csharp_prefer_braces = true:warning +csharp_preserve_single_line_blocks = false +csharp_preserve_single_line_statements = false -; .NET solution files - match defaults for VS -[*.sln] -end_of_line = crlf -indent_style = tab +# IDE0011: Add braces +csharp_prefer_braces = when_multiline:warning +# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 +dotnet_diagnostic.IDE0011.severity = warning -; Config - match XML and default nuget.config template -[*.config] -indent_size = 2 +# IDE0040: Add accessibility modifiers +dotnet_diagnostic.IDE0040.severity = warning -; Resources - match defaults for VS -[*.resx] -indent_size = 2 +# IDE0052: Remove unread private member +dotnet_diagnostic.IDE0052.severity = warning -; Static analysis rulesets - match defaults for VS -[*.ruleset] -indent_size = 2 +# IDE0059: Unnecessary assignment to a value +dotnet_diagnostic.IDE0059.severity = warning -; HTML, XML - match defaults for VS -[*.{cshtml,html,xml}] -indent_size = 4 - -; JavaScript and JS mixes - match eslint settings; JSON also matches .NET Core templates -[*.{js,json,ts,vue}] -indent_size = 2 +# IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0060.severity = warning -; Markdown - match markdownlint settings -[*.{md,markdown}] -indent_size = 2 +# CA1012: Abstract types should not have public constructors +dotnet_diagnostic.CA1012.severity = warning -; PowerShell - match defaults for New-ModuleManifest and PSScriptAnalyzer Invoke-Formatter -[*.{ps1,psd1,psm1}] -indent_size = 4 -charset = utf-8-bom - -; ReStructuredText - standard indentation format from examples -[*.rst] -indent_size = 2 - -# YAML - match standard YAML like Kubernetes and GitHub Actions -[*.{yaml,yml}] -indent_size = 2 +# CA1822: Make member static +dotnet_diagnostic.CA1822.severity = warning diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bb960f05..806661866 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,13 +8,13 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/igorshubovych/markdownlint-cli - rev: "76b3d32d3f4b965e1d6425253c59407420ae2c43" # frozen: v0.47.0 + rev: "e72a3ca1632f0b11a07d171449fe447a7ff6795e" # frozen: v0.48.0 hooks: - id: markdownlint args: - --fix - repo: https://github.com/tillig/json-sort-cli - rev: "009ab2ab49e1f2fa9d6b9dfc31009ceeca055204" # frozen: v3.0.0 + rev: "2b7e147e0933bd30b58133b6f287e5c695ff4f0e" # frozen: v3.0.1 hooks: - id: json-sort args: diff --git a/bench/Autofac.BenchmarkProfiling/Program.cs b/bench/Autofac.BenchmarkProfiling/Program.cs index cd2025b6e..1bc529957 100644 --- a/bench/Autofac.BenchmarkProfiling/Program.cs +++ b/bench/Autofac.BenchmarkProfiling/Program.cs @@ -6,9 +6,9 @@ namespace Autofac.BenchmarkProfiling; /// /// Simple command-line tool to invoke a benchmark manually in a way that helps with profiling each of the benchmarks. /// -class Program +internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { // Pick a benchmark. var availableBenchmarks = Benchmarks.BenchmarkSet.All; @@ -84,7 +84,7 @@ static void Main(string[] args) // Workload method is generated differently when BenchmarkDotNet actually runs; we'll need to wrap it in the set of parameters. // It's way slower than they way they do it, but it should still give us good profiler results. - void workloadAction(int repeat) + void WorkloadAction(int repeat) { while (repeat > 0) { @@ -96,13 +96,13 @@ void workloadAction(int repeat) setupAction.InvokeSingle(); // Warmup. - workloadAction(100); + WorkloadAction(100); // Now start a new thread. var runThread = new Thread(new ThreadStart(() => { // Do a lot. - workloadAction(10000); + WorkloadAction(10000); })) { Name = "Workload Thread" @@ -124,7 +124,7 @@ private static void PrintBenchmarks(Type[] availableBenchmarks) private static void PrintCases(BenchmarkRunInfo benchRunInfo) { - for (int idx = 0; idx < benchRunInfo.BenchmarksCases.Length; idx++) + for (var idx = 0; idx < benchRunInfo.BenchmarksCases.Length; idx++) { var benchCase = benchRunInfo.BenchmarksCases[idx]; if (benchCase.HasParameters) diff --git a/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs b/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs index 50f18251d..c0e6bcaa7 100644 --- a/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs +++ b/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs @@ -24,10 +24,16 @@ public ConcurrencyBenchmark() } [Params(100 /*, 100, 1_000 */)] - public int ResolveTaskCount { get; set; } + public int ResolveTaskCount + { + get; set; + } [Params(100 /*, 1_000, 10_000 */)] - public int ResolvesPerTask { get; set; } + public int ResolvesPerTask + { + get; set; + } [Benchmark] public async Task MultipleResolvesOnMultipleTasks() @@ -40,11 +46,7 @@ public async Task MultipleResolvesOnMultipleTasks() { for (var j = 0; j < ResolvesPerTask; j++) { - var instance = _container.Resolve(); - if (instance is null) - { - throw new InvalidOperationException("Instance is null"); - } + var instance = _container.Resolve() ?? throw new InvalidOperationException("Instance is null"); } }); tasks.Add(task); diff --git a/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs b/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs index b68ca9a87..4e72bdf30 100644 --- a/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs +++ b/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs @@ -22,10 +22,16 @@ public ConcurrencyNestedScopeBenchmark() } [Params(100 /*, 100, 1_000 */)] - public int ConcurrentRequests { get; set; } + public int ConcurrentRequests + { + get; set; + } [Params(10)] - public int RepeatCount { get; set; } + public int RepeatCount + { + get; set; + } [Benchmark] public async Task MultipleResolvesOnMultipleTasks() @@ -41,25 +47,13 @@ public async Task MultipleResolvesOnMultipleTasks() // Start request using (var requestScope = _container.BeginLifetimeScope("request")) { - var service1 = requestScope.Resolve(); - if (service1 == null) - { - throw new InvalidOperationException("Service1 is null"); - } + var service1 = requestScope.Resolve() ?? throw new InvalidOperationException("Service1 is null"); using (var unitOfWorkScope = requestScope.BeginLifetimeScope()) { - var nestedRequestService2 = unitOfWorkScope.Resolve(); - if (nestedRequestService2 == null) - { - throw new InvalidOperationException("Nested request service is null"); - } + var nestedRequestService2 = unitOfWorkScope.Resolve() ?? throw new InvalidOperationException("Nested request service is null"); - var unitOfWork = unitOfWorkScope.Resolve(); - if (unitOfWork == null) - { - throw new InvalidOperationException("Unit of work is null"); - } + var unitOfWork = unitOfWorkScope.Resolve() ?? throw new InvalidOperationException("Unit of work is null"); } } } diff --git a/bench/Autofac.Benchmarks/Program.cs b/bench/Autofac.Benchmarks/Program.cs index 6e98befa4..47b502275 100644 --- a/bench/Autofac.Benchmarks/Program.cs +++ b/bench/Autofac.Benchmarks/Program.cs @@ -78,8 +78,8 @@ private static bool TryMatchBaselineArg(string arg, out string? valueFromAssignm { valueFromAssignment = null; - static bool Matches(string candidate) => - candidate.Equals("--baseline-version", StringComparison.OrdinalIgnoreCase) || + static bool Matches(string candidate) + => candidate.Equals("--baseline-version", StringComparison.OrdinalIgnoreCase) || candidate.Equals("--baselineVersion", StringComparison.OrdinalIgnoreCase); var equalsIndex = arg.AsSpan().IndexOf('='); diff --git a/bench/Autofac.Benchmarks/PropertyInjectionBenchmark.cs b/bench/Autofac.Benchmarks/PropertyInjectionBenchmark.cs index a98c3ee3d..a6fa210b7 100644 --- a/bench/Autofac.Benchmarks/PropertyInjectionBenchmark.cs +++ b/bench/Autofac.Benchmarks/PropertyInjectionBenchmark.cs @@ -30,29 +30,47 @@ public void Resolve() internal class A { - public B1? B1 { get; set; } + public B1? B1 + { + get; set; + } - public B2? B2 { get; set; } + public B2? B2 + { + get; set; + } } internal class B1 { - public C1? C1 { get; set; } + public C1? C1 + { + get; set; + } } internal class B2 { - public C2? C2 { get; set; } + public C2? C2 + { + get; set; + } } internal class C1 { - public D1? D1 { get; set; } + public D1? D1 + { + get; set; + } } internal class C2 { - public D2? D2 { get; set; } + public D2? D2 + { + get; set; + } } internal class D1 diff --git a/bench/Autofac.Benchmarks/RequiredPropertyBenchmark.cs b/bench/Autofac.Benchmarks/RequiredPropertyBenchmark.cs index a57544e67..667129535 100644 --- a/bench/Autofac.Benchmarks/RequiredPropertyBenchmark.cs +++ b/bench/Autofac.Benchmarks/RequiredPropertyBenchmark.cs @@ -48,15 +48,27 @@ public ConstructorComponent(ServiceA serviceA, ServiceB serviceB) ServiceB = serviceB; } - public ServiceA ServiceA { get; } + public ServiceA ServiceA + { + get; + } - public ServiceB ServiceB { get; } + public ServiceB ServiceB + { + get; + } } private class RequiredPropertyComponent { - public required ServiceA ServiceA { get; set; } + public required ServiceA ServiceA + { + get; set; + } - public required ServiceA ServiceB { get; set; } + public required ServiceA ServiceB + { + get; set; + } } } diff --git a/build/stylecop.json b/build/stylecop.json index 8f5c703d0..20da2f6e6 100644 --- a/build/stylecop.json +++ b/build/stylecop.json @@ -9,6 +9,9 @@ "licenseName": "MIT" }, "xmlHeader": false + }, + "orderingRules": { + "usingDirectivesPlacement": "outsideNamespace" } } } diff --git a/codegen/Autofac.CodeGen/DelegateRegisterGenerator.cs b/codegen/Autofac.CodeGen/DelegateRegisterGenerator.cs index c625ef909..9e118bec6 100644 --- a/codegen/Autofac.CodeGen/DelegateRegisterGenerator.cs +++ b/codegen/Autofac.CodeGen/DelegateRegisterGenerator.cs @@ -26,7 +26,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { // Set up an incremental generator that regenerates when the 'RegistrationExtensions' class changes. // Capture the INamedTypeSymbol when it does. - IncrementalValuesProvider classDeclarations = context.SyntaxProvider + var classDeclarations = context.SyntaxProvider .CreateSyntaxProvider( predicate: static (s, _) => s is ClassDeclarationSyntax classSyn && classSyn.Modifiers.Any(static m => m.IsKind(SyntaxKind.PartialKeyword)), transform: static (context, cancelToken) => @@ -47,7 +47,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Where(static m => m is not null)!; // Just get our first one (will only be one instance anyway, we just need to convert to a single value provider). - IncrementalValueProvider firstSyntax + var firstSyntax = classDeclarations.Collect().Select((all, _) => all.FirstOrDefault()); context.RegisterSourceOutput( @@ -74,9 +74,9 @@ private static void Execute(SourceProductionContext spc, INamedTypeSymbol? regEx spc, "RegistrationExtensions", "Register", - static (int argCount, bool hasComponentContext) => hasComponentContext ? - $"DelegateInvokers.DelegateInvoker{argCount}WithComponentContext" : - $"DelegateInvokers.DelegateInvoker{argCount}", + static (int argCount, bool hasComponentContext) => hasComponentContext + ? $"DelegateInvokers.DelegateInvoker{argCount}WithComponentContext" + : $"DelegateInvokers.DelegateInvoker{argCount}", NumberOfGenericArgs); } diff --git a/default.proj b/default.proj index 49be97cd7..3eea4279a 100644 --- a/default.proj +++ b/default.proj @@ -63,8 +63,8 @@ - - + + diff --git a/src/Autofac/Builder/BuildCallbackManager.cs b/src/Autofac/Builder/BuildCallbackManager.cs index ebe69af35..a825dbc88 100644 --- a/src/Autofac/Builder/BuildCallbackManager.cs +++ b/src/Autofac/Builder/BuildCallbackManager.cs @@ -12,7 +12,7 @@ internal static class BuildCallbackManager { private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey); - private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService)); + private static readonly TypedService _callbackServiceType = new(typeof(BuildCallbackService)); /// /// Executes the newly-registered build callbacks for a given scope/container.. @@ -20,7 +20,7 @@ internal static class BuildCallbackManager /// The new scope/container. internal static void RunBuildCallbacks(ILifetimeScope scope) { - var buildCallbackServices = scope.ComponentRegistry.ServiceRegistrationsFor(CallbackServiceType); + var buildCallbackServices = scope.ComponentRegistry.ServiceRegistrationsFor(_callbackServiceType); foreach (var srv in buildCallbackServices) { @@ -30,7 +30,7 @@ internal static void RunBuildCallbacks(ILifetimeScope scope) continue; } - var request = new ResolveRequest(CallbackServiceType, srv, Enumerable.Empty()); + var request = new ResolveRequest(_callbackServiceType, srv, Enumerable.Empty()); var component = (BuildCallbackService)scope.ResolveComponent(request); srv.Registration.Metadata[BuildCallbacksExecutedKey] = true; diff --git a/src/Autofac/Builder/DeferredCallback.cs b/src/Autofac/Builder/DeferredCallback.cs index ac6045a3a..4febda75b 100644 --- a/src/Autofac/Builder/DeferredCallback.cs +++ b/src/Autofac/Builder/DeferredCallback.cs @@ -59,5 +59,8 @@ public Action Callback /// A that uniquely identifies the callback action /// in a set of callbacks. /// - public Guid Id { get; } + public Guid Id + { + get; + } } diff --git a/src/Autofac/Builder/IConcreteActivatorData.cs b/src/Autofac/Builder/IConcreteActivatorData.cs index 9c5aeb3fb..0c71a3662 100644 --- a/src/Autofac/Builder/IConcreteActivatorData.cs +++ b/src/Autofac/Builder/IConcreteActivatorData.cs @@ -13,5 +13,8 @@ public interface IConcreteActivatorData /// /// Gets the instance activator based on the provided data. /// - IInstanceActivator Activator { get; } + IInstanceActivator Activator + { + get; + } } diff --git a/src/Autofac/Builder/IRegistrationBuilder.cs b/src/Autofac/Builder/IRegistrationBuilder.cs index f76e252d0..cdcd0cbca 100644 --- a/src/Autofac/Builder/IRegistrationBuilder.cs +++ b/src/Autofac/Builder/IRegistrationBuilder.cs @@ -19,25 +19,37 @@ public interface IRegistrationBuilder [EditorBrowsable(EditorBrowsableState.Never)] - RegistrationData RegistrationData { get; } + RegistrationData RegistrationData + { + get; + } /// /// Gets the activator data. /// [EditorBrowsable(EditorBrowsableState.Never)] - TActivatorData ActivatorData { get; } + TActivatorData ActivatorData + { + get; + } /// /// Gets the registration style. /// [EditorBrowsable(EditorBrowsableState.Never)] - TRegistrationStyle RegistrationStyle { get; } + TRegistrationStyle RegistrationStyle + { + get; + } /// /// Gets the resolve pipeline for this registration. /// [EditorBrowsable(EditorBrowsableState.Never)] - IResolvePipelineBuilder ResolvePipeline { get; } + IResolvePipelineBuilder ResolvePipeline + { + get; + } /// /// Configure the component so that instances are never disposed by the container. diff --git a/src/Autofac/Builder/ReflectionActivatorData.cs b/src/Autofac/Builder/ReflectionActivatorData.cs index c82a67a3c..01b30d127 100644 --- a/src/Autofac/Builder/ReflectionActivatorData.cs +++ b/src/Autofac/Builder/ReflectionActivatorData.cs @@ -11,8 +11,8 @@ namespace Autofac.Builder; /// public class ReflectionActivatorData { - private static readonly IConstructorFinder DefaultConstructorFinder = new DefaultConstructorFinder(); - private static readonly IConstructorSelector DefaultConstructorSelector = new MostParametersConstructorSelector(); + private static readonly IConstructorFinder _defaultConstructorFinder = new DefaultConstructorFinder(); + private static readonly IConstructorSelector _defaultConstructorSelector = new MostParametersConstructorSelector(); private Type _implementer = default!; private IConstructorFinder _constructorFinder; @@ -26,8 +26,8 @@ public ReflectionActivatorData(Type implementer) { ImplementationType = implementer; - _constructorFinder = DefaultConstructorFinder; - _constructorSelector = DefaultConstructorSelector; + _constructorFinder = _defaultConstructorFinder; + _constructorSelector = _defaultConstructorSelector; } /// diff --git a/src/Autofac/Builder/RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs b/src/Autofac/Builder/RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs index 6cd15735e..2b243ffc6 100644 --- a/src/Autofac/Builder/RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs +++ b/src/Autofac/Builder/RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs @@ -54,25 +54,37 @@ public RegistrationBuilder(Service defaultService, TActivatorData activatorData, /// Gets the activator data. /// [EditorBrowsable(EditorBrowsableState.Never)] - public TActivatorData ActivatorData { get; } + public TActivatorData ActivatorData + { + get; + } /// /// Gets the registration style. /// [EditorBrowsable(EditorBrowsableState.Never)] - public TRegistrationStyle RegistrationStyle { get; } + public TRegistrationStyle RegistrationStyle + { + get; + } /// /// Gets the registration data. /// [EditorBrowsable(EditorBrowsableState.Never)] - public RegistrationData RegistrationData { get; } + public RegistrationData RegistrationData + { + get; + } /// /// Gets the resolve pipeline builder, that can be used to add middleware to the pipeline. /// [EditorBrowsable(EditorBrowsableState.Never)] - public IResolvePipelineBuilder ResolvePipeline { get; } + public IResolvePipelineBuilder ResolvePipeline + { + get; + } /// /// Configure the component so that instances are never disposed by the container. @@ -272,8 +284,8 @@ public IRegistrationBuilder As As(params Type[] services) { // Issue #919: Use arrays and iteration rather than LINQ to reduce memory allocation. - Service[] argArray = new Service[services.Length]; - for (int i = 0; i < services.Length; i++) + var argArray = new Service[services.Length]; + for (var i = 0; i < services.Length; i++) { var service = services[i]; if (service.FullName is not null) diff --git a/src/Autofac/Builder/RegistrationData.cs b/src/Autofac/Builder/RegistrationData.cs index a732ee0c5..2b4362de8 100644 --- a/src/Autofac/Builder/RegistrationData.cs +++ b/src/Autofac/Builder/RegistrationData.cs @@ -82,12 +82,18 @@ public IComponentLifetime Lifetime /// /// Gets the extended properties assigned to the component. /// - public IDictionary Metadata { get; } + public IDictionary Metadata + { + get; + } /// /// Gets or sets the options for the registration. /// - public RegistrationOptions Options { get; set; } + public RegistrationOptions Options + { + get; set; + } /// /// Gets or sets the callback used to register this component. @@ -96,7 +102,10 @@ public IComponentLifetime Lifetime /// A that contains the delegate /// used to register this component with an . /// - public DeferredCallback? DeferredCallback { get; set; } + public DeferredCallback? DeferredCallback + { + get; set; + } /// /// Add multiple services for the registration, overriding the default. diff --git a/src/Autofac/Builder/RegistrationOrderExtensions.cs b/src/Autofac/Builder/RegistrationOrderExtensions.cs index 6d84daed5..14734ea84 100644 --- a/src/Autofac/Builder/RegistrationOrderExtensions.cs +++ b/src/Autofac/Builder/RegistrationOrderExtensions.cs @@ -17,7 +17,7 @@ internal static class RegistrationOrderExtensions /// The original registration order value. internal static long GetRegistrationOrder(this IComponentRegistration registration) { - return registration.Metadata.TryGetValue(MetadataKeys.RegistrationOrderMetadataKey, out object? value) ? (long)value! : long.MaxValue; + return registration.Metadata.TryGetValue(MetadataKeys.RegistrationOrderMetadataKey, out var value) ? (long)value! : long.MaxValue; } /// diff --git a/src/Autofac/Builder/SimpleActivatorData.cs b/src/Autofac/Builder/SimpleActivatorData.cs index b18609449..336a02126 100644 --- a/src/Autofac/Builder/SimpleActivatorData.cs +++ b/src/Autofac/Builder/SimpleActivatorData.cs @@ -22,5 +22,8 @@ public SimpleActivatorData(IInstanceActivator activator) /// /// Gets the activator. /// - public IInstanceActivator Activator { get; } + public IInstanceActivator Activator + { + get; + } } diff --git a/src/Autofac/Builder/SingleRegistrationStyle.cs b/src/Autofac/Builder/SingleRegistrationStyle.cs index 1463e1196..97838495e 100644 --- a/src/Autofac/Builder/SingleRegistrationStyle.cs +++ b/src/Autofac/Builder/SingleRegistrationStyle.cs @@ -25,10 +25,16 @@ public class SingleRegistrationStyle /// By default, new registrations override existing registrations as defaults. /// If set to true, new registrations will not change existing defaults. /// - public bool PreserveDefaults { get; set; } + public bool PreserveDefaults + { + get; set; + } /// /// Gets or sets the component upon which this registration is based. /// - public IComponentRegistration? Target { get; set; } + public IComponentRegistration? Target + { + get; set; + } } diff --git a/src/Autofac/ContainerBuilder.cs b/src/Autofac/ContainerBuilder.cs index f50340a06..2de6894bd 100644 --- a/src/Autofac/ContainerBuilder.cs +++ b/src/Autofac/ContainerBuilder.cs @@ -90,7 +90,10 @@ internal ContainerBuilder(IDictionary properties, IComponentReg /// /// Gets the builder to use for building the underlying . /// - public IComponentRegistryBuilder ComponentRegistryBuilder { get; } + public IComponentRegistryBuilder ComponentRegistryBuilder + { + get; + } /// /// Gets the set of properties used during component registration. @@ -99,7 +102,10 @@ internal ContainerBuilder(IDictionary properties, IComponentReg /// An that can be used to share /// context across registrations. /// - public IDictionary Properties { get; } + public IDictionary Properties + { + get; + } /// /// Register a callback that will be invoked when the container is configured. diff --git a/src/Autofac/Core/ActivatedEventArgs.cs b/src/Autofac/Core/ActivatedEventArgs.cs index 65b365ff3..6cd0cee7f 100644 --- a/src/Autofac/Core/ActivatedEventArgs.cs +++ b/src/Autofac/Core/ActivatedEventArgs.cs @@ -34,25 +34,40 @@ public ActivatedEventArgs( /// /// Gets the service being resolved. /// - public Service Service { get; } + public Service Service + { + get; + } /// /// Gets the context in which the activation occurred. /// - public IComponentContext Context { get; } + public IComponentContext Context + { + get; + } /// /// Gets the component providing the instance. /// - public IComponentRegistration Component { get; } + public IComponentRegistration Component + { + get; + } /// /// Gets the parameters provided when resolved. /// - public IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } /// /// Gets the instance that will be used to satisfy the request. /// - public T Instance { get; } + public T Instance + { + get; + } } diff --git a/src/Autofac/Core/ActivatingEventArgs.cs b/src/Autofac/Core/ActivatingEventArgs.cs index cab6cf411..62b1c2cfe 100644 --- a/src/Autofac/Core/ActivatingEventArgs.cs +++ b/src/Autofac/Core/ActivatingEventArgs.cs @@ -33,17 +33,26 @@ public ActivatingEventArgs(IComponentContext context, Service service, IComponen /// /// Gets the service being resolved. /// - public Service Service { get; } + public Service Service + { + get; + } /// /// Gets the context in which the activation occurred. /// - public IComponentContext Context { get; } + public IComponentContext Context + { + get; + } /// /// Gets the component providing the instance. /// - public IComponentRegistration Component { get; } + public IComponentRegistration Component + { + get; + } /// /// Gets or sets the instance that will be used to satisfy the request. @@ -72,7 +81,10 @@ public T Instance /// /// Gets the parameters supplied to the activator. /// - public IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } /// /// The instance can be replaced if needed, e.g. by an interface proxy. diff --git a/src/Autofac/Core/Activators/DefaultPropertySelector.cs b/src/Autofac/Core/Activators/DefaultPropertySelector.cs index 21fb65837..48ada16ca 100644 --- a/src/Autofac/Core/Activators/DefaultPropertySelector.cs +++ b/src/Autofac/Core/Activators/DefaultPropertySelector.cs @@ -25,7 +25,10 @@ public class DefaultPropertySelector : IPropertySelector /// Gets a value indicating whether the value should be set if the value is already /// set (ie non-null). /// - public bool PreserveSetValues { get; } + public bool PreserveSetValues + { + get; + } /// /// Gets an instance of DefaultPropertySelector that will cause values to be overwritten. diff --git a/src/Autofac/Core/Activators/InstanceActivator.cs b/src/Autofac/Core/Activators/InstanceActivator.cs index 62f9b7d93..25257db78 100644 --- a/src/Autofac/Core/Activators/InstanceActivator.cs +++ b/src/Autofac/Core/Activators/InstanceActivator.cs @@ -23,7 +23,10 @@ protected InstanceActivator(Type limitType) /// /// Gets the most specific type that the component instances are known to be castable to. /// - public Type LimitType { get; } + public Type LimitType + { + get; + } /// /// Gets a string representation of the activator. diff --git a/src/Autofac/Core/Activators/ProvidedInstance/ProvidedInstanceActivator.cs b/src/Autofac/Core/Activators/ProvidedInstance/ProvidedInstanceActivator.cs index 22796689c..d02460444 100644 --- a/src/Autofac/Core/Activators/ProvidedInstance/ProvidedInstanceActivator.cs +++ b/src/Autofac/Core/Activators/ProvidedInstance/ProvidedInstanceActivator.cs @@ -31,7 +31,10 @@ public ProvidedInstanceActivator(object instance) /// Necessary because otherwise instances that are never resolved will never be /// disposed. /// - public bool DisposeInstance { get; set; } + public bool DisposeInstance + { + get; set; + } /// public void ConfigurePipeline(IComponentRegistryServices componentRegistryServices, IResolvePipelineBuilder pipelineBuilder) diff --git a/src/Autofac/Core/Activators/Reflection/AutowiringPropertyInjector.cs b/src/Autofac/Core/Activators/Reflection/AutowiringPropertyInjector.cs index 1ec6e3ff9..7efbb462b 100644 --- a/src/Autofac/Core/Activators/Reflection/AutowiringPropertyInjector.cs +++ b/src/Autofac/Core/Activators/Reflection/AutowiringPropertyInjector.cs @@ -17,7 +17,7 @@ internal static class AutowiringPropertyInjector /// internal const string InstanceTypeNamedParameter = "Autofac.AutowiringPropertyInjector.InstanceType"; - private static readonly MethodInfo CallPropertySetterOpenGenericMethod = + private static readonly MethodInfo _callPropertySetterOpenGenericMethod = typeof(AutowiringPropertyInjector).GetDeclaredMethod(nameof(CallPropertySetter)); /// @@ -164,13 +164,13 @@ private static IEnumerable GetInjectableProperties(Type instanceTy // Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; } var propertySetterAsAction = setMethod.CreateDelegate(typeof(Action<,>).MakeGenericType(typeInput, parameterType)); - var callPropertySetterClosedGenericMethod = CallPropertySetterOpenGenericMethod.MakeGenericMethod(typeInput, parameterType); + var callPropertySetterClosedGenericMethod = _callPropertySetterOpenGenericMethod.MakeGenericMethod(typeInput, parameterType); var callPropertySetterDelegate = callPropertySetterClosedGenericMethod.CreateDelegate>(propertySetterAsAction); return callPropertySetterDelegate; } private static void CallPropertySetter( - Action setter, object target, object value) => - setter((TDeclaringType)target, (TValue)value); + Action setter, object target, object value) + => setter((TDeclaringType)target, (TValue)value); } diff --git a/src/Autofac/Core/Activators/Reflection/BoundConstructor.cs b/src/Autofac/Core/Activators/Reflection/BoundConstructor.cs index 139c296de..4bd4f17ff 100644 --- a/src/Autofac/Core/Activators/Reflection/BoundConstructor.cs +++ b/src/Autofac/Core/Activators/Reflection/BoundConstructor.cs @@ -51,7 +51,10 @@ internal BoundConstructor(ConstructorBinder binder, ParameterInfo firstNonBindab /// /// Gets the binder that created this binding. /// - public ConstructorBinder Binder { get; } + public ConstructorBinder Binder + { + get; + } /// /// Gets a value indicating whether the constructor has the SetsRequiredMembers attribute, @@ -73,7 +76,10 @@ internal BoundConstructor(ConstructorBinder binder, ParameterInfo firstNonBindab /// /// Gets a value indicating whether the binding is valid. /// - public bool CanInstantiate { get; } + public bool CanInstantiate + { + get; + } /// /// Gets a description of the constructor parameter binding. @@ -99,8 +105,8 @@ public static BoundConstructor ForBindSuccess(ConstructorBinder binder, FuncThe binder that generated this binding. /// The first parameter that prevented binding. /// A with details about the unsuccessful bind. - public static BoundConstructor ForBindFailure(ConstructorBinder binder, ParameterInfo firstNonBindableParameter) => - new(binder, firstNonBindableParameter); + public static BoundConstructor ForBindFailure(ConstructorBinder binder, ParameterInfo firstNonBindableParameter) + => new(binder, firstNonBindableParameter); /// /// Invoke the constructor with the parameter bindings. diff --git a/src/Autofac/Core/Activators/Reflection/ConstructorBinder.cs b/src/Autofac/Core/Activators/Reflection/ConstructorBinder.cs index bb1fbab0c..0c0cdc0ab 100644 --- a/src/Autofac/Core/Activators/Reflection/ConstructorBinder.cs +++ b/src/Autofac/Core/Activators/Reflection/ConstructorBinder.cs @@ -13,7 +13,7 @@ namespace Autofac.Core.Activators.Reflection; /// public class ConstructorBinder { - private static readonly Func> FactoryBuilder = GetConstructorInvoker; + private static readonly Func> _factoryBuilder = GetConstructorInvoker; private readonly ParameterInfo[] _constructorArgs; private readonly Func? _factory; @@ -39,20 +39,26 @@ public ConstructorBinder(ConstructorInfo constructorInfo) var factoryCache = ReflectionCacheSet.Shared.Internal.ConstructorBinderFactory; // Build the invoker. - _factory = factoryCache.GetOrAdd(constructorInfo, FactoryBuilder); + _factory = factoryCache.GetOrAdd(constructorInfo, _factoryBuilder); } } /// /// Gets the constructor this binder is responsible for binding. /// - public ConstructorInfo Constructor { get; } + public ConstructorInfo Constructor + { + get; + } /// /// Gets a value indicating whether the constructor has the SetsRequiredMembers attribute, /// indicating we can skip population of required properties. /// - public bool SetsRequiredMembers { get; } + public bool SetsRequiredMembers + { + get; + } /// /// Gets the set of parameters to bind against. @@ -141,7 +147,7 @@ public BoundConstructor Bind(IEnumerable availableParameters, ICompon var parametersExpression = Expression.Parameter(typeof(object[]), "args"); var argumentsExpression = new Expression[paramsInfo.Length]; - for (int paramIndex = 0; paramIndex < paramsInfo.Length; paramIndex++) + for (var paramIndex = 0; paramIndex < paramsInfo.Length; paramIndex++) { var indexExpression = Expression.Constant(paramIndex); var parameterType = paramsInfo[paramIndex].ParameterType; diff --git a/src/Autofac/Core/Activators/Reflection/InjectableProperty.cs b/src/Autofac/Core/Activators/Reflection/InjectableProperty.cs index 8da02e237..804198e34 100644 --- a/src/Autofac/Core/Activators/Reflection/InjectableProperty.cs +++ b/src/Autofac/Core/Activators/Reflection/InjectableProperty.cs @@ -33,12 +33,18 @@ public InjectableProperty(PropertyInfo prop) /// /// Gets the underlying property. /// - public PropertyInfo Property { get; } + public PropertyInfo Property + { + get; + } /// /// Gets a value indicating whether this field is marked as required. /// - public bool IsRequired { get; } + public bool IsRequired + { + get; + } /// /// Try and supply a value for this property using the given parameter. diff --git a/src/Autofac/Core/Activators/Reflection/InjectablePropertyState.cs b/src/Autofac/Core/Activators/Reflection/InjectablePropertyState.cs index d5d55b860..3675bcb18 100644 --- a/src/Autofac/Core/Activators/Reflection/InjectablePropertyState.cs +++ b/src/Autofac/Core/Activators/Reflection/InjectablePropertyState.cs @@ -21,10 +21,16 @@ public InjectablePropertyState(InjectableProperty property) /// /// Gets the property. /// - public InjectableProperty Property { get; } + public InjectableProperty Property + { + get; + } /// /// Gets or sets a value indicating whether this property has already been set. /// - public bool Set { get; set; } + public bool Set + { + get; set; + } } diff --git a/src/Autofac/Core/Activators/Reflection/NoConstructorsFoundException.cs b/src/Autofac/Core/Activators/Reflection/NoConstructorsFoundException.cs index ea2d23800..2d8120f24 100644 --- a/src/Autofac/Core/Activators/Reflection/NoConstructorsFoundException.cs +++ b/src/Autofac/Core/Activators/Reflection/NoConstructorsFoundException.cs @@ -65,7 +65,10 @@ public NoConstructorsFoundException(Type offendingType, IConstructorFinder const /// An that was used when scanning the /// to find constructors. /// - public IConstructorFinder ConstructorFinder { get; private set; } + public IConstructorFinder ConstructorFinder + { + get; private set; + } /// /// Gets the type without found constructors. @@ -75,7 +78,10 @@ public NoConstructorsFoundException(Type offendingType, IConstructorFinder const /// and was determined to have no available /// constructors. /// - public Type OffendingType { get; private set; } + public Type OffendingType + { + get; private set; + } private static string FormatMessage(Type offendingType, IConstructorFinder constructorFinder) { diff --git a/src/Autofac/Core/Activators/Reflection/ReflectionActivator.cs b/src/Autofac/Core/Activators/Reflection/ReflectionActivator.cs index cf79ed6ce..8cd82789e 100644 --- a/src/Autofac/Core/Activators/Reflection/ReflectionActivator.cs +++ b/src/Autofac/Core/Activators/Reflection/ReflectionActivator.cs @@ -63,12 +63,18 @@ public ReflectionActivator( /// /// Gets the constructor finder. /// - public IConstructorFinder ConstructorFinder { get; } + public IConstructorFinder ConstructorFinder + { + get; + } /// /// Gets the constructor selector. /// - public IConstructorSelector ConstructorSelector { get; } + public IConstructorSelector ConstructorSelector + { + get; + } /// /// Gets a value indicating whether the activation pipeline needs a keyed service parameter for this type. @@ -116,7 +122,7 @@ public void ConfigurePipeline(IComponentRegistryServices componentRegistryServic _defaultFoundPropertySet = new InjectablePropertyState[actualProperties.Count]; - for (int idx = 0; idx < actualProperties.Count; idx++) + for (var idx = 0; idx < actualProperties.Count; idx++) { _defaultFoundPropertySet[idx] = new InjectablePropertyState(new InjectableProperty(actualProperties[idx])); } diff --git a/src/Autofac/Core/ComponentRegisteredEventArgs.cs b/src/Autofac/Core/ComponentRegisteredEventArgs.cs index 73a31c05c..cd243161c 100644 --- a/src/Autofac/Core/ComponentRegisteredEventArgs.cs +++ b/src/Autofac/Core/ComponentRegisteredEventArgs.cs @@ -25,10 +25,16 @@ public ComponentRegisteredEventArgs(IComponentRegistryBuilder registryBuilder, I /// /// Gets the into which the registration was made. /// - public IComponentRegistryBuilder ComponentRegistryBuilder { get; } + public IComponentRegistryBuilder ComponentRegistryBuilder + { + get; + } /// /// Gets the component registration. /// - public IComponentRegistration ComponentRegistration { get; } + public IComponentRegistration ComponentRegistration + { + get; + } } diff --git a/src/Autofac/Core/ConstantParameter.cs b/src/Autofac/Core/ConstantParameter.cs index 8cdff9119..cb31a504c 100644 --- a/src/Autofac/Core/ConstantParameter.cs +++ b/src/Autofac/Core/ConstantParameter.cs @@ -30,7 +30,10 @@ protected ConstantParameter(object? value, Predicate predicate) /// /// Gets the value of the parameter. /// - public object? Value { get; } + public object? Value + { + get; + } /// /// Returns true if the parameter is able to provide a value to a particular site. diff --git a/src/Autofac/Core/Container.cs b/src/Autofac/Core/Container.cs index 5d8536aab..b8497224b 100644 --- a/src/Autofac/Core/Container.cs +++ b/src/Autofac/Core/Container.cs @@ -34,8 +34,15 @@ internal Container(IComponentRegistry componentRegistry) /// public event EventHandler ChildLifetimeScopeBeginning { - add { _rootLifetimeScope.ChildLifetimeScopeBeginning += value; } - remove { _rootLifetimeScope.ChildLifetimeScopeBeginning -= value; } + add + { + _rootLifetimeScope.ChildLifetimeScopeBeginning += value; + } + + remove + { + _rootLifetimeScope.ChildLifetimeScopeBeginning -= value; + } } /// @@ -43,8 +50,15 @@ public event EventHandler ChildLifetimeScopeBeg /// public event EventHandler CurrentScopeEnding { - add { _rootLifetimeScope.CurrentScopeEnding += value; } - remove { _rootLifetimeScope.CurrentScopeEnding -= value; } + add + { + _rootLifetimeScope.CurrentScopeEnding += value; + } + + remove + { + _rootLifetimeScope.CurrentScopeEnding -= value; + } } /// @@ -52,8 +66,15 @@ public event EventHandler CurrentScopeEnding /// public event EventHandler ResolveOperationBeginning { - add { _rootLifetimeScope.ResolveOperationBeginning += value; } - remove { _rootLifetimeScope.ResolveOperationBeginning -= value; } + add + { + _rootLifetimeScope.ResolveOperationBeginning += value; + } + + remove + { + _rootLifetimeScope.ResolveOperationBeginning -= value; + } } /// @@ -72,7 +93,10 @@ public event EventHandler ResolveOperationBe /// /// Gets associated services with the components that provide them. /// - public IComponentRegistry ComponentRegistry { get; } + public IComponentRegistry ComponentRegistry + { + get; + } /// public DiagnosticListener DiagnosticSource => _rootLifetimeScope.DiagnosticSource; diff --git a/src/Autofac/Core/IActivatedEventArgs.cs b/src/Autofac/Core/IActivatedEventArgs.cs index 5dd0f310d..12618c19b 100644 --- a/src/Autofac/Core/IActivatedEventArgs.cs +++ b/src/Autofac/Core/IActivatedEventArgs.cs @@ -13,25 +13,40 @@ public interface IActivatedEventArgs /// /// Gets the service being resolved. /// - Service Service { get; } + Service Service + { + get; + } /// /// Gets the context in which the activation occurred. /// - IComponentContext Context { get; } + IComponentContext Context + { + get; + } /// /// Gets the component providing the instance. /// - IComponentRegistration Component { get; } + IComponentRegistration Component + { + get; + } /// /// Gets the parameters provided when resolved. /// - IEnumerable Parameters { get; } + IEnumerable Parameters + { + get; + } /// /// Gets the instance that will be used to satisfy the request. /// - T Instance { get; } + T Instance + { + get; + } } diff --git a/src/Autofac/Core/IActivatingEventArgs.cs b/src/Autofac/Core/IActivatingEventArgs.cs index cfbcd8f7a..6009afdfd 100644 --- a/src/Autofac/Core/IActivatingEventArgs.cs +++ b/src/Autofac/Core/IActivatingEventArgs.cs @@ -14,27 +14,42 @@ public interface IActivatingEventArgs /// /// Gets the service being resolved. /// - Service Service { get; } + Service Service + { + get; + } /// /// Gets the context in which the activation occurred. /// - IComponentContext Context { get; } + IComponentContext Context + { + get; + } /// /// Gets the component providing the instance. /// - IComponentRegistration Component { get; } + IComponentRegistration Component + { + get; + } /// /// Gets the instance that will be used to satisfy the request. /// - T Instance { get; } + T Instance + { + get; + } /// /// Gets the parameters supplied to the activator. /// - IEnumerable Parameters { get; } + IEnumerable Parameters + { + get; + } /// /// The instance can be replaced if needed, e.g. by an interface proxy. diff --git a/src/Autofac/Core/IComponentRegistration.cs b/src/Autofac/Core/IComponentRegistration.cs index ee70778d8..c74d7433c 100644 --- a/src/Autofac/Core/IComponentRegistration.cs +++ b/src/Autofac/Core/IComponentRegistration.cs @@ -26,52 +26,82 @@ public interface IComponentRegistration : IDisposable, IAsyncDisposable /// Gets a unique identifier for this component (shared in all sub-contexts.) /// This value also appears in Services. /// - Guid Id { get; } + Guid Id + { + get; + } /// /// Gets the activator used to create instances. /// - IInstanceActivator Activator { get; } + IInstanceActivator Activator + { + get; + } /// /// Gets the lifetime associated with the component. /// - IComponentLifetime Lifetime { get; } + IComponentLifetime Lifetime + { + get; + } /// /// Gets a value indicating whether the component instances are shared or not. /// - InstanceSharing Sharing { get; } + InstanceSharing Sharing + { + get; + } /// /// Gets a value indicating whether the instances of the component should be disposed by the container. /// - InstanceOwnership Ownership { get; } + InstanceOwnership Ownership + { + get; + } /// /// Gets the services provided by the component. /// - IEnumerable Services { get; } + IEnumerable Services + { + get; + } /// /// Gets additional data associated with the component. /// - IDictionary Metadata { get; } + IDictionary Metadata + { + get; + } /// /// Gets the component registration upon which this registration is based. /// - IComponentRegistration Target { get; } + IComponentRegistration Target + { + get; + } /// /// Gets the resolve pipeline for the component. /// - IResolvePipeline ResolvePipeline { get; } + IResolvePipeline ResolvePipeline + { + get; + } /// /// Gets the options for the registration. /// - RegistrationOptions Options { get; } + RegistrationOptions Options + { + get; + } /// /// Builds the resolve pipeline. diff --git a/src/Autofac/Core/IComponentRegistry.cs b/src/Autofac/Core/IComponentRegistry.cs index b28bde2c6..a2c0e78a1 100644 --- a/src/Autofac/Core/IComponentRegistry.cs +++ b/src/Autofac/Core/IComponentRegistry.cs @@ -18,22 +18,34 @@ public interface IComponentRegistry : IDisposable, IAsyncDisposable /// An that can be used to share /// context across registrations. /// - IDictionary Properties { get; } + IDictionary Properties + { + get; + } /// /// Gets the set of registered components. /// - IEnumerable Registrations { get; } + IEnumerable Registrations + { + get; + } /// /// Gets the registration sources that are used by the registry. /// - IEnumerable Sources { get; } + IEnumerable Sources + { + get; + } /// /// Gets the set of service middleware sources that are used by the registry. /// - IEnumerable ServiceMiddlewareSources { get; } + IEnumerable ServiceMiddlewareSources + { + get; + } /// /// Gets a value indicating whether the registry contains its own components. @@ -42,7 +54,10 @@ public interface IComponentRegistry : IDisposable, IAsyncDisposable /// /// This property is used when walking up the scope tree looking for /// registrations for a new customized scope. - bool HasLocalComponents { get; } + bool HasLocalComponents + { + get; + } /// /// Attempts to find a default registration for the specified service. diff --git a/src/Autofac/Core/IInstanceActivator.cs b/src/Autofac/Core/IInstanceActivator.cs index a487d0292..1e4855c9c 100644 --- a/src/Autofac/Core/IInstanceActivator.cs +++ b/src/Autofac/Core/IInstanceActivator.cs @@ -13,7 +13,10 @@ public interface IInstanceActivator : IDisposable /// /// Gets the most specific type that the component instances are known to be castable to. /// - Type LimitType { get; } + Type LimitType + { + get; + } /// /// Allows an implementation to add middleware to a registration's resolve pipeline. diff --git a/src/Autofac/Core/IReflectionCache.cs b/src/Autofac/Core/IReflectionCache.cs index 7277e2cca..abbfcae0a 100644 --- a/src/Autofac/Core/IReflectionCache.cs +++ b/src/Autofac/Core/IReflectionCache.cs @@ -30,7 +30,10 @@ public interface IReflectionCache /// /// Gets a value indicating when the cache is used. /// - ReflectionCacheUsage Usage { get; } + ReflectionCacheUsage Usage + { + get; + } /// /// Clear the cache. diff --git a/src/Autofac/Core/IRegistrationSource.cs b/src/Autofac/Core/IRegistrationSource.cs index c1d6a72d0..6e66a69a7 100644 --- a/src/Autofac/Core/IRegistrationSource.cs +++ b/src/Autofac/Core/IRegistrationSource.cs @@ -13,7 +13,10 @@ public interface IRegistrationSource /// Gets a value indicating whether the registrations provided by this source are 1:1 adapters on top /// of other components (e.g., Meta, Func, or Owned). /// - bool IsAdapterForIndividualComponents { get; } + bool IsAdapterForIndividualComponents + { + get; + } /// /// Retrieve registrations for an unregistered service, to be used diff --git a/src/Autofac/Core/IServiceWithType.cs b/src/Autofac/Core/IServiceWithType.cs index 27da58ecc..496e60f74 100644 --- a/src/Autofac/Core/IServiceWithType.cs +++ b/src/Autofac/Core/IServiceWithType.cs @@ -12,7 +12,10 @@ public interface IServiceWithType /// Gets the type of the service. /// /// The type of the service. - Type ServiceType { get; } + Type ServiceType + { + get; + } /// /// Return a new service of the same kind, but carrying diff --git a/src/Autofac/Core/ISharingLifetimeScope.cs b/src/Autofac/Core/ISharingLifetimeScope.cs index 6414fc575..5eec53e04 100644 --- a/src/Autofac/Core/ISharingLifetimeScope.cs +++ b/src/Autofac/Core/ISharingLifetimeScope.cs @@ -11,12 +11,18 @@ public interface ISharingLifetimeScope : ILifetimeScope /// /// Gets the root of the sharing hierarchy. /// - ISharingLifetimeScope RootLifetimeScope { get; } + ISharingLifetimeScope RootLifetimeScope + { + get; + } /// /// Gets the parent of this node of the hierarchy, or null. /// - ISharingLifetimeScope? ParentLifetimeScope { get; } + ISharingLifetimeScope? ParentLifetimeScope + { + get; + } /// /// Try to retrieve a shared instance based on a GUID key. diff --git a/src/Autofac/Core/ImplicitRegistrationSource.cs b/src/Autofac/Core/ImplicitRegistrationSource.cs index 66bda63dd..7830872ae 100644 --- a/src/Autofac/Core/ImplicitRegistrationSource.cs +++ b/src/Autofac/Core/ImplicitRegistrationSource.cs @@ -13,7 +13,7 @@ namespace Autofac.Core; /// public abstract class ImplicitRegistrationSource : IRegistrationSource { - private static readonly MethodInfo CreateRegistrationMethod = typeof(ImplicitRegistrationSource).GetDeclaredMethod(nameof(CreateRegistration)); + private static readonly MethodInfo _createRegistrationMethod = typeof(ImplicitRegistrationSource).GetDeclaredMethod(nameof(CreateRegistration)); private readonly Type _type; @@ -69,7 +69,7 @@ public IEnumerable RegistrationsFor(Service service, Fun var registrationCreator = methodCache.GetOrAdd(valueType, t => { - return CreateRegistrationMethod.MakeGenericMethod(t).CreateDelegate(this); + return _createRegistrationMethod.MakeGenericMethod(t).CreateDelegate(this); }); return registrationAccessor(valueService) diff --git a/src/Autofac/Core/InternalReflectionCaches.cs b/src/Autofac/Core/InternalReflectionCaches.cs index 0988cafa2..b8deae22b 100644 --- a/src/Autofac/Core/InternalReflectionCaches.cs +++ b/src/Autofac/Core/InternalReflectionCaches.cs @@ -43,70 +43,112 @@ public InternalReflectionCaches(ReflectionCacheSet set) /// /// Gets the cache used by . /// - public ReflectionCacheAssemblyDictionary> AssemblyScanAllowedTypes { get; } + public ReflectionCacheAssemblyDictionary> AssemblyScanAllowedTypes + { + get; + } /// /// Gets the cache used by . /// - public ReflectionCacheDictionary IsGenericEnumerableInterface { get; } + public ReflectionCacheDictionary IsGenericEnumerableInterface + { + get; + } /// /// Gets the cache used by . /// - public ReflectionCacheDictionary IsGenericListOrCollectionInterfaceType { get; } + public ReflectionCacheDictionary IsGenericListOrCollectionInterfaceType + { + get; + } /// /// Gets the cache used by . /// - public ReflectionCacheTupleDictionary IsGenericTypeDefinedBy { get; } + public ReflectionCacheTupleDictionary IsGenericTypeDefinedBy + { + get; + } /// /// Gets the cache used by . /// - public ReflectionCacheTupleDictionary IsGenericTypeContainingType { get; } + public ReflectionCacheTupleDictionary IsGenericTypeContainingType + { + get; + } /// /// Gets the cache used by . /// - public ReflectionCacheDictionary> ConstructorBinderFactory { get; } + public ReflectionCacheDictionary> ConstructorBinderFactory + { + get; + } /// /// Gets a cache used by . /// - public ReflectionCacheDictionary> AutowiringPropertySetters { get; } + public ReflectionCacheDictionary> AutowiringPropertySetters + { + get; + } /// /// Gets a cache used by . /// - public ReflectionCacheDictionary> AutowiringInjectableProperties { get; } + public ReflectionCacheDictionary> AutowiringInjectableProperties + { + get; + } /// /// Gets a cache used by . /// - public ReflectionCacheDictionary DefaultPublicConstructors { get; } + public ReflectionCacheDictionary DefaultPublicConstructors + { + get; + } /// /// Gets a cache of memoized . /// - public ReflectionCacheDictionary GenericTypeDefinitionByType { get; } + public ReflectionCacheDictionary GenericTypeDefinitionByType + { + get; + } /// /// Gets a cache used by . /// - public ReflectionCacheDictionary HasRequiredMemberAttribute { get; } + public ReflectionCacheDictionary HasRequiredMemberAttribute + { + get; + } /// /// Gets a cache used to track usage on parameters. /// - public ReflectionCacheParameterDictionary ServiceKeyParameterAttributes { get; } + public ReflectionCacheParameterDictionary ServiceKeyParameterAttributes + { + get; + } /// /// Gets a cache used to track usage on properties. /// - public ReflectionCacheDictionary ServiceKeyPropertyAttributes { get; } + public ReflectionCacheDictionary ServiceKeyPropertyAttributes + { + get; + } /// /// Gets a cache used to determine if a type uses . /// - public ReflectionCacheDictionary ServiceKeyUsageByType { get; } + public ReflectionCacheDictionary ServiceKeyUsageByType + { + get; + } } diff --git a/src/Autofac/Core/KeyedService.cs b/src/Autofac/Core/KeyedService.cs index cf34ba634..54d1ed84f 100644 --- a/src/Autofac/Core/KeyedService.cs +++ b/src/Autofac/Core/KeyedService.cs @@ -35,13 +35,19 @@ public KeyedService(object serviceKey, Type serviceType) /// Gets the key of the service. /// /// The key of the service. - public object ServiceKey { get; } + public object ServiceKey + { + get; + } /// /// Gets the type of the service. /// /// The type of the service. - public Type ServiceType { get; } + public Type ServiceType + { + get; + } /// /// Gets a human-readable description of the service. diff --git a/src/Autofac/Core/Lifetime/LifetimeScope.cs b/src/Autofac/Core/Lifetime/LifetimeScope.cs index 665109597..cc11ef3fe 100644 --- a/src/Autofac/Core/Lifetime/LifetimeScope.cs +++ b/src/Autofac/Core/Lifetime/LifetimeScope.cs @@ -102,7 +102,10 @@ protected LifetimeScope(IComponentRegistry componentRegistry, LifetimeScope pare /// /// Gets the root of the sharing hierarchy. /// - public ISharingLifetimeScope RootLifetimeScope { get; } + public ISharingLifetimeScope RootLifetimeScope + { + get; + } /// /// Gets the disposer associated with this container. Instances can be associated @@ -115,12 +118,18 @@ protected LifetimeScope(IComponentRegistry componentRegistry, LifetimeScope pare /// /// The tag applied to this scope and the contexts generated when /// it resolves component dependencies. - public object Tag { get; } + public object Tag + { + get; + } /// /// Gets the services associated with the components that provide them. /// - public IComponentRegistry ComponentRegistry { get; } + public IComponentRegistry ComponentRegistry + { + get; + } /// /// Gets the id of the lifetime scope self-registration. @@ -131,7 +140,10 @@ protected LifetimeScope(IComponentRegistry componentRegistry, LifetimeScope pare /// Gets the to which /// trace events should be written. /// - internal DiagnosticListener DiagnosticSource { get; } + internal DiagnosticListener DiagnosticSource + { + get; + } /// /// Begin a new anonymous sub-scope. Instances created via the sub-scope diff --git a/src/Autofac/Core/Lifetime/LifetimeScopeBeginningEventArgs.cs b/src/Autofac/Core/Lifetime/LifetimeScopeBeginningEventArgs.cs index 6d58a3b03..fd0d6f282 100644 --- a/src/Autofac/Core/Lifetime/LifetimeScopeBeginningEventArgs.cs +++ b/src/Autofac/Core/Lifetime/LifetimeScopeBeginningEventArgs.cs @@ -20,5 +20,8 @@ public LifetimeScopeBeginningEventArgs(ILifetimeScope lifetimeScope) /// /// Gets the lifetime scope that is beginning. /// - public ILifetimeScope LifetimeScope { get; } + public ILifetimeScope LifetimeScope + { + get; + } } diff --git a/src/Autofac/Core/Lifetime/LifetimeScopeEndingEventArgs.cs b/src/Autofac/Core/Lifetime/LifetimeScopeEndingEventArgs.cs index a4ac26332..16faf914d 100644 --- a/src/Autofac/Core/Lifetime/LifetimeScopeEndingEventArgs.cs +++ b/src/Autofac/Core/Lifetime/LifetimeScopeEndingEventArgs.cs @@ -20,5 +20,8 @@ public LifetimeScopeEndingEventArgs(ILifetimeScope lifetimeScope) /// /// Gets the lifetime scope that is ending. /// - public ILifetimeScope LifetimeScope { get; } + public ILifetimeScope LifetimeScope + { + get; + } } diff --git a/src/Autofac/Core/Lifetime/MatchingScopeLifetime.cs b/src/Autofac/Core/Lifetime/MatchingScopeLifetime.cs index 791681dbf..e6e092bd1 100644 --- a/src/Autofac/Core/Lifetime/MatchingScopeLifetime.cs +++ b/src/Autofac/Core/Lifetime/MatchingScopeLifetime.cs @@ -49,7 +49,7 @@ public ISharingLifetimeScope FindScope(ISharingLifetimeScope mostNestedVisibleSc throw new ArgumentNullException(nameof(mostNestedVisibleScope)); } - ISharingLifetimeScope? next = mostNestedVisibleScope; + var next = mostNestedVisibleScope; while (next is not null) { if (_tagsToMatch.Contains(next.Tag)) diff --git a/src/Autofac/Core/NamedPropertyParameter.cs b/src/Autofac/Core/NamedPropertyParameter.cs index 96d9b24b1..fcdcd8b95 100644 --- a/src/Autofac/Core/NamedPropertyParameter.cs +++ b/src/Autofac/Core/NamedPropertyParameter.cs @@ -20,7 +20,7 @@ public class NamedPropertyParameter : ConstantParameter public NamedPropertyParameter(string name, object? value) : base(value, pi => { - return pi.TryGetDeclaringProperty(out PropertyInfo? prop) && + return pi.TryGetDeclaringProperty(out var prop) && prop.Name == name; }) { @@ -30,5 +30,8 @@ public NamedPropertyParameter(string name, object? value) /// /// Gets the name of the property. /// - public string Name { get; private set; } + public string Name + { + get; private set; + } } diff --git a/src/Autofac/Core/PreparingEventArgs.cs b/src/Autofac/Core/PreparingEventArgs.cs index 5d772ec76..243397d31 100644 --- a/src/Autofac/Core/PreparingEventArgs.cs +++ b/src/Autofac/Core/PreparingEventArgs.cs @@ -29,17 +29,26 @@ public PreparingEventArgs(IComponentContext context, Service service, IComponent /// /// Gets the service being resolved. /// - public Service Service { get; } + public Service Service + { + get; + } /// /// Gets the context in which the activation is occurring. /// - public IComponentContext Context { get; } + public IComponentContext Context + { + get; + } /// /// Gets the component providing the instance being activated. /// - public IComponentRegistration Component { get; } + public IComponentRegistration Component + { + get; + } /// /// Gets or sets the parameters supplied to the activator. diff --git a/src/Autofac/Core/ReflectionCacheSet.cs b/src/Autofac/Core/ReflectionCacheSet.cs index 8c1c8d9bb..8f031deb7 100644 --- a/src/Autofac/Core/ReflectionCacheSet.cs +++ b/src/Autofac/Core/ReflectionCacheSet.cs @@ -12,7 +12,7 @@ namespace Autofac.Core; /// public sealed class ReflectionCacheSet { - private static readonly object CacheAllocationLock = new(); + private static readonly object _cacheAllocationLock = new(); private static WeakReference? _sharedSet; @@ -42,7 +42,7 @@ public static ReflectionCacheSet Shared { if (!TryGetSharedCache(out var sharedCache)) { - lock (CacheAllocationLock) + lock (_cacheAllocationLock) { // Check the cache again inside the lock, another thread may have updated it. if (!TryGetSharedCache(out sharedCache)) @@ -60,7 +60,10 @@ public static ReflectionCacheSet Shared /// /// Gets the instance of the known Internal caches defined in . /// - internal InternalReflectionCaches Internal { get; } + internal InternalReflectionCaches Internal + { + get; + } /// /// Get a typed cache store with a given name, that is held in this instance. An instance will be created if it does not already exist. diff --git a/src/Autofac/Core/Registration/ComponentPipelineBuildingArgs.cs b/src/Autofac/Core/Registration/ComponentPipelineBuildingArgs.cs index 95a7a80c5..4491cfbc6 100644 --- a/src/Autofac/Core/Registration/ComponentPipelineBuildingArgs.cs +++ b/src/Autofac/Core/Registration/ComponentPipelineBuildingArgs.cs @@ -24,10 +24,16 @@ public ComponentPipelineBuildingArgs(IComponentRegistration registration, IResol /// /// Gets the component registration whose pipeline is being built. /// - public IComponentRegistration Registration { get; } + public IComponentRegistration Registration + { + get; + } /// /// Gets the pipeline builder for the registration. Add middleware to the builder to add to the component behaviour. /// - public IResolvePipelineBuilder PipelineBuilder { get; } + public IResolvePipelineBuilder PipelineBuilder + { + get; + } } diff --git a/src/Autofac/Core/Registration/ComponentRegistration.cs b/src/Autofac/Core/Registration/ComponentRegistration.cs index dfa668a4e..336b427b1 100644 --- a/src/Autofac/Core/Registration/ComponentRegistration.cs +++ b/src/Autofac/Core/Registration/ComponentRegistration.cs @@ -179,42 +179,66 @@ public event EventHandler? PipelineBuilding /// Gets a unique identifier for this component (shared in all sub-contexts.) /// This value also appears in Services. /// - public Guid Id { get; } + public Guid Id + { + get; + } /// /// Gets the activator for the registration. /// - public IInstanceActivator Activator { get; } + public IInstanceActivator Activator + { + get; + } /// /// Gets the lifetime associated with the component. /// - public IComponentLifetime Lifetime { get; } + public IComponentLifetime Lifetime + { + get; + } /// /// Gets information about whether the component instances are shared or not. /// - public InstanceSharing Sharing { get; } + public InstanceSharing Sharing + { + get; + } /// /// Gets information about whether the instances of the component should be disposed by the container. /// - public InstanceOwnership Ownership { get; } + public InstanceOwnership Ownership + { + get; + } /// /// Gets the services provided by the component. /// - public IEnumerable Services { get; } + public IEnumerable Services + { + get; + } /// /// Gets additional data associated with the component. /// - public IDictionary Metadata { get; } + public IDictionary Metadata + { + get; + } /// /// Gets the options for the registration. /// - public RegistrationOptions Options { get; } + public RegistrationOptions Options + { + get; + } /// public IResolvePipeline ResolvePipeline @@ -232,14 +256,11 @@ public void BuildResolvePipeline(IComponentRegistryServices registryServices) return; } - if (_pipelineBuildEvent is not null) - { - _pipelineBuildEvent.Invoke(this, _lateBuildPipeline); + _pipelineBuildEvent?.Invoke(this, _lateBuildPipeline); - // Reset the PipelineBuilding event so we don't accidentally retain - // references we don't need to. - _pipelineBuildEvent = null; - } + // Reset the PipelineBuilding event so we don't accidentally retain + // references we don't need to. + _pipelineBuildEvent = null; ResolvePipeline = BuildResolvePipeline(registryServices, _lateBuildPipeline); } diff --git a/src/Autofac/Core/Registration/ComponentRegistrationLifetimeDecorator.cs b/src/Autofac/Core/Registration/ComponentRegistrationLifetimeDecorator.cs index 5ea54a7ff..5cd3172d3 100644 --- a/src/Autofac/Core/Registration/ComponentRegistrationLifetimeDecorator.cs +++ b/src/Autofac/Core/Registration/ComponentRegistrationLifetimeDecorator.cs @@ -39,7 +39,10 @@ public event EventHandler PipelineBuilding public IInstanceActivator Activator => _inner.Activator; /// - public IComponentLifetime Lifetime { get; } + public IComponentLifetime Lifetime + { + get; + } /// public InstanceSharing Sharing => _inner.Sharing; diff --git a/src/Autofac/Core/Registration/ComponentRegistry.cs b/src/Autofac/Core/Registration/ComponentRegistry.cs index 4370c21fb..0c73d4ca8 100644 --- a/src/Autofac/Core/Registration/ComponentRegistry.cs +++ b/src/Autofac/Core/Registration/ComponentRegistry.cs @@ -38,7 +38,10 @@ internal ComponentRegistry(IRegisteredServicesTracker registeredServicesTracker, /// An that can be used to share /// context across registrations. /// - public IDictionary Properties { get; } + public IDictionary Properties + { + get; + } /// /// Gets the registered components. diff --git a/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs b/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs index dd32841c4..a62385144 100644 --- a/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs +++ b/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs @@ -39,7 +39,7 @@ public event EventHandler Registered { add { - foreach (IComponentRegistration registration in _registeredServicesTracker.Registrations) + foreach (var registration in _registeredServicesTracker.Registrations) { value(this, new ComponentRegisteredEventArgs(this, registration)); } @@ -60,7 +60,7 @@ public event EventHandler RegistrationSourceAd { add { - foreach (IRegistrationSource source in _registeredServicesTracker.Sources) + foreach (var source in _registeredServicesTracker.Sources) { value(this, new RegistrationSourceAddedEventArgs(this, source)); } @@ -81,7 +81,10 @@ public event EventHandler RegistrationSourceAd /// An that can be used to share /// context across registrations. /// - public IDictionary Properties { get; } + public IDictionary Properties + { + get; + } /// /// Create a new with all the component registrations that have been made. diff --git a/src/Autofac/Core/Registration/DefaultRegisteredServicesTracker.cs b/src/Autofac/Core/Registration/DefaultRegisteredServicesTracker.cs index 0a9eb7286..1737dbaf4 100644 --- a/src/Autofac/Core/Registration/DefaultRegisteredServicesTracker.cs +++ b/src/Autofac/Core/Registration/DefaultRegisteredServicesTracker.cs @@ -14,7 +14,7 @@ namespace Autofac.Core.Registration; /// internal class DefaultRegisteredServicesTracker : Disposable, IRegisteredServicesTracker { - private static readonly Func RegInfoFactory = srv => new ServiceRegistrationInfo(srv); + private static readonly Func _regInfoFactory = srv => new ServiceRegistrationInfo(srv); private readonly Func> _registrationAccessor; @@ -528,6 +528,6 @@ private void BeginServiceInfoInitialization(Service service, ServiceRegistration [MethodImpl(MethodImplOptions.AggressiveInlining)] private ServiceRegistrationInfo GetServiceInfo(Service service) { - return _serviceInfo.GetOrAdd(service, RegInfoFactory); + return _serviceInfo.GetOrAdd(service, _regInfoFactory); } } diff --git a/src/Autofac/Core/Registration/ExternalComponentRegistration.cs b/src/Autofac/Core/Registration/ExternalComponentRegistration.cs index 41a9440d3..91ebcc3a9 100644 --- a/src/Autofac/Core/Registration/ExternalComponentRegistration.cs +++ b/src/Autofac/Core/Registration/ExternalComponentRegistration.cs @@ -34,7 +34,10 @@ public NoOpActivator(Type limitType) LimitType = limitType; } - public Type LimitType { get; } + public Type LimitType + { + get; + } public void ConfigurePipeline(IComponentRegistryServices componentRegistryServices, IResolvePipelineBuilder pipelineBuilder) { diff --git a/src/Autofac/Core/Registration/IComponentRegistryBuilder.cs b/src/Autofac/Core/Registration/IComponentRegistryBuilder.cs index dd00462f1..db1f80d77 100644 --- a/src/Autofac/Core/Registration/IComponentRegistryBuilder.cs +++ b/src/Autofac/Core/Registration/IComponentRegistryBuilder.cs @@ -28,7 +28,10 @@ public interface IComponentRegistryBuilder : IDisposable, IAsyncDisposable /// An that can be used to share /// context across registrations. /// - IDictionary Properties { get; } + IDictionary Properties + { + get; + } /// /// Create a new with all the component registrations that have been made. diff --git a/src/Autofac/Core/Registration/IModuleRegistrar.cs b/src/Autofac/Core/Registration/IModuleRegistrar.cs index 1b49fbd3c..06f445896 100644 --- a/src/Autofac/Core/Registration/IModuleRegistrar.cs +++ b/src/Autofac/Core/Registration/IModuleRegistrar.cs @@ -14,7 +14,10 @@ public interface IModuleRegistrar /// Gets the registrar data. /// [EditorBrowsable(EditorBrowsableState.Never)] - public ModuleRegistrarData RegistrarData { get; } + ModuleRegistrarData RegistrarData + { + get; + } /// /// Add a module to the container. diff --git a/src/Autofac/Core/Registration/IRegisteredServicesTracker.cs b/src/Autofac/Core/Registration/IRegisteredServicesTracker.cs index f33c7bc10..5e96dc498 100644 --- a/src/Autofac/Core/Registration/IRegisteredServicesTracker.cs +++ b/src/Autofac/Core/Registration/IRegisteredServicesTracker.cs @@ -23,17 +23,26 @@ internal interface IRegisteredServicesTracker : IDisposable, IAsyncDisposable, I /// /// Gets the registered components. /// - IEnumerable Registrations { get; } + IEnumerable Registrations + { + get; + } /// /// Gets the registration sources that are used by the registry. /// - IEnumerable Sources { get; } + IEnumerable Sources + { + get; + } /// /// Gets the set of registered service middleware sources. /// - IEnumerable ServiceMiddlewareSources { get; } + IEnumerable ServiceMiddlewareSources + { + get; + } /// /// Adds a registration to the list of registered services. diff --git a/src/Autofac/Core/Registration/ModuleRegistrar.cs b/src/Autofac/Core/Registration/ModuleRegistrar.cs index bad53e298..9bd292459 100644 --- a/src/Autofac/Core/Registration/ModuleRegistrar.cs +++ b/src/Autofac/Core/Registration/ModuleRegistrar.cs @@ -38,7 +38,10 @@ public ModuleRegistrar(ContainerBuilder builder) } /// - public ModuleRegistrarData RegistrarData { get; } + public ModuleRegistrarData RegistrarData + { + get; + } /// /// Add a module to the container. diff --git a/src/Autofac/Core/Registration/ModuleRegistrarData.cs b/src/Autofac/Core/Registration/ModuleRegistrarData.cs index 7b8147509..cc009af4d 100644 --- a/src/Autofac/Core/Registration/ModuleRegistrarData.cs +++ b/src/Autofac/Core/Registration/ModuleRegistrarData.cs @@ -22,5 +22,8 @@ public ModuleRegistrarData(DeferredCallback callback) /// /// Gets the callback invoked when the collection of modules attached to this registrar are registered. /// - public DeferredCallback Callback { get; } + public DeferredCallback Callback + { + get; + } } diff --git a/src/Autofac/Core/Registration/ServiceRegistrationInfo.cs b/src/Autofac/Core/Registration/ServiceRegistrationInfo.cs index 1ba12652b..80d58aa30 100644 --- a/src/Autofac/Core/Registration/ServiceRegistrationInfo.cs +++ b/src/Autofac/Core/Registration/ServiceRegistrationInfo.cs @@ -67,7 +67,10 @@ public bool IsInitialized /// /// Gets or sets a value representing the current initialization depth. Will always be zero for initialized service blocks. /// - public int InitializationDepth { get; set; } + public int InitializationDepth + { + get; set; + } /// /// Gets the known implementations. The first implementation is a default one. @@ -169,8 +172,8 @@ public IEnumerable ServiceMiddleware /// PipelineType IResolvePipelineBuilder.Type => PipelineType.Service; - private bool Any => - _defaultImplementations.Count > 0 || + private bool Any + => _defaultImplementations.Count > 0 || _sourceImplementations is not null || _preserveDefaultImplementations is not null; diff --git a/src/Autofac/Core/RegistrationSourceAddedEventArgs.cs b/src/Autofac/Core/RegistrationSourceAddedEventArgs.cs index 92b222199..4e3666bfa 100644 --- a/src/Autofac/Core/RegistrationSourceAddedEventArgs.cs +++ b/src/Autofac/Core/RegistrationSourceAddedEventArgs.cs @@ -24,10 +24,16 @@ public RegistrationSourceAddedEventArgs(IComponentRegistryBuilder componentRegis /// /// Gets the registry to which the source was added. /// - public IRegistrationSource RegistrationSource { get; } + public IRegistrationSource RegistrationSource + { + get; + } /// /// Gets the source that was added. /// - public IComponentRegistryBuilder ComponentRegistry { get; } + public IComponentRegistryBuilder ComponentRegistry + { + get; + } } diff --git a/src/Autofac/Core/Resolving/ActivatorExtensions.cs b/src/Autofac/Core/Resolving/ActivatorExtensions.cs index 166a3fff8..310423fae 100644 --- a/src/Autofac/Core/Resolving/ActivatorExtensions.cs +++ b/src/Autofac/Core/Resolving/ActivatorExtensions.cs @@ -20,8 +20,8 @@ internal static class ActivatorExtensions public static string DisplayName(this IInstanceActivator activator) { var fullName = activator?.LimitType.FullName ?? ""; - return activator is DelegateActivator ? - $"λ:{fullName}" : - fullName; + return activator is DelegateActivator + ? $"λ:{fullName}" + : fullName; } } diff --git a/src/Autofac/Core/Resolving/IDependencyTrackingResolveOperation.cs b/src/Autofac/Core/Resolving/IDependencyTrackingResolveOperation.cs index 33588faee..bc46c7550 100644 --- a/src/Autofac/Core/Resolving/IDependencyTrackingResolveOperation.cs +++ b/src/Autofac/Core/Resolving/IDependencyTrackingResolveOperation.cs @@ -19,7 +19,10 @@ public interface IDependencyTrackingResolveOperation : IResolveOperation /// , /// hence it's internal. /// - SegmentedStack RequestStack { get; } + SegmentedStack RequestStack + { + get; + } /// /// Enter a new dependency chain block where subsequent requests inside the operation are allowed to repeat diff --git a/src/Autofac/Core/Resolving/IResolveOperation.cs b/src/Autofac/Core/Resolving/IResolveOperation.cs index f65ff8459..ab07e1889 100644 --- a/src/Autofac/Core/Resolving/IResolveOperation.cs +++ b/src/Autofac/Core/Resolving/IResolveOperation.cs @@ -25,33 +25,51 @@ public interface IResolveOperation /// /// Gets the active resolve request. /// - ResolveRequestContext? ActiveRequestContext { get; } + ResolveRequestContext? ActiveRequestContext + { + get; + } /// /// Gets the current lifetime scope of the operation; based on the most recently executed request. /// - ISharingLifetimeScope CurrentScope { get; } + ISharingLifetimeScope CurrentScope + { + get; + } /// /// Gets the set of all in-progress requests on the request stack. /// - IEnumerable InProgressRequests { get; } + IEnumerable InProgressRequests + { + get; + } /// /// Gets the for the operation. /// - DiagnosticListener DiagnosticSource { get; } + DiagnosticListener DiagnosticSource + { + get; + } /// /// Gets the current request depth. /// - int RequestDepth { get; } + int RequestDepth + { + get; + } /// /// Gets the that initiated the operation. Other nested requests may have been /// issued as a result of this one. /// - ResolveRequest? InitiatingRequest { get; } + ResolveRequest? InitiatingRequest + { + get; + } /// /// Get or create and share an instance of the requested service in the . diff --git a/src/Autofac/Core/Resolving/Middleware/CoreEventMiddleware.cs b/src/Autofac/Core/Resolving/Middleware/CoreEventMiddleware.cs index 90d23e72d..fdbe6d66c 100644 --- a/src/Autofac/Core/Resolving/Middleware/CoreEventMiddleware.cs +++ b/src/Autofac/Core/Resolving/Middleware/CoreEventMiddleware.cs @@ -26,12 +26,18 @@ internal CoreEventMiddleware(ResolveEventType eventType, PipelinePhase phase, Ac } /// - public PipelinePhase Phase { get; } + public PipelinePhase Phase + { + get; + } /// /// Gets the event type represented by this middleware. /// - public ResolveEventType EventType { get; } + public ResolveEventType EventType + { + get; + } /// public override string ToString() => EventType.ToString(); diff --git a/src/Autofac/Core/Resolving/Middleware/DelegateMiddleware.cs b/src/Autofac/Core/Resolving/Middleware/DelegateMiddleware.cs index 252681e3c..362c5b9c0 100644 --- a/src/Autofac/Core/Resolving/Middleware/DelegateMiddleware.cs +++ b/src/Autofac/Core/Resolving/Middleware/DelegateMiddleware.cs @@ -27,7 +27,10 @@ public DelegateMiddleware(string descriptor, PipelinePhase phase, Action - public PipelinePhase Phase { get; } + public PipelinePhase Phase + { + get; + } /// public void Execute(ResolveRequestContext context, Action next) diff --git a/src/Autofac/Core/Resolving/Pipeline/DefaultResolveRequestContext.cs b/src/Autofac/Core/Resolving/Pipeline/DefaultResolveRequestContext.cs index d0badb5b4..106bddadf 100644 --- a/src/Autofac/Core/Resolving/Pipeline/DefaultResolveRequestContext.cs +++ b/src/Autofac/Core/Resolving/Pipeline/DefaultResolveRequestContext.cs @@ -41,10 +41,16 @@ internal DefaultResolveRequestContext( public override event EventHandler? RequestCompleting; /// - public override IResolveOperation Operation { get; } + public override IResolveOperation Operation + { + get; + } /// - public override ISharingLifetimeScope ActivationScope { get; protected set; } + public override ISharingLifetimeScope ActivationScope + { + get; protected set; + } /// public override IComponentRegistration Registration => _resolveRequest.Registration; @@ -67,38 +73,50 @@ public override object? Instance public override bool NewInstanceActivated => Instance is not null && PhaseReached == PipelinePhase.Activation; /// - public override DiagnosticListener DiagnosticSource { get; } + public override DiagnosticListener DiagnosticSource + { + get; + } /// - public override IEnumerable Parameters { get; protected set; } + public override IEnumerable Parameters + { + get; protected set; + } /// - public override PipelinePhase PhaseReached { get; set; } + public override PipelinePhase PhaseReached + { + get; set; + } /// public override IComponentRegistry ComponentRegistry => ActivationScope.ComponentRegistry; /// - public override DecoratorContext? DecoratorContext { get; set; } + public override DecoratorContext? DecoratorContext + { + get; set; + } /// - public override void ChangeScope(ISharingLifetimeScope newScope) => - ActivationScope = newScope ?? throw new ArgumentNullException(nameof(newScope)); + public override void ChangeScope(ISharingLifetimeScope newScope) + => ActivationScope = newScope ?? throw new ArgumentNullException(nameof(newScope)); /// - public override void ChangeParameters(IEnumerable newParameters) => - Parameters = KeyedServiceParameterInjector.AddKeyedServiceParameter(Service, newParameters ?? throw new ArgumentNullException(nameof(newParameters)), Registration); + public override void ChangeParameters(IEnumerable newParameters) + => Parameters = KeyedServiceParameterInjector.AddKeyedServiceParameter(Service, newParameters ?? throw new ArgumentNullException(nameof(newParameters)), Registration); /// - public override object ResolveComponent(in ResolveRequest request) => - Operation.GetOrCreateInstance(ActivationScope, request); + public override object ResolveComponent(in ResolveRequest request) + => Operation.GetOrCreateInstance(ActivationScope, request); /// /// Complete the request, raising any appropriate events. /// public void CompleteRequest() { - EventHandler? handler = RequestCompleting; + var handler = RequestCompleting; handler?.Invoke(this, new ResolveRequestCompletingEventArgs(this)); } } diff --git a/src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs b/src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs index 710e6d9d9..516ecb0b3 100644 --- a/src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs +++ b/src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs @@ -11,7 +11,10 @@ public interface IResolveMiddleware /// /// Gets the phase of the resolve pipeline at which to execute. /// - PipelinePhase Phase { get; } + PipelinePhase Phase + { + get; + } /// /// Invoked when this middleware is executed as part of an active . The middleware should usually call diff --git a/src/Autofac/Core/Resolving/Pipeline/IResolvePipelineBuilder.cs b/src/Autofac/Core/Resolving/Pipeline/IResolvePipelineBuilder.cs index bc9dabf99..084f64506 100644 --- a/src/Autofac/Core/Resolving/Pipeline/IResolvePipelineBuilder.cs +++ b/src/Autofac/Core/Resolving/Pipeline/IResolvePipelineBuilder.cs @@ -11,12 +11,18 @@ public interface IResolvePipelineBuilder /// /// Gets the set of middleware currently registered. /// - IEnumerable Middleware { get; } + IEnumerable Middleware + { + get; + } /// /// Gets the type of the pipeline this instance will build. /// - PipelineType Type { get; } + PipelineType Type + { + get; + } /// /// Construct a concrete resolve pipeline from this builder. diff --git a/src/Autofac/Core/Resolving/Pipeline/MiddlewareDeclaration.cs b/src/Autofac/Core/Resolving/Pipeline/MiddlewareDeclaration.cs index 40fee9bf8..b49c58ce5 100644 --- a/src/Autofac/Core/Resolving/Pipeline/MiddlewareDeclaration.cs +++ b/src/Autofac/Core/Resolving/Pipeline/MiddlewareDeclaration.cs @@ -21,20 +21,32 @@ public MiddlewareDeclaration(IResolveMiddleware middleware) /// /// Gets or sets the next node in a pipeline set. /// - public MiddlewareDeclaration? Next { get; set; } + public MiddlewareDeclaration? Next + { + get; set; + } /// /// Gets or sets the previous node in a pipeline set. /// - public MiddlewareDeclaration? Previous { get; set; } + public MiddlewareDeclaration? Previous + { + get; set; + } /// /// Gets the middleware for this declaration. /// - public IResolveMiddleware Middleware { get; } + public IResolveMiddleware Middleware + { + get; + } /// /// Gets the declared phase of the middleware. /// - public PipelinePhase Phase { get; } + public PipelinePhase Phase + { + get; + } } diff --git a/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs b/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs index 23b750d1d..8464b87e0 100644 --- a/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs +++ b/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs @@ -32,7 +32,7 @@ internal class ResolvePipelineBuilder : IResolvePipelineBuilder, IEnumerable /// Termination action for the end of pipelines. /// - private static readonly Action TerminateAction = context => { }; + private static readonly Action _terminateAction = context => { }; private MiddlewareDeclaration? _first; private MiddlewareDeclaration? _last; @@ -50,7 +50,10 @@ public ResolvePipelineBuilder(PipelineType pipelineType) public IEnumerable Middleware => this; /// - public PipelineType Type { get; } + public PipelineType Type + { + get; + } /// public IResolvePipelineBuilder Use(IResolveMiddleware stage, MiddlewareInsertionMode insertionMode = MiddlewareInsertionMode.EndOfPhase) @@ -90,9 +93,9 @@ public IResolvePipelineBuilder UseRange(IEnumerable stages, while (currentStage is not null) { - if (insertionMode == MiddlewareInsertionMode.StartOfPhase ? - currentStage.Middleware.Phase >= nextNewStage.Phase : - currentStage.Middleware.Phase > nextNewStage.Phase) + if (insertionMode == MiddlewareInsertionMode.StartOfPhase + ? currentStage.Middleware.Phase >= nextNewStage.Phase + : currentStage.Middleware.Phase > nextNewStage.Phase) { var newDecl = new MiddlewareDeclaration(enumerator.Current); @@ -204,7 +207,7 @@ private static ResolvePipeline BuildPipeline(MiddlewareDeclaration? lastDecl) { // When we build, we go through the set and construct a single call stack, starting from the end. var current = lastDecl; - Action? currentInvoke = TerminateAction; + var currentInvoke = _terminateAction; Action Chain(Action next, IResolveMiddleware stage) { diff --git a/src/Autofac/Core/Resolving/Pipeline/ResolveRequestContext.cs b/src/Autofac/Core/Resolving/Pipeline/ResolveRequestContext.cs index 1bb18cba7..aff37799f 100644 --- a/src/Autofac/Core/Resolving/Pipeline/ResolveRequestContext.cs +++ b/src/Autofac/Core/Resolving/Pipeline/ResolveRequestContext.cs @@ -18,28 +18,43 @@ public abstract class ResolveRequestContext : IComponentContext /// /// Gets a reference to the owning resolve operation (which might encompass multiple nested requests). /// - public abstract IResolveOperation Operation { get; } + public abstract IResolveOperation Operation + { + get; + } /// /// Gets or sets the lifetime scope that will be used for the activation of any components later in the pipeline. /// Avoid resolving instances directly from this scope; they will not be traced as part of the same operation. /// - public abstract ISharingLifetimeScope ActivationScope { get; protected set; } + public abstract ISharingLifetimeScope ActivationScope + { + get; protected set; + } /// /// Gets the component registration that is being resolved in the current request. /// - public abstract IComponentRegistration Registration { get; } + public abstract IComponentRegistration Registration + { + get; + } /// /// Gets the service that is being resolved in the current request. /// - public abstract Service Service { get; } + public abstract Service Service + { + get; + } /// /// Gets the target registration for decorator requests. /// - public abstract IComponentRegistration? DecoratorTarget { get; } + public abstract IComponentRegistration? DecoratorTarget + { + get; + } /// /// Gets or sets the instance that will be returned as the result of the @@ -50,36 +65,57 @@ public abstract class ResolveRequestContext : IComponentContext /// shared instance previously activated. /// [DisallowNull] - public abstract object? Instance { get; set; } + public abstract object? Instance + { + get; set; + } /// /// Gets a value indicating whether the resolved is a new instance of a component has been activated during this request, /// or an existing shared instance that has been retrieved. /// - public abstract bool NewInstanceActivated { get; } + public abstract bool NewInstanceActivated + { + get; + } /// /// Gets the to which trace events should be written. /// - public abstract DiagnosticListener DiagnosticSource { get; } + public abstract DiagnosticListener DiagnosticSource + { + get; + } /// /// Gets or sets the current resolve parameters. These can be changed using the method. /// - public abstract IEnumerable Parameters { get; protected set; } + public abstract IEnumerable Parameters + { + get; protected set; + } /// /// Gets or sets the phase of the pipeline reached by this request. /// - public abstract PipelinePhase PhaseReached { get; set; } + public abstract PipelinePhase PhaseReached + { + get; set; + } /// /// Gets or sets the active decorator context for the request. /// - public abstract DecoratorContext? DecoratorContext { get; set; } + public abstract DecoratorContext? DecoratorContext + { + get; set; + } /// - public abstract IComponentRegistry ComponentRegistry { get; } + public abstract IComponentRegistry ComponentRegistry + { + get; + } /// /// Use this method to change the that is used in this request. Changing this scope will diff --git a/src/Autofac/Core/Resolving/Pipeline/ServicePipelines.cs b/src/Autofac/Core/Resolving/Pipeline/ServicePipelines.cs index e3188fff4..2d169300d 100644 --- a/src/Autofac/Core/Resolving/Pipeline/ServicePipelines.cs +++ b/src/Autofac/Core/Resolving/Pipeline/ServicePipelines.cs @@ -10,23 +10,29 @@ namespace Autofac.Core.Resolving.Pipeline; /// public static class ServicePipelines { + private static readonly IReadOnlyList _defaultMiddleware = + [ + CircularDependencyDetectorMiddleware.Default, + ScopeSelectionMiddleware.Instance, + SharingMiddleware.Instance, + RegistrationPipelineInvokeMiddleware.Instance, + ]; + /// /// Gets the set of default middleware added to each service pipeline. /// - public static IReadOnlyList DefaultMiddleware { get; } = new IResolveMiddleware[] + public static IReadOnlyList DefaultMiddleware { - CircularDependencyDetectorMiddleware.Default, - ScopeSelectionMiddleware.Instance, - SharingMiddleware.Instance, - RegistrationPipelineInvokeMiddleware.Instance, - }; + get + { + return _defaultMiddleware; + } + } /// /// Gets a default pre-built service pipeline that contains only the . /// - public static IResolvePipeline DefaultServicePipeline { get; } = new ResolvePipelineBuilder(PipelineType.Service) - .UseRange(DefaultMiddleware) - .Build(); + public static IResolvePipeline DefaultServicePipeline { get; } = new ResolvePipelineBuilder(PipelineType.Service).UseRange(DefaultMiddleware).Build(); /// /// Checks whether a given resolve middleware is one of the default middleware in . diff --git a/src/Autofac/Core/Resolving/ResolveOperation.cs b/src/Autofac/Core/Resolving/ResolveOperation.cs index 7ed0fc08a..cc475364e 100644 --- a/src/Autofac/Core/Resolving/ResolveOperation.cs +++ b/src/Autofac/Core/Resolving/ResolveOperation.cs @@ -45,12 +45,18 @@ public ResolveOperation( /// /// Gets the active resolve request. /// - public ResolveRequestContext? ActiveRequestContext { get; private set; } + public ResolveRequestContext? ActiveRequestContext + { + get; private set; + } /// /// Gets the current lifetime scope of the operation; based on the most recently executed request. /// - public ISharingLifetimeScope CurrentScope { get; private set; } + public ISharingLifetimeScope CurrentScope + { + get; private set; + } /// public IEnumerable InProgressRequests => RequestStack; @@ -58,12 +64,18 @@ public ResolveOperation( /// /// Gets the for the operation. /// - public DiagnosticListener DiagnosticSource { get; } + public DiagnosticListener DiagnosticSource + { + get; + } /// /// Gets the current request depth. /// - public int RequestDepth { get; private set; } + public int RequestDepth + { + get; private set; + } /// public SegmentedStack RequestStack { get; } = new SegmentedStack(); @@ -72,7 +84,10 @@ public ResolveOperation( /// Gets the that initiated the operation. Other nested requests may have been /// issued as a result of this one. /// - public ResolveRequest? InitiatingRequest { get; private set; } + public ResolveRequest? InitiatingRequest + { + get; private set; + } /// /// Execute the complete resolve operation. @@ -122,7 +137,7 @@ ResolveRequestBeginning is null && RequestDepth++; // Track the last active request and scope in the call stack. - ResolveRequestContext? lastActiveRequest = ActiveRequestContext; + var lastActiveRequest = ActiveRequestContext; var lastScope = CurrentScope; ActiveRequestContext = requestContext; diff --git a/src/Autofac/Core/Resolving/ResolveOperationBeginningEventArgs.cs b/src/Autofac/Core/Resolving/ResolveOperationBeginningEventArgs.cs index 9306920af..b5bd9118b 100644 --- a/src/Autofac/Core/Resolving/ResolveOperationBeginningEventArgs.cs +++ b/src/Autofac/Core/Resolving/ResolveOperationBeginningEventArgs.cs @@ -20,5 +20,8 @@ public ResolveOperationBeginningEventArgs(IResolveOperation resolveOperation) /// /// Gets the resolve operation that is beginning. /// - public IResolveOperation ResolveOperation { get; } + public IResolveOperation ResolveOperation + { + get; + } } diff --git a/src/Autofac/Core/Resolving/ResolveOperationEndingEventArgs.cs b/src/Autofac/Core/Resolving/ResolveOperationEndingEventArgs.cs index 59e4f58d0..d6eeb87dd 100644 --- a/src/Autofac/Core/Resolving/ResolveOperationEndingEventArgs.cs +++ b/src/Autofac/Core/Resolving/ResolveOperationEndingEventArgs.cs @@ -22,10 +22,16 @@ public ResolveOperationEndingEventArgs(IResolveOperation resolveOperation, Excep /// /// Gets the exception causing the operation to end, or null. /// - public Exception? Exception { get; } + public Exception? Exception + { + get; + } /// /// Gets the resolve operation that is ending. /// - public IResolveOperation ResolveOperation { get; } + public IResolveOperation ResolveOperation + { + get; + } } diff --git a/src/Autofac/Core/Resolving/ResolveRequestBeginningEventArgs.cs b/src/Autofac/Core/Resolving/ResolveRequestBeginningEventArgs.cs index cec99434d..c1795ca9e 100644 --- a/src/Autofac/Core/Resolving/ResolveRequestBeginningEventArgs.cs +++ b/src/Autofac/Core/Resolving/ResolveRequestBeginningEventArgs.cs @@ -22,5 +22,8 @@ public ResolveRequestBeginningEventArgs(ResolveRequestContext requestContext) /// /// Gets the resolve request that is beginning. /// - public ResolveRequestContext RequestContext { get; } + public ResolveRequestContext RequestContext + { + get; + } } diff --git a/src/Autofac/Core/Resolving/ResolveRequestCompletingEventArgs.cs b/src/Autofac/Core/Resolving/ResolveRequestCompletingEventArgs.cs index 5994e2849..88d445270 100644 --- a/src/Autofac/Core/Resolving/ResolveRequestCompletingEventArgs.cs +++ b/src/Autofac/Core/Resolving/ResolveRequestCompletingEventArgs.cs @@ -27,5 +27,8 @@ public ResolveRequestCompletingEventArgs(ResolveRequestContext requestContext) /// /// Gets the instance lookup operation that is beginning. /// - public ResolveRequestContext RequestContext { get; } + public ResolveRequestContext RequestContext + { + get; + } } diff --git a/src/Autofac/Core/Resolving/SegmentedStack.cs b/src/Autofac/Core/Resolving/SegmentedStack.cs index 433a2e660..0b1bb923c 100644 --- a/src/Autofac/Core/Resolving/SegmentedStack.cs +++ b/src/Autofac/Core/Resolving/SegmentedStack.cs @@ -41,7 +41,7 @@ public void Push(T item) { // No null check for item here; internally called method only, known to never be null, and is a very hot path. var next = _next; - T[] arr = _array; + var arr = _array; // Array bounds checking cast. if ((uint)next < (uint)arr.Length) @@ -61,7 +61,7 @@ public void Push(T item) /// The item that has just been popped. public T Pop() { - int next = _next - 1; + var next = _next - 1; var array = _array; // Array bounds checking cast. diff --git a/src/Autofac/Core/ScopeIsolatedService.cs b/src/Autofac/Core/ScopeIsolatedService.cs index 7b0dc87d4..ad5e2a8d3 100644 --- a/src/Autofac/Core/ScopeIsolatedService.cs +++ b/src/Autofac/Core/ScopeIsolatedService.cs @@ -22,7 +22,10 @@ public ScopeIsolatedService(Service service) /// /// Gets the actual service that has been isolated. /// - public Service Service { get; } + public Service Service + { + get; + } /// public override string Description => Service.Description; diff --git a/src/Autofac/Core/Service.cs b/src/Autofac/Core/Service.cs index d9b0ee31e..54bd1602a 100644 --- a/src/Autofac/Core/Service.cs +++ b/src/Autofac/Core/Service.cs @@ -12,7 +12,10 @@ public abstract class Service /// Gets a human-readable description of the service. /// /// The description. - public abstract string Description { get; } + public abstract string Description + { + get; + } /// /// Implements the operator ==. diff --git a/src/Autofac/Core/ServiceKeyAttributeCache.cs b/src/Autofac/Core/ServiceKeyAttributeCache.cs index 202b24a7a..fd4f175f1 100644 --- a/src/Autofac/Core/ServiceKeyAttributeCache.cs +++ b/src/Autofac/Core/ServiceKeyAttributeCache.cs @@ -38,7 +38,7 @@ public static bool ParameterHasServiceKey(ParameterInfo parameter) return true; } - return p.TryGetDeclaringProperty(out PropertyInfo? property) && PropertyHasServiceKey(property); + return p.TryGetDeclaringProperty(out var property) && PropertyHasServiceKey(property); }); } diff --git a/src/Autofac/Core/ServiceRegistration.cs b/src/Autofac/Core/ServiceRegistration.cs index fcdf84125..245fdd175 100644 --- a/src/Autofac/Core/ServiceRegistration.cs +++ b/src/Autofac/Core/ServiceRegistration.cs @@ -25,12 +25,18 @@ public ServiceRegistration(IResolvePipeline servicePipeline, IComponentRegistrat /// /// Gets the pipeline to invoke that will resolve the associated . /// - public IResolvePipeline Pipeline { get; } + public IResolvePipeline Pipeline + { + get; + } /// /// Gets the registration that will be resolved when a resolve request runs. /// - public IComponentRegistration Registration { get; } + public IComponentRegistration Registration + { + get; + } /// /// Gets additional data associated with the component. diff --git a/src/Autofac/Core/TypedService.cs b/src/Autofac/Core/TypedService.cs index a835b2c68..4a090d129 100644 --- a/src/Autofac/Core/TypedService.cs +++ b/src/Autofac/Core/TypedService.cs @@ -21,7 +21,10 @@ public TypedService(Type serviceType) /// Gets the type of the service. /// /// The type of the service. - public Type ServiceType { get; } + public Type ServiceType + { + get; + } /// /// Gets a human-readable description of the service. diff --git a/src/Autofac/Diagnostics/AutofacMetrics.cs b/src/Autofac/Diagnostics/AutofacMetrics.cs index 7583d2319..778d34a78 100644 --- a/src/Autofac/Diagnostics/AutofacMetrics.cs +++ b/src/Autofac/Diagnostics/AutofacMetrics.cs @@ -75,72 +75,114 @@ static AutofacMetrics() /// /// Gets a value indicating whether diagnostics metrics are enabled. /// - public static bool MetricsEnabled { get; } + public static bool MetricsEnabled + { + get; + } /// /// Gets the underlying diagnostics meter. /// - public static Meter? DiagnosticsMeter { get; } + public static Meter? DiagnosticsMeter + { + get; + } /// /// Gets the histogram tracking lock contention duration. /// - public static Histogram? LockContentionDuration { get; } + public static Histogram? LockContentionDuration + { + get; + } /// /// Gets the counter tracking the number of lock contention events. /// - public static Counter? LockContentionCount { get; } + public static Counter? LockContentionCount + { + get; + } /// /// Gets the counter accumulating total lock wait time. /// - public static Counter? LockContentionTotalTime { get; } + public static Counter? LockContentionTotalTime + { + get; + } /// /// Gets the histogram tracking implicit collection build durations. /// - public static Histogram? CollectionBuildDuration { get; } + public static Histogram? CollectionBuildDuration + { + get; + } /// /// Gets the counter measuring how many collections were materialized. /// - public static Counter? CollectionBuildCount { get; } + public static Counter? CollectionBuildCount + { + get; + } /// /// Gets the counter measuring how many items were added across all collections. /// - public static Counter? CollectionItemCount { get; } + public static Counter? CollectionItemCount + { + get; + } /// /// Gets the histogram tracking property injection durations. /// - public static Histogram? PropertyInjectionDuration { get; } + public static Histogram? PropertyInjectionDuration + { + get; + } /// /// Gets the counter measuring how many instances had property injection. /// - public static Counter? PropertyInjectionCount { get; } + public static Counter? PropertyInjectionCount + { + get; + } /// /// Gets the counter tracking the number of property assignments performed. /// - public static Counter? PropertyInjectionAssignments { get; } + public static Counter? PropertyInjectionAssignments + { + get; + } /// /// Gets the histogram tracking reflection activator durations. /// - public static Histogram? ReflectionActivationDuration { get; } + public static Histogram? ReflectionActivationDuration + { + get; + } /// /// Gets the histogram tracking middleware execution duration. /// - public static Histogram? MiddlewareExecutionDuration { get; } + public static Histogram? MiddlewareExecutionDuration + { + get; + } /// /// Gets the counter tracking how many middleware executions occurred. /// - public static Counter? MiddlewareExecutionCount { get; } + public static Counter? MiddlewareExecutionCount + { + get; + } /// /// Records a collection build event. diff --git a/src/Autofac/Diagnostics/DefaultDiagnosticTracer.cs b/src/Autofac/Diagnostics/DefaultDiagnosticTracer.cs index 2f3e9f7bb..87c39e57c 100644 --- a/src/Autofac/Diagnostics/DefaultDiagnosticTracer.cs +++ b/src/Autofac/Diagnostics/DefaultDiagnosticTracer.cs @@ -26,7 +26,7 @@ public class DefaultDiagnosticTracer : OperationDiagnosticTracerBase { private const string RequestExceptionTraced = "__RequestException"; - private static readonly string[] NewLineSplit = new[] { Environment.NewLine }; + private static readonly string[] _newLineSplit = new[] { Environment.NewLine }; private readonly ConcurrentDictionary _operationBuilders = new(); @@ -273,7 +273,7 @@ public void AppendException(string message, Exception ex) AppendIndent(); _builder.AppendLine(message); - var exceptionBody = ex.ToString().Split(NewLineSplit, StringSplitOptions.None); + var exceptionBody = ex.ToString().Split(_newLineSplit, StringSplitOptions.None); Indent(); diff --git a/src/Autofac/Diagnostics/MiddlewareDiagnosticData.cs b/src/Autofac/Diagnostics/MiddlewareDiagnosticData.cs index 84a343b59..ecbb55640 100644 --- a/src/Autofac/Diagnostics/MiddlewareDiagnosticData.cs +++ b/src/Autofac/Diagnostics/MiddlewareDiagnosticData.cs @@ -24,10 +24,16 @@ public MiddlewareDiagnosticData(ResolveRequestContext requestContext, IResolveMi /// /// Gets the context for the resolve request that is running. /// - public ResolveRequestContext RequestContext { get; private set; } + public ResolveRequestContext RequestContext + { + get; private set; + } /// /// Gets the middleware that is running. /// - public IResolveMiddleware Middleware { get; private set; } + public IResolveMiddleware Middleware + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/OperationDiagnosticTracerBase.cs b/src/Autofac/Diagnostics/OperationDiagnosticTracerBase.cs index b69b58668..91233402d 100644 --- a/src/Autofac/Diagnostics/OperationDiagnosticTracerBase.cs +++ b/src/Autofac/Diagnostics/OperationDiagnosticTracerBase.cs @@ -60,7 +60,10 @@ protected OperationDiagnosticTracerBase(IEnumerable subscriptions) /// An with the number of trace IDs associated /// with in-progress operations being traced by this tracer. /// - public abstract int OperationsInProgress { get; } + public abstract int OperationsInProgress + { + get; + } /// public override void Enable(string diagnosticName) diff --git a/src/Autofac/Diagnostics/OperationFailureDiagnosticData.cs b/src/Autofac/Diagnostics/OperationFailureDiagnosticData.cs index 2ce738be6..c7b21fdbc 100644 --- a/src/Autofac/Diagnostics/OperationFailureDiagnosticData.cs +++ b/src/Autofac/Diagnostics/OperationFailureDiagnosticData.cs @@ -24,10 +24,16 @@ public OperationFailureDiagnosticData(IResolveOperation operation, Exception ope /// /// Gets the resolve operation that failed. /// - public IResolveOperation Operation { get; private set; } + public IResolveOperation Operation + { + get; private set; + } /// /// Gets the exception that caused the operation failure. /// - public Exception OperationException { get; private set; } + public Exception OperationException + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/OperationStartDiagnosticData.cs b/src/Autofac/Diagnostics/OperationStartDiagnosticData.cs index 397e9f5d4..471a6213e 100644 --- a/src/Autofac/Diagnostics/OperationStartDiagnosticData.cs +++ b/src/Autofac/Diagnostics/OperationStartDiagnosticData.cs @@ -24,10 +24,16 @@ public OperationStartDiagnosticData(IResolveOperation operation, in ResolveReque /// /// Gets the pipeline resolve operation that is about to run. /// - public IResolveOperation Operation { get; private set; } + public IResolveOperation Operation + { + get; private set; + } /// /// Gets the request that is responsible for starting this operation. /// - public ResolveRequest InitiatingRequest { get; private set; } + public ResolveRequest InitiatingRequest + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/OperationSuccessDiagnosticData.cs b/src/Autofac/Diagnostics/OperationSuccessDiagnosticData.cs index 4dbb8370b..0d9a9185e 100644 --- a/src/Autofac/Diagnostics/OperationSuccessDiagnosticData.cs +++ b/src/Autofac/Diagnostics/OperationSuccessDiagnosticData.cs @@ -24,10 +24,16 @@ public OperationSuccessDiagnosticData(IResolveOperation operation, object resolv /// /// Gets the resolve operation that succeeded. /// - public IResolveOperation Operation { get; private set; } + public IResolveOperation Operation + { + get; private set; + } /// /// Gets the resolved instance providing the requested service. /// - public object ResolvedInstance { get; private set; } + public object ResolvedInstance + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/OperationTraceCompletedArgs.cs b/src/Autofac/Diagnostics/OperationTraceCompletedArgs.cs index 741e56c2b..6c0ccaf77 100644 --- a/src/Autofac/Diagnostics/OperationTraceCompletedArgs.cs +++ b/src/Autofac/Diagnostics/OperationTraceCompletedArgs.cs @@ -29,15 +29,24 @@ public OperationTraceCompletedArgs(IResolveOperation operation, bool operationSu /// /// Gets the operation for which a trace is available. /// - public IResolveOperation Operation { get; } + public IResolveOperation Operation + { + get; + } /// /// Gets a value indicating whether the operation this trace represents succeeded (if true), or failed with an exception (if false). /// - public bool OperationSucceeded { get; } + public bool OperationSucceeded + { + get; + } /// /// Gets the content of the trace. /// - public TContent TraceContent { get; } + public TContent TraceContent + { + get; + } } diff --git a/src/Autofac/Diagnostics/RequestDiagnosticData.cs b/src/Autofac/Diagnostics/RequestDiagnosticData.cs index fd9628673..0c3f2e92b 100644 --- a/src/Autofac/Diagnostics/RequestDiagnosticData.cs +++ b/src/Autofac/Diagnostics/RequestDiagnosticData.cs @@ -25,10 +25,16 @@ public RequestDiagnosticData(IResolveOperation operation, ResolveRequestContext /// /// Gets the pipeline resolve operation that this request is running within. /// - public IResolveOperation Operation { get; private set; } + public IResolveOperation Operation + { + get; private set; + } /// /// Gets the context for the resolve request that is running. /// - public ResolveRequestContext RequestContext { get; private set; } + public ResolveRequestContext RequestContext + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/RequestFailureDiagnosticData.cs b/src/Autofac/Diagnostics/RequestFailureDiagnosticData.cs index 277c93f15..7e00cc175 100644 --- a/src/Autofac/Diagnostics/RequestFailureDiagnosticData.cs +++ b/src/Autofac/Diagnostics/RequestFailureDiagnosticData.cs @@ -27,15 +27,24 @@ public RequestFailureDiagnosticData(IResolveOperation operation, ResolveRequestC /// /// Gets the pipeline resolve operation that this request is running within. /// - public IResolveOperation Operation { get; private set; } + public IResolveOperation Operation + { + get; private set; + } /// /// Gets the context for the resolve request that failed. /// - public ResolveRequestContext RequestContext { get; private set; } + public ResolveRequestContext RequestContext + { + get; private set; + } /// /// Gets the exception that caused the failure. /// - public Exception RequestException { get; private set; } + public Exception RequestException + { + get; private set; + } } diff --git a/src/Autofac/Diagnostics/ValueStopwatch.cs b/src/Autofac/Diagnostics/ValueStopwatch.cs index 9d1331e6e..8cbda8a55 100644 --- a/src/Autofac/Diagnostics/ValueStopwatch.cs +++ b/src/Autofac/Diagnostics/ValueStopwatch.cs @@ -15,7 +15,7 @@ namespace Autofac.Diagnostics; internal struct ValueStopwatch { #if !NET7_0_OR_GREATER - private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; + private static readonly double _timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; #endif private readonly long _startTimestamp; @@ -46,7 +46,7 @@ public static TimeSpan GetElapsedTime(long startingTimestamp, long endingTimesta { #if !NET7_0_OR_GREATER var timestampDelta = endingTimestamp - startingTimestamp; - var ticks = (long)(TimestampToTicks * timestampDelta); + var ticks = (long)(_timestampToTicks * timestampDelta); return new TimeSpan(ticks); #else return Stopwatch.GetElapsedTime(startingTimestamp, endingTimestamp); diff --git a/src/Autofac/Features/AttributeFilters/KeyFilterAttribute.cs b/src/Autofac/Features/AttributeFilters/KeyFilterAttribute.cs index 693a8ffa5..2f682dcf0 100644 --- a/src/Autofac/Features/AttributeFilters/KeyFilterAttribute.cs +++ b/src/Autofac/Features/AttributeFilters/KeyFilterAttribute.cs @@ -91,7 +91,10 @@ public KeyFilterAttribute(object key) /// The corresponding to a registered service key on a component. /// Resolved components must be keyed with this value to satisfy the filter. /// - public object Key { get; } + public object Key + { + get; + } /// /// Resolves a constructor parameter based on keyed service requirements. diff --git a/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs b/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs index 6f93ec42a..b59a41fa5 100644 --- a/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs +++ b/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs @@ -75,11 +75,11 @@ namespace Autofac.Features.AttributeFilters; [SuppressMessage("Microsoft.Design", "CA1018:MarkAttributesWithAttributeUsage", Justification = "Allowing the inherited AttributeUsageAttribute to be used avoids accidental override or conflict at this level.")] public sealed class MetadataFilterAttribute : ParameterFilterAttribute { - private static readonly MethodInfo FilterOneMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(FilterOne)); + private static readonly MethodInfo _filterOneMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(FilterOne)); - private static readonly MethodInfo FilterAllMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(FilterAll)); + private static readonly MethodInfo _filterAllMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(FilterAll)); - private static readonly MethodInfo CanResolveMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(CanResolve)); + private static readonly MethodInfo _canResolveMethod = typeof(MetadataFilterAttribute).GetDeclaredMethod(nameof(CanResolve)); /// /// Initializes a new instance of the class. @@ -100,7 +100,10 @@ public MetadataFilterAttribute(string key, object value) /// key on a component. Resolved components must have this metadata key to /// satisfy the filter. /// - public string Key { get; } + public string Key + { + get; + } /// /// Gets the value the dependency is expected to have to satisfy the parameter. @@ -111,7 +114,10 @@ public MetadataFilterAttribute(string key, object value) /// with /// this value to satisfy the filter. /// - public object Value { get; private set; } + public object Value + { + get; private set; + } /// /// Resolves a constructor parameter based on metadata requirements. @@ -144,8 +150,8 @@ public MetadataFilterAttribute(string key, object value) var hasMany = elementType != parameter.ParameterType; return hasMany - ? FilterAllMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value }) - : FilterOneMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value }); + ? _filterAllMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value }) + : _filterOneMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value }); } /// @@ -173,7 +179,7 @@ public override bool CanResolveParameter(ParameterInfo parameter, IComponentCont var elementType = GetElementType(parameter.ParameterType); // CanResolveMethod always returns a value. - return (bool)CanResolveMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value })!; + return (bool)_canResolveMethod.MakeGenericMethod(elementType).Invoke(null, new[] { context, Key, Value })!; } private static Type GetElementType(Type type) diff --git a/src/Autofac/Features/Decorators/DecoratorContext.cs b/src/Autofac/Features/Decorators/DecoratorContext.cs index ef4bd68b4..029928f29 100644 --- a/src/Autofac/Features/Decorators/DecoratorContext.cs +++ b/src/Autofac/Features/Decorators/DecoratorContext.cs @@ -29,19 +29,34 @@ private DecoratorContext( } /// - public Type ImplementationType { get; private set; } + public Type ImplementationType + { + get; private set; + } /// - public Type ServiceType { get; private set; } + public Type ServiceType + { + get; private set; + } /// - public IReadOnlyList AppliedDecoratorTypes { get; private set; } + public IReadOnlyList AppliedDecoratorTypes + { + get; private set; + } /// - public IReadOnlyList AppliedDecorators { get; private set; } + public IReadOnlyList AppliedDecorators + { + get; private set; + } /// - public object CurrentInstance { get; private set; } + public object CurrentInstance + { + get; private set; + } /// public IComponentRegistry ComponentRegistry => _componentContext.ComponentRegistry; diff --git a/src/Autofac/Features/Decorators/DecoratorService.cs b/src/Autofac/Features/Decorators/DecoratorService.cs index 8d97205af..e01e226d6 100644 --- a/src/Autofac/Features/Decorators/DecoratorService.cs +++ b/src/Autofac/Features/Decorators/DecoratorService.cs @@ -25,12 +25,18 @@ public DecoratorService(Type serviceType, Func? conditi } /// - public Type ServiceType { get; } + public Type ServiceType + { + get; + } /// /// Gets the condition that must be met for the decorator to be applied. /// - public Func Condition { get; } + public Func Condition + { + get; + } /// public override string Description => $"Decorator ({ServiceType.FullName})"; diff --git a/src/Autofac/Features/Decorators/IDecoratorContext.cs b/src/Autofac/Features/Decorators/IDecoratorContext.cs index bffd31db5..b9f649b3f 100644 --- a/src/Autofac/Features/Decorators/IDecoratorContext.cs +++ b/src/Autofac/Features/Decorators/IDecoratorContext.cs @@ -11,27 +11,42 @@ public interface IDecoratorContext : IComponentContext /// /// Gets the implementation type of the service that is being decorated. /// - Type ImplementationType { get; } + Type ImplementationType + { + get; + } /// /// Gets the service type of the service that is being decorated. /// - Type ServiceType { get; } + Type ServiceType + { + get; + } /// /// Gets the implementation types of the decorators that have been applied. /// - IReadOnlyList AppliedDecoratorTypes { get; } + IReadOnlyList AppliedDecoratorTypes + { + get; + } /// /// Gets the decorator instances that have been applied. /// - IReadOnlyList AppliedDecorators { get; } + IReadOnlyList AppliedDecorators + { + get; + } /// /// Gets the current instance in the decorator chain. This will be initialized /// to the service being decorated and will then become the decorated instance /// as each decorator is applied. /// - object CurrentInstance { get; } + object CurrentInstance + { + get; + } } diff --git a/src/Autofac/Features/GeneratedFactories/FactoryGenerator.cs b/src/Autofac/Features/GeneratedFactories/FactoryGenerator.cs index e47446ea3..0927dbd1f 100644 --- a/src/Autofac/Features/GeneratedFactories/FactoryGenerator.cs +++ b/src/Autofac/Features/GeneratedFactories/FactoryGenerator.cs @@ -17,7 +17,7 @@ public class FactoryGenerator { // The explicit '!' default is ok because the code is never executed, it's just used by // the expression tree. - private static readonly ConstructorInfo RequestConstructor + private static readonly ConstructorInfo _requestConstructor = ReflectionExtensions.GetConstructor(() => new ResolveRequest(default!, default!, default!, default)); private readonly Func, Delegate> _generator; @@ -77,7 +77,7 @@ public FactoryGenerator(Type delegateType, Service service, ServiceRegistration { // new ResolveRequest(service, productRegistration, [new Parameter(name, (object)dps)])*) var newExpression = Expression.New( - RequestConstructor, + _requestConstructor, Expression.Constant(service, typeof(Service)), Expression.Constant(productRegistration, typeof(ServiceRegistration)), Expression.NewArrayInit(typeof(Parameter), resolveParameterArray), diff --git a/src/Autofac/Features/LazyDependencies/LazyRegistrationSource.cs b/src/Autofac/Features/LazyDependencies/LazyRegistrationSource.cs index 0fcca1fba..12b02b3d2 100644 --- a/src/Autofac/Features/LazyDependencies/LazyRegistrationSource.cs +++ b/src/Autofac/Features/LazyDependencies/LazyRegistrationSource.cs @@ -28,7 +28,7 @@ public LazyRegistrationSource() protected override object ResolveInstance(IComponentContext context, in ResolveRequest request) { var capturedContext = context.Resolve(); - ResolveRequest requestCopy = request; + var requestCopy = request; return new Lazy(() => (T)capturedContext.ResolveComponent(requestCopy)); } } diff --git a/src/Autofac/Features/LazyDependencies/LazyWithMetadataRegistrationSource.cs b/src/Autofac/Features/LazyDependencies/LazyWithMetadataRegistrationSource.cs index e61f0fb98..be3ef9e5d 100644 --- a/src/Autofac/Features/LazyDependencies/LazyWithMetadataRegistrationSource.cs +++ b/src/Autofac/Features/LazyDependencies/LazyWithMetadataRegistrationSource.cs @@ -21,7 +21,7 @@ internal class LazyWithMetadataRegistrationSource : IRegistrationSource { private const string ReflectionCacheName = $"{nameof(LazyWithMetadataRegistrationSource)}.Cache"; - private static readonly MethodInfo CreateLazyRegistrationMethod = typeof(LazyWithMetadataRegistrationSource).GetDeclaredMethod(nameof(CreateLazyRegistration)); + private static readonly MethodInfo _createLazyRegistrationMethod = typeof(LazyWithMetadataRegistrationSource).GetDeclaredMethod(nameof(CreateLazyRegistration)); private delegate IComponentRegistration RegistrationCreator(Service providedService, Service valueService, ServiceRegistration registrationResolveInfo); @@ -59,7 +59,7 @@ public IEnumerable RegistrationsFor(Service service, Fun var registrationCreator = methodCache.GetOrAdd((valueType, metaType), types => { - return CreateLazyRegistrationMethod.MakeGenericMethod(types.Item1, types.Item2).CreateDelegate(null); + return _createLazyRegistrationMethod.MakeGenericMethod(types.Item1, types.Item2).CreateDelegate(null); }); return registrationAccessor(valueService) diff --git a/src/Autofac/Features/LightweightAdapters/LightweightAdapterActivatorData.cs b/src/Autofac/Features/LightweightAdapters/LightweightAdapterActivatorData.cs index e70584c61..e2a986ede 100644 --- a/src/Autofac/Features/LightweightAdapters/LightweightAdapterActivatorData.cs +++ b/src/Autofac/Features/LightweightAdapters/LightweightAdapterActivatorData.cs @@ -26,10 +26,16 @@ public LightweightAdapterActivatorData( /// /// Gets the adapter function. /// - public Func, object, object> Adapter { get; } + public Func, object, object> Adapter + { + get; + } /// /// Gets the service to be adapted from. /// - public Service FromService { get; } + public Service FromService + { + get; + } } diff --git a/src/Autofac/Features/Metadata/MetadataViewProvider.cs b/src/Autofac/Features/Metadata/MetadataViewProvider.cs index a59fb0e70..bf599dcec 100644 --- a/src/Autofac/Features/Metadata/MetadataViewProvider.cs +++ b/src/Autofac/Features/Metadata/MetadataViewProvider.cs @@ -10,11 +10,11 @@ namespace Autofac.Features.Metadata; /// -/// Helper methods for creating a metadata access function that retrieves typed metdata from a dictionary. +/// Helper methods for creating a metadata access function that retrieves typed metadata from a dictionary. /// internal static class MetadataViewProvider { - private static readonly MethodInfo GetMetadataValueMethod = typeof(MetadataViewProvider).GetDeclaredMethod(nameof(GetMetadataValue)); + private static readonly MethodInfo _getMetadataValueMethod = typeof(MetadataViewProvider).GetDeclaredMethod(nameof(GetMetadataValue)); /// /// Generate a provider function that takes a dictionary of metadata, and outputs a typed metadata object. @@ -68,7 +68,7 @@ prop.GetMethod is not null && !prop.GetMethod.IsStatic && { var dva = Expression.Constant(prop.GetCustomAttribute(false), typeof(DefaultValueAttribute)); var name = Expression.Constant(prop.Name, typeof(string)); - var m = GetMetadataValueMethod.MakeGenericMethod(prop.PropertyType); + var m = _getMetadataValueMethod.MakeGenericMethod(prop.PropertyType); var assign = Expression.Assign( Expression.Property(resultVar, prop), Expression.Call(null, m, providerArg, name, dva)); @@ -88,7 +88,7 @@ prop.GetMethod is not null && !prop.GetMethod.IsStatic && private static TValue? GetMetadataValue(IDictionary metadata, string name, DefaultValueAttribute defaultValue) { - if (metadata.TryGetValue(name, out object? result)) + if (metadata.TryGetValue(name, out var result)) { return (TValue)result; } diff --git a/src/Autofac/Features/Metadata/Meta{T,TMetadata}.cs b/src/Autofac/Features/Metadata/Meta{T,TMetadata}.cs index 4e2dcaf1c..9173e2cf4 100644 --- a/src/Autofac/Features/Metadata/Meta{T,TMetadata}.cs +++ b/src/Autofac/Features/Metadata/Meta{T,TMetadata}.cs @@ -24,10 +24,16 @@ public Meta(T value, TMetadata metadata) /// /// Gets the value described by . /// - public T Value { get; } + public T Value + { + get; + } /// /// Gets metadata describing the value. /// - public TMetadata Metadata { get; } + public TMetadata Metadata + { + get; + } } diff --git a/src/Autofac/Features/Metadata/Meta{T}.cs b/src/Autofac/Features/Metadata/Meta{T}.cs index 6c7ef7cd2..fabdaba56 100644 --- a/src/Autofac/Features/Metadata/Meta{T}.cs +++ b/src/Autofac/Features/Metadata/Meta{T}.cs @@ -23,10 +23,16 @@ public Meta(T value, IDictionary metadata) /// /// Gets the value described by . /// - public T Value { get; } + public T Value + { + get; + } /// /// Gets the metadata describing the value. /// - public IDictionary Metadata { get; } + public IDictionary Metadata + { + get; + } } diff --git a/src/Autofac/Features/Metadata/StronglyTypedMetaRegistrationSource.cs b/src/Autofac/Features/Metadata/StronglyTypedMetaRegistrationSource.cs index 4567bc9e4..dc47e13f7 100644 --- a/src/Autofac/Features/Metadata/StronglyTypedMetaRegistrationSource.cs +++ b/src/Autofac/Features/Metadata/StronglyTypedMetaRegistrationSource.cs @@ -18,7 +18,7 @@ internal class StronglyTypedMetaRegistrationSource : IRegistrationSource { private const string ReflectionCacheName = $"{nameof(StronglyTypedMetaRegistrationSource)}.Cache"; - private static readonly MethodInfo CreateMetaRegistrationMethod = typeof(StronglyTypedMetaRegistrationSource).GetDeclaredMethod(nameof(CreateMetaRegistration)); + private static readonly MethodInfo _createMetaRegistrationMethod = typeof(StronglyTypedMetaRegistrationSource).GetDeclaredMethod(nameof(CreateMetaRegistration)); private delegate IComponentRegistration RegistrationCreator(Service providedService, Service valueService, ServiceRegistration valueRegistration); @@ -54,7 +54,7 @@ public IEnumerable RegistrationsFor(Service service, Fun var registrationCreator = methodCache.GetOrAdd((valueType, metaType), t => { - return CreateMetaRegistrationMethod.MakeGenericMethod(t.Item1, t.Item2).CreateDelegate(null); + return _createMetaRegistrationMethod.MakeGenericMethod(t.Item1, t.Item2).CreateDelegate(null); }); return registrationAccessor(valueService) diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorActivatorData.cs b/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorActivatorData.cs index 742e71c26..b3005f652 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorActivatorData.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorActivatorData.cs @@ -36,5 +36,8 @@ public OpenGenericDecoratorActivatorData(Type implementer, IServiceWithType from /// /// Gets the open generic service type to decorate. /// - public IServiceWithType FromService { get; } + public IServiceWithType FromService + { + get; + } } diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorRegistrationSource.cs b/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorRegistrationSource.cs index 35c561a38..d41a76d20 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorRegistrationSource.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericDecoratorRegistrationSource.cs @@ -72,7 +72,7 @@ public IEnumerable RegistrationsFor(Service service, Fun return Enumerable.Empty(); } - if (OpenGenericServiceBinder.TryBindOpenGenericTypedService(swt, _registrationData.Services, _activatorData.ImplementationType, out Type? constructedImplementationType, out Service[]? services)) + if (OpenGenericServiceBinder.TryBindOpenGenericTypedService(swt, _registrationData.Services, _activatorData.ImplementationType, out var constructedImplementationType, out var services)) { var fromService = _activatorData.FromService.ChangeType(swt.ServiceType); @@ -107,7 +107,7 @@ private static Parameter[] AddDecoratedComponentParameter(Service service, Type var resultArray = new Parameter[configuredParameters.Count + 1]; resultArray[0] = parameter; - for (int i = 0; i < configuredParameters.Count; i++) + for (var i = 0; i < configuredParameters.Count; i++) { resultArray[i + 1] = configuredParameters[i]; } diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericDelegateActivatorData.cs b/src/Autofac/Features/OpenGenerics/OpenGenericDelegateActivatorData.cs index 15c423ec3..03e21bb1a 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericDelegateActivatorData.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericDelegateActivatorData.cs @@ -22,5 +22,8 @@ public OpenGenericDelegateActivatorData(Func /// Gets the factory method that will create a closed generic instance. /// - public Func, object> Factory { get; } + public Func, object> Factory + { + get; + } } diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericDelegateRegistrationSource.cs b/src/Autofac/Features/OpenGenerics/OpenGenericDelegateRegistrationSource.cs index aaeba014e..f2997d462 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericDelegateRegistrationSource.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericDelegateRegistrationSource.cs @@ -55,7 +55,7 @@ public IEnumerable RegistrationsFor(Service service, Fun yield break; } - if (OpenGenericServiceBinder.TryBindOpenGenericDelegateService(swt, _registrationData.Services, _activatorData.Factory, out var constructedFactory, out Service[]? services)) + if (OpenGenericServiceBinder.TryBindOpenGenericDelegateService(swt, _registrationData.Services, _activatorData.Factory, out var constructedFactory, out var services)) { // Pass the pipeline builder from the original registration to the 'CreateRegistration'. // So the original registration will contain all of the pipeline stages originally added, plus anything we want to add. diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericRegistrationSource.cs b/src/Autofac/Features/OpenGenerics/OpenGenericRegistrationSource.cs index 6d8422735..dcb6a5671 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericRegistrationSource.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericRegistrationSource.cs @@ -67,7 +67,7 @@ public IEnumerable RegistrationsFor(Service service, Fun yield break; } - if (OpenGenericServiceBinder.TryBindOpenGenericTypedService(swt, _registrationData.Services, _activatorData.ImplementationType, out Type? constructedImplementationType, out Service[]? services)) + if (OpenGenericServiceBinder.TryBindOpenGenericTypedService(swt, _registrationData.Services, _activatorData.ImplementationType, out var constructedImplementationType, out var services)) { // Pass the pipeline builder from the original registration to the 'CreateRegistration'. // So the original registration will contain all of the pipeline stages originally added, plus anything we want to add. diff --git a/src/Autofac/Features/OpenGenerics/OpenGenericServiceBinder.cs b/src/Autofac/Features/OpenGenerics/OpenGenericServiceBinder.cs index eb5ba2fdc..cae5ba040 100644 --- a/src/Autofac/Features/OpenGenerics/OpenGenericServiceBinder.cs +++ b/src/Autofac/Features/OpenGenerics/OpenGenericServiceBinder.cs @@ -260,8 +260,8 @@ public static void EnforceBindable(Type implementationType, IEnumerable return baseType; } - private static Type[] GetInterfaces(Type implementationType, Type serviceType) => - implementationType.GetInterfaces() + private static Type[] GetInterfaces(Type implementationType, Type serviceType) + => implementationType.GetInterfaces() .Where(i => i.Name == serviceType.Name && i.Namespace == serviceType.Namespace) .ToArray(); diff --git a/src/Autofac/Features/OwnedInstances/Owned.cs b/src/Autofac/Features/OwnedInstances/Owned.cs index 044d63adc..16bbee883 100644 --- a/src/Autofac/Features/OwnedInstances/Owned.cs +++ b/src/Autofac/Features/OwnedInstances/Owned.cs @@ -80,7 +80,10 @@ public Owned(T value, IDisposable lifetime) /// /// Gets or sets the owned value. /// - public T Value { get; set; } + public T Value + { + get; set; + } /// /// Releases unmanaged and - optionally - managed resources. diff --git a/src/Autofac/Features/ResolveAnything/AnyConcreteTypeNotAlreadyRegisteredSource.cs b/src/Autofac/Features/ResolveAnything/AnyConcreteTypeNotAlreadyRegisteredSource.cs index fb093332f..982e5402c 100644 --- a/src/Autofac/Features/ResolveAnything/AnyConcreteTypeNotAlreadyRegisteredSource.cs +++ b/src/Autofac/Features/ResolveAnything/AnyConcreteTypeNotAlreadyRegisteredSource.cs @@ -46,7 +46,10 @@ public AnyConcreteTypeNotAlreadyRegisteredSource(Func predicate) /// A that can be used to modify the behavior /// of registrations that are generated by this source. /// - public Action>? RegistrationConfiguration { get; set; } + public Action>? RegistrationConfiguration + { + get; set; + } /// /// Retrieve registrations for an unregistered service, to be used diff --git a/src/Autofac/Features/Scanning/BaseScanningActivatorData.cs b/src/Autofac/Features/Scanning/BaseScanningActivatorData.cs index 48a40e38b..480eb7e07 100644 --- a/src/Autofac/Features/Scanning/BaseScanningActivatorData.cs +++ b/src/Autofac/Features/Scanning/BaseScanningActivatorData.cs @@ -28,7 +28,10 @@ protected BaseScanningActivatorData( /// /// Gets the additional actions to be performed on the concrete type registrations. /// - public ICollection>> ConfigurationActions { get; } + public ICollection>> ConfigurationActions + { + get; + } /// /// Gets the filters applied to the types from the scanned assembly. diff --git a/src/Autofac/IComponentContext.cs b/src/Autofac/IComponentContext.cs index b462652fb..d251e494d 100644 --- a/src/Autofac/IComponentContext.cs +++ b/src/Autofac/IComponentContext.cs @@ -16,7 +16,10 @@ public interface IComponentContext /// /// Gets the associated services with the components that provide them. /// - IComponentRegistry ComponentRegistry { get; } + IComponentRegistry ComponentRegistry + { + get; + } /// /// Resolve an instance of the provided registration within the context. diff --git a/src/Autofac/IContainer.cs b/src/Autofac/IContainer.cs index 5bbf2b733..3a5a9b565 100644 --- a/src/Autofac/IContainer.cs +++ b/src/Autofac/IContainer.cs @@ -34,5 +34,8 @@ public interface IContainer : ILifetimeScope /// Gets the to which /// trace events should be written. /// - DiagnosticListener DiagnosticSource { get; } + DiagnosticListener DiagnosticSource + { + get; + } } diff --git a/src/Autofac/ILifetimeScope.cs b/src/Autofac/ILifetimeScope.cs index e26fc3a96..9f474983a 100644 --- a/src/Autofac/ILifetimeScope.cs +++ b/src/Autofac/ILifetimeScope.cs @@ -85,7 +85,10 @@ public interface ILifetimeScope : IComponentContext, IDisposable, IAsyncDisposab /// /// Typical usage does not require interaction with this member- it /// is used when extending the container. - IDisposer Disposer { get; } + IDisposer Disposer + { + get; + } /// /// Gets the tag applied to the . @@ -93,7 +96,10 @@ public interface ILifetimeScope : IComponentContext, IDisposable, IAsyncDisposab /// Tags allow a level in the lifetime hierarchy to be identified. /// In most applications, tags are not necessary. /// - object Tag { get; } + object Tag + { + get; + } /// /// Begin a new nested scope. Component instances created via the new scope diff --git a/src/Autofac/KeyedServiceKeyParameter.cs b/src/Autofac/KeyedServiceKeyParameter.cs index 43226d9b3..a9618578e 100644 --- a/src/Autofac/KeyedServiceKeyParameter.cs +++ b/src/Autofac/KeyedServiceKeyParameter.cs @@ -23,7 +23,10 @@ public KeyedServiceKeyParameter(object serviceKey) /// /// Gets the keyed service key value. /// - public object ServiceKey { get; } + public object ServiceKey + { + get; + } /// public override bool CanSupplyValue(ParameterInfo pi, IComponentContext context, [NotNullWhen(returnValue: true)] out Func? valueProvider) diff --git a/src/Autofac/NamedParameter.cs b/src/Autofac/NamedParameter.cs index 5a75bceef..3c3f86e18 100644 --- a/src/Autofac/NamedParameter.cs +++ b/src/Autofac/NamedParameter.cs @@ -41,11 +41,14 @@ public class NamedParameter : ConstantParameter /// The name of the parameter. /// The parameter value. public NamedParameter(string name, object? value) - : base(value, pi => pi.Name == name) => - Name = Enforce.ArgumentNotNullOrEmpty(name, "name"); + : base(value, pi => pi.Name == name) + => Name = Enforce.ArgumentNotNullOrEmpty(name, "name"); /// /// Gets the name of the parameter. /// - public string Name { get; } + public string Name + { + get; + } } diff --git a/src/Autofac/PositionalParameter.cs b/src/Autofac/PositionalParameter.cs index 063564943..ff593bca5 100644 --- a/src/Autofac/PositionalParameter.cs +++ b/src/Autofac/PositionalParameter.cs @@ -55,5 +55,8 @@ public PositionalParameter(int position, object? value) /// /// Gets the zero-based position of the parameter. /// - public int Position { get; private set; } + public int Position + { + get; private set; + } } diff --git a/src/Autofac/RegistrationExtensions.Decorators.cs b/src/Autofac/RegistrationExtensions.Decorators.cs index a12e4e5d9..9f6faffee 100644 --- a/src/Autofac/RegistrationExtensions.Decorators.cs +++ b/src/Autofac/RegistrationExtensions.Decorators.cs @@ -258,7 +258,7 @@ public static void RegisterDecorator( var rb = RegistrationBuilder.ForDelegate((c, p) => { - TService? instance = (TService?)p + var instance = (TService?)p .OfType() .FirstOrDefault(tp => tp.Type == typeof(TService)) ?.Value ?? throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, RegistrationExtensionsResources.DecoratorRequiresInstanceParameter, typeof(TService).Name)); diff --git a/src/Autofac/ResolutionExtensions.cs b/src/Autofac/ResolutionExtensions.cs index 9008eeb75..76d9f67a0 100644 --- a/src/Autofac/ResolutionExtensions.cs +++ b/src/Autofac/ResolutionExtensions.cs @@ -907,7 +907,7 @@ public static object ResolveNamed(this IComponentContext context, string service throw new ArgumentNullException(nameof(parameters)); } - context.TryResolveService(service, parameters, out object? instance); + context.TryResolveService(service, parameters, out var instance); return instance; } @@ -1019,7 +1019,7 @@ public static bool TryResolve(this IComponentContext context, [NotNullWhen(re where T : class { // Null annotation attributes only work if placed directly in an if statement. - if (context.TryResolve(typeof(T), out object? component)) + if (context.TryResolve(typeof(T), out var component)) { instance = CastInstance(component); @@ -1066,7 +1066,7 @@ public static bool TryResolve(this IComponentContext context, Type serviceType, public static bool TryResolveKeyed(this IComponentContext context, object serviceKey, [NotNullWhen(returnValue: true)] out T? instance) where T : class { - if (context.TryResolveKeyed(serviceKey, typeof(T), out object? component)) + if (context.TryResolveKeyed(serviceKey, typeof(T), out var component)) { instance = CastInstance(component); @@ -1115,7 +1115,7 @@ public static bool TryResolveKeyed(this IComponentContext context, object servic public static bool TryResolveNamed(this IComponentContext context, string serviceName, [NotNullWhen(returnValue: true)] out T? instance) where T : class { - if (context.TryResolveNamed(serviceName, typeof(T), out object? component)) + if (context.TryResolveNamed(serviceName, typeof(T), out var component)) { instance = CastInstance(component); diff --git a/src/Autofac/ResolutionValueExtensions.cs b/src/Autofac/ResolutionValueExtensions.cs index 26d40c124..ec16b9bab 100644 --- a/src/Autofac/ResolutionValueExtensions.cs +++ b/src/Autofac/ResolutionValueExtensions.cs @@ -11,7 +11,7 @@ namespace Autofac; /// public static class ResolutionValueExtensions { - private static readonly IEnumerable NoParameters = Enumerable.Empty(); + private static readonly IEnumerable _noParameters = Enumerable.Empty(); /// /// Retrieve a service from the context, or null if the service is not @@ -28,7 +28,7 @@ public static class ResolutionValueExtensions public static TService? ResolveOptional(this IComponentContext context) where TService : struct { - return ResolveOptional(context, NoParameters); + return ResolveOptional(context, _noParameters); } /// @@ -85,7 +85,7 @@ public static class ResolutionValueExtensions public static TService? ResolveOptionalKeyed(this IComponentContext context, object serviceKey) where TService : struct { - return context.ResolveOptionalKeyed(serviceKey, NoParameters); + return context.ResolveOptionalKeyed(serviceKey, _noParameters); } /// @@ -208,7 +208,7 @@ public static bool TryResolve(this IComponentContext context, [NotNullWhen(re } // Null annotation attributes only work if placed directly in an if statement. - if (context.TryResolve(typeof(T), out object? component)) + if (context.TryResolve(typeof(T), out var component)) { instance = (T)component; diff --git a/src/Autofac/ResolveRequest.cs b/src/Autofac/ResolveRequest.cs index 5293e4120..962446049 100644 --- a/src/Autofac/ResolveRequest.cs +++ b/src/Autofac/ResolveRequest.cs @@ -35,27 +35,42 @@ public ResolveRequest(Service service, ServiceRegistration serviceRegistration, /// /// Gets the service being resolved. /// - public Service Service { get; } + public Service Service + { + get; + } /// /// Gets the component registration for the service being resolved. This may be null if a service is being supplied without registrations. /// - public IComponentRegistration Registration { get; } + public IComponentRegistration Registration + { + get; + } /// /// Gets the resolve pipeline for the request. /// - public IResolvePipeline ResolvePipeline { get; } + public IResolvePipeline ResolvePipeline + { + get; + } /// /// Gets the parameters used when resolving the service. /// - public IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } /// /// Gets the component registration for the decorator target if configured. /// - public IComponentRegistration? DecoratorTarget { get; } + public IComponentRegistration? DecoratorTarget + { + get; + } /// /// Implements the operator ==. @@ -71,18 +86,18 @@ public ResolveRequest(Service service, ServiceRegistration serviceRegistration, /// The left operand. /// The right operand. /// The result of the operator. - public static bool operator !=(ResolveRequest left, ResolveRequest right) => - !(left == right); + public static bool operator !=(ResolveRequest left, ResolveRequest right) + => !(left == right); /// - public override bool Equals(object? obj) => - obj is ResolveRequest other && Equals(other); + public override bool Equals(object? obj) + => obj is ResolveRequest other && Equals(other); /// - public bool Equals(ResolveRequest other) => - Service == other.Service && Registration == other.Registration && ResolvePipeline == other.ResolvePipeline && Parameters == other.Parameters && DecoratorTarget == other.DecoratorTarget; + public bool Equals(ResolveRequest other) + => Service == other.Service && Registration == other.Registration && ResolvePipeline == other.ResolvePipeline && Parameters == other.Parameters && DecoratorTarget == other.DecoratorTarget; /// - public override int GetHashCode() => - Service.GetHashCode() ^ Registration.GetHashCode() ^ ResolvePipeline.GetHashCode() ^ Parameters.GetHashCode() ^ (DecoratorTarget?.GetHashCode() ?? 0); + public override int GetHashCode() + => Service.GetHashCode() ^ Registration.GetHashCode() ^ ResolvePipeline.GetHashCode() ^ Parameters.GetHashCode() ^ (DecoratorTarget?.GetHashCode() ?? 0); } diff --git a/src/Autofac/TypedParameter.cs b/src/Autofac/TypedParameter.cs index 815961978..a677f00b4 100644 --- a/src/Autofac/TypedParameter.cs +++ b/src/Autofac/TypedParameter.cs @@ -50,7 +50,10 @@ public TypedParameter(Type type, object? value) /// Gets the type against which targets are matched. /// [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "Property serves a different purpose than the default get method.")] - public Type Type { get; private set; } + public Type Type + { + get; private set; + } /// /// Shortcut for creating diff --git a/src/Autofac/Util/Enforce.cs b/src/Autofac/Util/Enforce.cs index 69095b7cd..b518db06c 100644 --- a/src/Autofac/Util/Enforce.cs +++ b/src/Autofac/Util/Enforce.cs @@ -92,7 +92,7 @@ public static void ArgumentTypeIsFunction(Type delegateType) throw new ArgumentNullException(nameof(delegateType)); } - MethodInfo invoke = delegateType.GetDeclaredMethod("Invoke") ?? throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, EnforceResources.NotDelegate, delegateType)); + var invoke = delegateType.GetDeclaredMethod("Invoke") ?? throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, EnforceResources.NotDelegate, delegateType)); if (invoke.ReturnType == typeof(void)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, EnforceResources.DelegateReturnsVoid, delegateType)); diff --git a/src/Autofac/Util/FallbackDictionary.cs b/src/Autofac/Util/FallbackDictionary.cs index 6cc47ff67..000f46b28 100644 --- a/src/Autofac/Util/FallbackDictionary.cs +++ b/src/Autofac/Util/FallbackDictionary.cs @@ -134,7 +134,7 @@ public TValue this[TKey key] { get { - if (_localValues.TryGetValue(key, out TValue? value)) + if (_localValues.TryGetValue(key, out var value)) { return value; } diff --git a/src/Autofac/Util/LinkerAttributes.cs b/src/Autofac/Util/LinkerAttributes.cs index bc4a0ee5b..b01d530e2 100644 --- a/src/Autofac/Util/LinkerAttributes.cs +++ b/src/Autofac/Util/LinkerAttributes.cs @@ -101,7 +101,10 @@ public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes member /// Gets the which specifies the type /// of members dynamically accessed. /// - public DynamicallyAccessedMemberTypes MemberTypes { get; } + public DynamicallyAccessedMemberTypes MemberTypes + { + get; + } } /// @@ -130,13 +133,19 @@ public RequiresUnreferencedCodeAttribute(string message) /// /// Gets a message that contains information about the usage of unreferenced code. /// - public string Message { get; } + public string Message + { + get; + } /// /// Gets or sets an optional URL that contains more information about the method, /// why it requries unreferenced code, and what options a consumer has to deal with it. /// - public string? Url { get; set; } + public string? Url + { + get; set; + } } #endif diff --git a/src/Autofac/Util/NullableAttributes.cs b/src/Autofac/Util/NullableAttributes.cs index 6bd5dcb2f..e8a2295a4 100644 --- a/src/Autofac/Util/NullableAttributes.cs +++ b/src/Autofac/Util/NullableAttributes.cs @@ -47,7 +47,10 @@ internal sealed class MaybeNullWhenAttribute : Attribute /// /// Gets a value indicating whether the return value is required to be true or false. /// - public bool ReturnValue { get; } + public bool ReturnValue + { + get; + } } /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. @@ -64,7 +67,10 @@ internal sealed class NotNullWhenAttribute : Attribute /// /// Gets a value indicating whether the return value is required to be true or false. /// - public bool ReturnValue { get; } + public bool ReturnValue + { + get; + } } /// Specifies that the output will be non-null if the named parameter is non-null. @@ -81,7 +87,10 @@ internal sealed class NotNullIfNotNullAttribute : Attribute /// /// Gets the name of the parameter. /// - public string ParameterName { get; } + public string ParameterName + { + get; + } } /// Applied to a method that will never return under any circumstance. @@ -105,6 +114,9 @@ internal sealed class DoesNotReturnIfAttribute : Attribute /// /// Gets a value indicating whether the parameter value is expected to be true or false. /// - public bool ParameterValue { get; } + public bool ParameterValue + { + get; + } } #endif diff --git a/test/Autofac.Specification.Test/ContainerBuilderTests.cs b/test/Autofac.Specification.Test/ContainerBuilderTests.cs index 58dde3031..36e5c4eb9 100644 --- a/test/Autofac.Specification.Test/ContainerBuilderTests.cs +++ b/test/Autofac.Specification.Test/ContainerBuilderTests.cs @@ -178,7 +178,10 @@ public void OnlyAllowBuildOnce() private class BuildCallbackModule : Module { - public int Called { get; private set; } + public int Called + { + get; private set; + } protected override void Load(ContainerBuilder builder) { @@ -195,9 +198,15 @@ void BuildCallback(ILifetimeScope c) private class NestingModule : Module { - public bool OuterBuildCallback { get; set; } + public bool OuterBuildCallback + { + get; set; + } - public bool InnerBuildCallback { get; set; } + public bool InnerBuildCallback + { + get; set; + } protected override void Load(ContainerBuilder containerBuilder) { diff --git a/test/Autofac.Specification.Test/Diagnostics/DefaultDiagnosticTracerTests.cs b/test/Autofac.Specification.Test/Diagnostics/DefaultDiagnosticTracerTests.cs index 844bb16fb..a3a1f3250 100644 --- a/test/Autofac.Specification.Test/Diagnostics/DefaultDiagnosticTracerTests.cs +++ b/test/Autofac.Specification.Test/Diagnostics/DefaultDiagnosticTracerTests.cs @@ -114,7 +114,10 @@ public Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } private class Implementor : IService diff --git a/test/Autofac.Specification.Test/Features/CircularDependency/DependsByCtor.cs b/test/Autofac.Specification.Test/Features/CircularDependency/DependsByCtor.cs index 1868b2a65..aaa2822cb 100644 --- a/test/Autofac.Specification.Test/Features/CircularDependency/DependsByCtor.cs +++ b/test/Autofac.Specification.Test/Features/CircularDependency/DependsByCtor.cs @@ -10,5 +10,8 @@ public DependsByCtor(DependsByProp o) Dep = o; } - public DependsByProp Dep { get; private set; } + public DependsByProp Dep + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Features/CircularDependency/DependsByProp.cs b/test/Autofac.Specification.Test/Features/CircularDependency/DependsByProp.cs index 5d4789d32..34885de2c 100644 --- a/test/Autofac.Specification.Test/Features/CircularDependency/DependsByProp.cs +++ b/test/Autofac.Specification.Test/Features/CircularDependency/DependsByProp.cs @@ -5,5 +5,8 @@ namespace Autofac.Specification.Test.Features.CircularDependency; public class DependsByProp { - public DependsByCtor Dep { get; set; } + public DependsByCtor Dep + { + get; set; + } } diff --git a/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs b/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs index ce498b012..b5a705549 100644 --- a/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs +++ b/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs @@ -227,36 +227,60 @@ public void CircularDependenciesHandledWhenAllDependenciesPropertyInjected() private interface ICircularDependencyA { - ICircularDependencyB DependencyB { get; } + ICircularDependencyB DependencyB + { + get; + } } private interface ICircularDependencyB { - ICircularDependencyA DependencyA { get; } + ICircularDependencyA DependencyA + { + get; + } } private interface ICircularDependencyHost { - public ICircularDependencyB DependencyB { get; } + ICircularDependencyB DependencyB + { + get; + } - public ICircularDependencyA DependencyA { get; } + ICircularDependencyA DependencyA + { + get; + } } private class CircularDependencyA : ICircularDependencyA { - public ICircularDependencyB DependencyB { get; set; } + public ICircularDependencyB DependencyB + { + get; set; + } } private class CircularDependencyB : ICircularDependencyB { - public ICircularDependencyA DependencyA { get; set; } + public ICircularDependencyA DependencyA + { + get; set; + } } private class CircularDependencyHost : ICircularDependencyHost { - public ICircularDependencyB DependencyB { get; set; } + public ICircularDependencyB DependencyB + { + get; set; + } - public ICircularDependencyA DependencyA { get; set; } + public ICircularDependencyA DependencyA + { + get; set; + } } private static IPlugin SafeResolvePlugin(string pluginName, IComponentContext core) diff --git a/test/Autofac.Specification.Test/Features/CompositeTests.cs b/test/Autofac.Specification.Test/Features/CompositeTests.cs index f4dc32988..de05bd8fe 100644 --- a/test/Autofac.Specification.Test/Features/CompositeTests.cs +++ b/test/Autofac.Specification.Test/Features/CompositeTests.cs @@ -744,7 +744,10 @@ public MyComposite(IList implementations) Implementations = implementations; } - public IList Implementations { get; } + public IList Implementations + { + get; + } } private class MultiComposite : I1, I2 @@ -755,9 +758,15 @@ public MultiComposite(IEnumerable composite1, IEnumerable composite2) Composite2 = composite2; } - public IEnumerable Composite1 { get; } + public IEnumerable Composite1 + { + get; + } - public IEnumerable Composite2 { get; } + public IEnumerable Composite2 + { + get; + } } private class MyLazyComposite : I1 @@ -767,7 +776,10 @@ public MyLazyComposite(Lazy> implementations) Implementations = implementations; } - public Lazy> Implementations { get; } + public Lazy> Implementations + { + get; + } } private class CircularComposite : I1 @@ -784,7 +796,10 @@ public DecoratorForI1(I1 instance) Instance = instance; } - public I1 Instance { get; } + public I1 Instance + { + get; + } } private interface IGenericService @@ -810,7 +825,10 @@ public GenericComposite(IList> implementations) Implementations = implementations; } - public IList> Implementations { get; } + public IList> Implementations + { + get; + } } private interface I1 diff --git a/test/Autofac.Specification.Test/Features/DecoratorTests.cs b/test/Autofac.Specification.Test/Features/DecoratorTests.cs index 77e1cc4c0..d4b220e02 100644 --- a/test/Autofac.Specification.Test/Features/DecoratorTests.cs +++ b/test/Autofac.Specification.Test/Features/DecoratorTests.cs @@ -12,17 +12,26 @@ public class DecoratorTests { private interface IDecoratedService : IService { - IDecoratedService Decorated { get; } + IDecoratedService Decorated + { + get; + } } private interface IDecoratorWithContext { - IDecoratorContext Context { get; } + IDecoratorContext Context + { + get; + } } private interface IDecoratorWithParameter { - string Parameter { get; } + string Parameter + { + get; + } } private interface IService @@ -608,20 +617,20 @@ public void DecoratorAndDecoratedBothDisposedWhenInstancePerLifetimeScope() [Fact] public void DecoratorAndDecoratedBothDisposedWhenInstancePerMatchingLifetimeScope() { - const string tag = "foo"; + const string Tag = "foo"; var builder = new ContainerBuilder(); builder.RegisterType() .As() - .InstancePerMatchingLifetimeScope(tag); + .InstancePerMatchingLifetimeScope(Tag); builder.RegisterDecorator(); var container = builder.Build(); DisposableDecorator decorator; DisposableImplementor decorated; - using (var scope = container.BeginLifetimeScope(tag)) + using (var scope = container.BeginLifetimeScope(Tag)) { var instance = scope.Resolve(); decorator = (DisposableDecorator)instance; @@ -818,17 +827,17 @@ public void DecoratorInheritsDecoratedLifetimeWhenInstancePerLifetimeScope() [Fact] public void DecoratorInheritsDecoratedLifetimeWhenInstancePerMatchingLifetimeScope() { - const string tag = "foo"; + const string Tag = "foo"; var builder = new ContainerBuilder(); builder.RegisterType() .As() - .InstancePerMatchingLifetimeScope(tag); + .InstancePerMatchingLifetimeScope(Tag); builder.RegisterDecorator(); var container = builder.Build(); - using (var scope = container.BeginLifetimeScope(tag)) + using (var scope = container.BeginLifetimeScope(Tag)) { var first = scope.Resolve(); var second = scope.Resolve(); @@ -863,8 +872,8 @@ public void DecoratorInheritsDecoratedLifetimeWhenSingleInstance() [Fact] public void DecoratorRegisteredAsLambdaCanAcceptAdditionalParameters() { - const string parameterName = "parameter"; - const string parameterValue = "ABC"; + const string ParameterName = "parameter"; + const string ParameterValue = "ABC"; var builder = new ContainerBuilder(); builder.RegisterType().As(); @@ -872,17 +881,17 @@ public void DecoratorRegisteredAsLambdaCanAcceptAdditionalParameters() { var stringParameter = (string)p .OfType() - .FirstOrDefault(np => np.Name == parameterName)?.Value; + .FirstOrDefault(np => np.Name == ParameterName)?.Value; return new DecoratorWithParameter(i, stringParameter); }); builder.RegisterDecorator(); var container = builder.Build(); - var parameter = new NamedParameter(parameterName, parameterValue); + var parameter = new NamedParameter(ParameterName, ParameterValue); var instance = container.Resolve(parameter); - Assert.Equal(parameterValue, ((DecoratorWithParameter)instance.Decorated).Parameter); + Assert.Equal(ParameterValue, ((DecoratorWithParameter)instance.Decorated).Parameter); } [Fact] @@ -1216,7 +1225,7 @@ public void OpenGenericCanBeDecoratedFromInsideAModuleDecoratorRegisteredSecond( } [Fact] - public void OpenGenericInModuleCanBeDecoratoredByDecoratorOutsideModuleWhereModuleRegisteredFirst() + public void OpenGenericInModuleCanBeDecoratedByDecoratorOutsideModuleWhereModuleRegisteredFirst() { var activatedInstances = new List(); @@ -1235,7 +1244,7 @@ public void OpenGenericInModuleCanBeDecoratoredByDecoratorOutsideModuleWhereModu } [Fact] - public void OpenGenericInModuleCanBeDecoratoredByDecoratorOutsideModuleWhereModuleRegisteredSecond() + public void OpenGenericInModuleCanBeDecoratedByDecoratorOutsideModuleWhereModuleRegisteredSecond() { var activatedInstances = new List(); @@ -1289,7 +1298,10 @@ public void DecoratorConditionalFunctionThrowsCircularDependencyErrorOnResolveSe private class MyMetadata { - public int A { get; set; } + public int A + { + get; set; + } } private abstract class Decorator : IDecoratedService @@ -1299,7 +1311,10 @@ protected Decorator(IDecoratedService decorated) Decorated = decorated; } - public IDecoratedService Decorated { get; } + public IDecoratedService Decorated + { + get; + } } private class DecoratorA : Decorator @@ -1326,7 +1341,10 @@ public DecoratorWithContextA(IDecoratedService decorated, IDecoratorContext cont Context = context; } - public IDecoratorContext Context { get; } + public IDecoratorContext Context + { + get; + } } // ReSharper disable once ClassNeverInstantiated.Local @@ -1338,7 +1356,10 @@ public DecoratorWithContextB(IDecoratedService decorated, IDecoratorContext cont Context = context; } - public IDecoratorContext Context { get; } + public IDecoratorContext Context + { + get; + } } private class DecoratorWithFunc : IDecoratedService @@ -1348,7 +1369,10 @@ public DecoratorWithFunc(Func decorated) Decorated = decorated(); } - public IDecoratedService Decorated { get; } + public IDecoratedService Decorated + { + get; + } } private class DecoratorWithLazy : IDecoratedService @@ -1358,7 +1382,10 @@ public DecoratorWithLazy(Lazy decorated) Decorated = decorated.Value; } - public IDecoratedService Decorated { get; } + public IDecoratedService Decorated + { + get; + } } private class DecoratorWithParameter : Decorator, IDecoratorWithParameter @@ -1369,7 +1396,10 @@ public DecoratorWithParameter(IDecoratedService decorated, string parameter) Parameter = parameter; } - public string Parameter { get; } + public string Parameter + { + get; + } } // ReSharper disable once ClassNeverInstantiated.Local @@ -1380,7 +1410,10 @@ public DisposableDecorator(IDecoratedService decorated) { } - public int DisposeCallCount { get; private set; } + public int DisposeCallCount + { + get; private set; + } public void Dispose() { @@ -1393,7 +1426,10 @@ private class DisposableImplementor : IDecoratedService, IDisposable { public IDecoratedService Decorated => this; - public int DisposeCallCount { get; private set; } + public int DisposeCallCount + { + get; private set; + } public void Dispose() { @@ -1422,7 +1458,10 @@ public ImplementorWithParameters(string parameter) public IDecoratedService Decorated => this; - public string Parameter { get; } + public string Parameter + { + get; + } } // ReSharper disable once ClassNeverInstantiated.Local @@ -1436,7 +1475,10 @@ private class StartableImplementation : IStartable { public IStartable Decorated => this; - public bool Started { get; private set; } + public bool Started + { + get; private set; + } public void Start() { @@ -1447,7 +1489,10 @@ public void Start() // ReSharper disable once ClassNeverInstantiated.Local private class StartableDecorator : IStartable { - public IStartable Decorated { get; } + public IStartable Decorated + { + get; + } public StartableDecorator(IStartable startable) { @@ -1490,11 +1535,17 @@ public GenericDecorator(IGenericService decorated) Decorated = decorated; } - public IGenericService Decorated { get; } + public IGenericService Decorated + { + get; + } } private class ConditionalShouldDecorate { - public bool ShouldDecorate { get; set; } + public bool ShouldDecorate + { + get; set; + } } } diff --git a/test/Autofac.Specification.Test/Features/KeyedServiceTests.cs b/test/Autofac.Specification.Test/Features/KeyedServiceTests.cs index be87d2841..fdcaeab1c 100644 --- a/test/Autofac.Specification.Test/Features/KeyedServiceTests.cs +++ b/test/Autofac.Specification.Test/Features/KeyedServiceTests.cs @@ -266,8 +266,8 @@ public void ResolveWithAnyKeyQuery_Constructor(bool anyKeyQueryBeforeSingletonQu void DoAnyKeyQuery() { - IEnumerable allA = provider.ResolveKeyed>(KeyedService.AnyKey); - IEnumerable allB = provider.ResolveKeyed>(KeyedService.AnyKey); + var allA = provider.ResolveKeyed>(KeyedService.AnyKey); + var allB = provider.ResolveKeyed>(KeyedService.AnyKey); // Verify caching returns the same IEnumerable<> instance. Assert.Same(allA, provider.ResolveKeyed>(KeyedService.AnyKey)); @@ -333,8 +333,8 @@ public void ResolveWithAnyKeyQuery_Constructor_Duplicates(bool anyKeyQueryBefore void DoAnyKeyQuery() { - IEnumerable allA = provider.ResolveKeyed>(KeyedService.AnyKey); - IEnumerable allB = provider.ResolveKeyed>(KeyedService.AnyKey); + var allA = provider.ResolveKeyed>(KeyedService.AnyKey); + var allB = provider.ResolveKeyed>(KeyedService.AnyKey); // Verify caching returns the same IEnumerable<> instances. Assert.Same(allA, provider.ResolveKeyed>(KeyedService.AnyKey)); @@ -409,8 +409,8 @@ public void ResolveWithAnyKeyQuery_InstanceProvided(bool anyKeyQueryBeforeSingle void DoAnyKeyQuery() { - IEnumerable allA = provider.ResolveKeyed>(KeyedService.AnyKey); - IEnumerable allB = provider.ResolveKeyed>(KeyedService.AnyKey); + var allA = provider.ResolveKeyed>(KeyedService.AnyKey); + var allB = provider.ResolveKeyed>(KeyedService.AnyKey); // Verify caching returns the same items. Assert.Equal(allA, provider.ResolveKeyed>(KeyedService.AnyKey)); @@ -475,8 +475,8 @@ public void ResolveWithAnyKeyQuery_InstanceProvided_Duplicates(bool anyKeyQueryB void DoAnyKeyQuery() { - IEnumerable allA = provider.ResolveKeyed>(KeyedService.AnyKey); - IEnumerable allB = provider.ResolveKeyed>(KeyedService.AnyKey); + var allA = provider.ResolveKeyed>(KeyedService.AnyKey); + var allB = provider.ResolveKeyed>(KeyedService.AnyKey); // Verify caching returns the same items. Assert.Equal(allA, provider.ResolveKeyed>(KeyedService.AnyKey)); @@ -729,7 +729,7 @@ public void ResolveKeyedServiceSingletonFactoryWithAnyKey() Assert.Throws(() => provider.Resolve()); - for (int i = 0; i < 3; i++) + for (var i = 0; i < 3; i++) { var key = "service" + i; var s1 = provider.ResolveKeyed(key); @@ -940,9 +940,15 @@ public OtherService( Service2 = service2; } - public IService Service1 { get; } + public IService Service1 + { + get; + } - public IService Service2 { get; } + public IService Service2 + { + get; + } } private class OtherServiceWithDefaultCtorArgs @@ -955,9 +961,15 @@ public OtherServiceWithDefaultCtorArgs( Service2 = service2; } - public IService Service1 { get; } + public IService Service1 + { + get; + } - public IService Service2 { get; } + public IService Service2 + { + get; + } } [Fact] @@ -1023,7 +1035,10 @@ private class AnotherSimpleService : ISimpleService private class FakeService : IFakeSingletonService, IFakeOpenGenericService { - public PocoClass Value { get; set; } + public PocoClass Value + { + get; set; + } } private interface IFakeSingletonService @@ -1032,7 +1047,10 @@ private interface IFakeSingletonService private interface IFakeOpenGenericService { - TValue Value { get; } + TValue Value + { + get; + } } private class PocoClass @@ -1046,6 +1064,9 @@ public FakeOpenGenericService(TVal value) Value = value; } - public TVal Value { get; } + public TVal Value + { + get; + } } } diff --git a/test/Autofac.Specification.Test/Features/PropertyInjection/CtorWithValueParameter.cs b/test/Autofac.Specification.Test/Features/PropertyInjection/CtorWithValueParameter.cs index d8bdda861..3483bc811 100644 --- a/test/Autofac.Specification.Test/Features/PropertyInjection/CtorWithValueParameter.cs +++ b/test/Autofac.Specification.Test/Features/PropertyInjection/CtorWithValueParameter.cs @@ -11,7 +11,10 @@ public class CtorWithValueParameter // parameter that is named `value` - this property doesn't // need to be filled in, it just needs to exist and not be // a simple `object` or `string` or something. - public HasMixedVisibilityProperties Dummy { get; set; } + public HasMixedVisibilityProperties Dummy + { + get; set; + } public CtorWithValueParameter(string value) { diff --git a/test/Autofac.Specification.Test/Features/PropertyInjection/HasMixedVisibilityProperties.cs b/test/Autofac.Specification.Test/Features/PropertyInjection/HasMixedVisibilityProperties.cs index 07d25123b..8e853b855 100644 --- a/test/Autofac.Specification.Test/Features/PropertyInjection/HasMixedVisibilityProperties.cs +++ b/test/Autofac.Specification.Test/Features/PropertyInjection/HasMixedVisibilityProperties.cs @@ -5,10 +5,16 @@ namespace Autofac.Specification.Test.Features.PropertyInjection; public class HasMixedVisibilityProperties { - public string PublicString { get; set; } + public string PublicString + { + get; set; + } [Inject] - private string PrivateString { get; set; } + private string PrivateString + { + get; set; + } public string PrivateStringAccessor() { diff --git a/test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetter.cs b/test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetter.cs index e8ea68c34..68a8c7e54 100644 --- a/test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetter.cs +++ b/test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetter.cs @@ -5,5 +5,8 @@ namespace Autofac.Specification.Test.Features.PropertyInjection; public class HasPublicSetter { - public string Val { get; set; } + public string Val + { + get; set; + } } diff --git a/test/Autofac.Specification.Test/Features/PropertyInjection/HasStaticSetter.cs b/test/Autofac.Specification.Test/Features/PropertyInjection/HasStaticSetter.cs index 0e17fd844..ba1a440b2 100644 --- a/test/Autofac.Specification.Test/Features/PropertyInjection/HasStaticSetter.cs +++ b/test/Autofac.Specification.Test/Features/PropertyInjection/HasStaticSetter.cs @@ -6,5 +6,8 @@ namespace Autofac.Specification.Test.Features.PropertyInjection; [SuppressMessage("CA1052", "CA1052", Justification = "Handles a specific test scenario of a non-static class with a static property.")] public class HasStaticSetter { - public static string Val { get; set; } + public static string Val + { + get; set; + } } diff --git a/test/Autofac.Specification.Test/Features/PropertyInjectionTests.cs b/test/Autofac.Specification.Test/Features/PropertyInjectionTests.cs index 5191cfb99..180ed6c93 100644 --- a/test/Autofac.Specification.Test/Features/PropertyInjectionTests.cs +++ b/test/Autofac.Specification.Test/Features/PropertyInjectionTests.cs @@ -45,24 +45,24 @@ public void InjectPropertiesAllowsSeparationOfConstructorAndPropertyParameters() [Fact] public void InjectPropertiesOverwritesSetProperties() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = new HasPublicSetterWithDefaultValue(); c.InjectProperties(obj); - Assert.Equal(str, obj.Val); + Assert.Equal(Str, obj.Val); } [Fact] public void InjectPropertiesWithDelegateSelectorAllowsPrivateSet() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = new HasMixedVisibilityProperties(); @@ -71,16 +71,16 @@ public void InjectPropertiesWithDelegateSelectorAllowsPrivateSet() Assert.Null(obj.PrivateStringAccessor()); c.InjectProperties(obj, new DelegatePropertySelector((p, _) => p.GetCustomAttributes().Any())); Assert.Null(obj.PublicString); - Assert.Equal(str, obj.PrivateStringAccessor()); + Assert.Equal(Str, obj.PrivateStringAccessor()); } [Fact] public void InjectPropertiesWithPropertySelectorAllowsPrivateSet() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = new HasMixedVisibilityProperties(); @@ -89,16 +89,16 @@ public void InjectPropertiesWithPropertySelectorAllowsPrivateSet() Assert.Null(obj.PrivateStringAccessor()); c.InjectProperties(obj, new InjectAttributePropertySelector()); Assert.Null(obj.PublicString); - Assert.Equal(str, obj.PrivateStringAccessor()); + Assert.Equal(Str, obj.PrivateStringAccessor()); } [Fact] public void InjectUnsetPropertiesSkipsSetProperties() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = new HasPublicSetter() @@ -113,10 +113,10 @@ public void InjectUnsetPropertiesSkipsSetProperties() [Fact] public void InjectUnsetPropertiesUsesPublicOnly() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = new HasMixedVisibilityProperties(); @@ -124,7 +124,7 @@ public void InjectUnsetPropertiesUsesPublicOnly() Assert.Null(obj.PublicString); Assert.Null(obj.PrivateStringAccessor()); c.InjectUnsetProperties(obj); - Assert.Equal(str, obj.PublicString); + Assert.Equal(Str, obj.PublicString); Assert.Null(obj.PrivateStringAccessor()); } @@ -247,50 +247,50 @@ public void PropertiesAutowiredSetsWriteOnlyPublicProperty() [Fact] public void PropertiesAutowiredUsingDelegateSelector() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); cb.Register(_ => new HasMixedVisibilityProperties()) .PropertiesAutowired(new DelegatePropertySelector((p, _) => p.GetCustomAttributes().Any())); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = c.Resolve(); Assert.Null(obj.PublicString); - Assert.Equal(str, obj.PrivateStringAccessor()); + Assert.Equal(Str, obj.PrivateStringAccessor()); } [Fact] public void PropertiesAutowiredUsingInlineDelegate() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); cb.RegisterType() .PropertiesAutowired((propInfo, instance) => true); - cb.RegisterInstance(str); // Must register, otherwise delegate won't be called + cb.RegisterInstance(Str); // Must register, otherwise delegate won't be called var c = cb.Build(); var obj = c.Resolve(); - Assert.Equal(str, obj.PublicString); - Assert.Equal(str, obj.PrivateStringAccessor()); + Assert.Equal(Str, obj.PublicString); + Assert.Equal(Str, obj.PrivateStringAccessor()); } [Fact] public void PropertiesAutowiredUsingPropertySelector() { - const string str = "test"; + const string Str = "test"; var cb = new ContainerBuilder(); cb.Register(_ => new HasMixedVisibilityProperties()) .PropertiesAutowired(new InjectAttributePropertySelector()); - cb.RegisterInstance(str); + cb.RegisterInstance(Str); var c = cb.Build(); var obj = c.Resolve(); Assert.Null(obj.PublicString); - Assert.Equal(str, obj.PrivateStringAccessor()); + Assert.Equal(Str, obj.PrivateStringAccessor()); } [Fact] @@ -440,19 +440,31 @@ public ConstructorParamNotAttachedToProperty(string id) _id = id; } - public string Name { get; set; } + public string Name + { + get; set; + } } private class EnumProperty { - public SimpleEnumeration Value { get; set; } + public SimpleEnumeration Value + { + get; set; + } } private class SplitAccess { - public bool GetterCalled { get; set; } + public bool GetterCalled + { + get; set; + } - public bool SetterCalled { get; set; } + public bool SetterCalled + { + get; set; + } public string Value { @@ -476,7 +488,10 @@ private interface IMyService private sealed class DecoratedService : IMyService { - public string Prop { get; set; } + public string Prop + { + get; set; + } public void AssertProp() { diff --git a/test/Autofac.Specification.Test/Features/RequiredPropertyTests.cs b/test/Autofac.Specification.Test/Features/RequiredPropertyTests.cs index 5248c3fc0..265fb2b76 100644 --- a/test/Autofac.Specification.Test/Features/RequiredPropertyTests.cs +++ b/test/Autofac.Specification.Test/Features/RequiredPropertyTests.cs @@ -259,7 +259,10 @@ public void CanResolveOpenGenericComponentRequiredProperties() private class OpenGenericComponent { - public required OpenGenericService Service { get; set; } + public required OpenGenericService Service + { + get; set; + } } private class OpenGenericService @@ -273,9 +276,15 @@ public ConstructorComponent() { } - public required ServiceA ServiceA { get; set; } + public required ServiceA ServiceA + { + get; set; + } - public required ServiceB ServiceB { get; set; } + public required ServiceB ServiceB + { + get; set; + } } private class MixedConstructorAndPropertyComponent @@ -285,9 +294,15 @@ public MixedConstructorAndPropertyComponent(ServiceA serviceA) ServiceA = serviceA; } - public ServiceA ServiceA { get; set; } + public ServiceA ServiceA + { + get; set; + } - public required ServiceB ServiceB { get; set; } + public required ServiceB ServiceB + { + get; set; + } } private class MultiConstructorComponent @@ -301,14 +316,23 @@ public MultiConstructorComponent(ServiceC serviceC) { } - public required ServiceA ServiceA { get; set; } + public required ServiceA ServiceA + { + get; set; + } } private class Component { - public required ServiceA ServiceA { get; set; } + public required ServiceA ServiceA + { + get; set; + } - public required ServiceB ServiceB { get; set; } + public required ServiceB ServiceB + { + get; set; + } } private class DerivedComponentWithProp : Component @@ -317,7 +341,10 @@ public DerivedComponentWithProp() { } - public required ServiceC ServiceC { get; set; } + public required ServiceC ServiceC + { + get; set; + } } private class DerivedComponent : Component @@ -331,7 +358,10 @@ public ServiceA() Tag = "Default"; } - public string Tag { get; set; } + public string Tag + { + get; set; + } } private class ServiceB @@ -341,7 +371,10 @@ public ServiceB() Tag = "Default"; } - public string Tag { get; set; } + public string Tag + { + get; set; + } } private class ServiceC diff --git a/test/Autofac.Specification.Test/Features/StartableTests.cs b/test/Autofac.Specification.Test/Features/StartableTests.cs index e993e9785..48052a520 100644 --- a/test/Autofac.Specification.Test/Features/StartableTests.cs +++ b/test/Autofac.Specification.Test/Features/StartableTests.cs @@ -210,7 +210,10 @@ private sealed class MyComponent2 private class Startable : IStartable { - public int StartCount { get; private set; } + public int StartCount + { + get; private set; + } public void Start() { @@ -255,7 +258,10 @@ public StartableDependency() Count++; } - public static int Count { get; set; } + public static int Count + { + get; set; + } } private class StartableTakesDependency : IStartable @@ -264,7 +270,10 @@ public StartableTakesDependency(IStartableDependency[] dependencies) { } - public bool WasStarted { get; private set; } + public bool WasStarted + { + get; private set; + } public void Start() { diff --git a/test/Autofac.Specification.Test/Lifetime/DisposalTests.cs b/test/Autofac.Specification.Test/Lifetime/DisposalTests.cs index c778f81e6..bb31c4928 100644 --- a/test/Autofac.Specification.Test/Lifetime/DisposalTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/DisposalTests.cs @@ -213,6 +213,9 @@ public B(A a) A = a; } - public A A { get; private set; } + public A A + { + get; private set; + } } } diff --git a/test/Autofac.Specification.Test/Lifetime/InstancePerMatchingLifetimeScopeTests.cs b/test/Autofac.Specification.Test/Lifetime/InstancePerMatchingLifetimeScopeTests.cs index 4b933638f..dbb8b6304 100644 --- a/test/Autofac.Specification.Test/Lifetime/InstancePerMatchingLifetimeScopeTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/InstancePerMatchingLifetimeScopeTests.cs @@ -27,16 +27,16 @@ public void ChildOfNamedScopeGetsSharedInstance() public void InstancePerRequest_AdditionalLifetimeScopeTagsCanBeProvided() { var builder = new ContainerBuilder(); - const string tag1 = "Tag1"; - const string tag2 = "Tag2"; - builder.Register(c => new object()).InstancePerRequest(tag1, tag2); + const string Tag1 = "Tag1"; + const string Tag2 = "Tag2"; + builder.Register(c => new object()).InstancePerRequest(Tag1, Tag2); var container = builder.Build(); - var scope1 = container.BeginLifetimeScope(tag1); + var scope1 = container.BeginLifetimeScope(Tag1); Assert.NotNull(scope1.Resolve()); - var scope2 = container.BeginLifetimeScope(tag2); + var scope2 = container.BeginLifetimeScope(Tag2); Assert.NotNull(scope2.Resolve()); var requestScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag); diff --git a/test/Autofac.Specification.Test/Lifetime/InstancePerOwnedTests.cs b/test/Autofac.Specification.Test/Lifetime/InstancePerOwnedTests.cs index f52d11929..7a410ab70 100644 --- a/test/Autofac.Specification.Test/Lifetime/InstancePerOwnedTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/InstancePerOwnedTests.cs @@ -44,11 +44,11 @@ public void InstancePerOwnedResolvesToOwnedScope_NonGenericMethodSignature() public void InstancePerOwnedWithKeyResolvesToOwnedScope_GenericMethodSignature() { var cb = new ContainerBuilder(); - const string serviceKey = "ServiceKey"; - cb.RegisterType().Keyed(serviceKey); - cb.RegisterType().InstancePerOwned(serviceKey); + const string ServiceKey = "ServiceKey"; + cb.RegisterType().Keyed(ServiceKey); + cb.RegisterType().InstancePerOwned(ServiceKey); var container = cb.Build(); - var owned = container.ResolveKeyed>(serviceKey); + var owned = container.ResolveKeyed>(ServiceKey); Assert.Same(owned.Value.LifetimeScope.Tag, owned.Value.DependentService.LifetimeScope.Tag); } @@ -56,11 +56,11 @@ public void InstancePerOwnedWithKeyResolvesToOwnedScope_GenericMethodSignature() public void InstancePerOwnedWithKeyResolvesToOwnedScope_NonGenericMethodSignature() { var cb = new ContainerBuilder(); - const string serviceKey = "ServiceKey"; - cb.RegisterType().Keyed(serviceKey); - cb.RegisterType().InstancePerOwned(serviceKey, typeof(MessageHandler)); + const string ServiceKey = "ServiceKey"; + cb.RegisterType().Keyed(ServiceKey); + cb.RegisterType().InstancePerOwned(ServiceKey, typeof(MessageHandler)); var container = cb.Build(); - var owned = container.ResolveKeyed>(serviceKey); + var owned = container.ResolveKeyed>(ServiceKey); Assert.Same(owned.Value.LifetimeScope.Tag, owned.Value.DependentService.LifetimeScope.Tag); } @@ -68,17 +68,17 @@ public void InstancePerOwnedWithKeyResolvesToOwnedScope_NonGenericMethodSignatur public void InstancePerOwnedWithoutKeysResolvesForOwnedServicesWithKeys() { var builder = new ContainerBuilder(); - const string serviceKeyA = "A"; - const string serviceKeyB = "B"; + const string ServiceKeyA = "A"; + const string ServiceKeyB = "B"; builder.RegisterType().AsSelf().InstancePerOwned(); - builder.RegisterType().Keyed(serviceKeyA); - builder.RegisterType().Keyed(serviceKeyB); + builder.RegisterType().Keyed(ServiceKeyA); + builder.RegisterType().Keyed(ServiceKeyB); var container = builder.Build(); - var ownedRoot = container.ResolveKeyed>(serviceKeyA); + var ownedRoot = container.ResolveKeyed>(ServiceKeyA); Assert.NotNull(ownedRoot.Value.Dependency); - ownedRoot = container.ResolveKeyed>(serviceKeyB); + ownedRoot = container.ResolveKeyed>(ServiceKeyB); Assert.NotNull(ownedRoot.Value.Dependency); } @@ -86,17 +86,17 @@ public void InstancePerOwnedWithoutKeysResolvesForOwnedServicesWithKeys() public void InstancePerOwnedWithMultipleKeysResolvesForOwnedServicesWithMatchingKeys() { var builder = new ContainerBuilder(); - const string serviceKeyA = "A"; - const string serviceKeyB = "B"; - builder.RegisterType().AsSelf().InstancePerOwned(serviceKeyA, serviceKeyB); - builder.RegisterType().Keyed(serviceKeyA); - builder.RegisterType().Keyed(serviceKeyB); + const string ServiceKeyA = "A"; + const string ServiceKeyB = "B"; + builder.RegisterType().AsSelf().InstancePerOwned(ServiceKeyA, ServiceKeyB); + builder.RegisterType().Keyed(ServiceKeyA); + builder.RegisterType().Keyed(ServiceKeyB); var container = builder.Build(); - var ownedRoot = container.ResolveKeyed>(serviceKeyA); + var ownedRoot = container.ResolveKeyed>(ServiceKeyA); Assert.NotNull(ownedRoot.Value.Dependency); - ownedRoot = container.ResolveKeyed>(serviceKeyB); + ownedRoot = container.ResolveKeyed>(ServiceKeyB); Assert.NotNull(ownedRoot.Value.Dependency); } @@ -104,17 +104,17 @@ public void InstancePerOwnedWithMultipleKeysResolvesForOwnedServicesWithMatching public void InstancePerOwnedThrowsWhenKeyMissingForOwnedServiceWithKey() { var builder = new ContainerBuilder(); - const string serviceKeyA = "A"; - const string serviceKeyB = "B"; - builder.RegisterType().AsSelf().InstancePerOwned(serviceKeyA); - builder.RegisterType().Keyed(serviceKeyA); - builder.RegisterType().Keyed(serviceKeyB); + const string ServiceKeyA = "A"; + const string ServiceKeyB = "B"; + builder.RegisterType().AsSelf().InstancePerOwned(ServiceKeyA); + builder.RegisterType().Keyed(ServiceKeyA); + builder.RegisterType().Keyed(ServiceKeyB); var container = builder.Build(); - var ownedRoot = container.ResolveKeyed>(serviceKeyA); + var ownedRoot = container.ResolveKeyed>(ServiceKeyA); Assert.NotNull(ownedRoot.Value.Dependency); - void Resolve() => container.ResolveKeyed>(serviceKeyB); + void Resolve() => container.ResolveKeyed>(ServiceKeyB); Assert.Throws(Resolve); } @@ -122,8 +122,8 @@ public void InstancePerOwnedThrowsWhenKeyMissingForOwnedServiceWithKey() public void InstancePerOwnedWithKeyThrowsWhenOwnedServiceHasNoKey() { var builder = new ContainerBuilder(); - const string serviceKey = "A"; - builder.RegisterType().AsSelf().InstancePerOwned(serviceKey); + const string ServiceKey = "A"; + builder.RegisterType().AsSelf().InstancePerOwned(ServiceKey); builder.RegisterType().As(); var container = builder.Build(); @@ -139,9 +139,15 @@ public MessageHandler(ILifetimeScope lifetimeScope, ServiceForHandler service) LifetimeScope = lifetimeScope; } - public ServiceForHandler DependentService { get; set; } + public ServiceForHandler DependentService + { + get; set; + } - public ILifetimeScope LifetimeScope { get; set; } + public ILifetimeScope LifetimeScope + { + get; set; + } } private class ServiceForHandler @@ -151,7 +157,10 @@ public ServiceForHandler(ILifetimeScope lifetimeScope) LifetimeScope = lifetimeScope; } - public ILifetimeScope LifetimeScope { get; set; } + public ILifetimeScope LifetimeScope + { + get; set; + } } private class Service @@ -160,7 +169,10 @@ private class Service private interface IRoot { - Service Dependency { get; } + Service Dependency + { + get; + } } private class RootA : IRoot @@ -170,7 +182,10 @@ public RootA(Service dependency) Dependency = dependency; } - public Service Dependency { get; } + public Service Dependency + { + get; + } } private class RootB : IRoot @@ -180,6 +195,9 @@ public RootB(Service dependency) Dependency = dependency; } - public Service Dependency { get; } + public Service Dependency + { + get; + } } } diff --git a/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs b/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs index e21bd1317..6a938ba13 100644 --- a/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs @@ -12,40 +12,40 @@ public class LifetimeEventTests [Fact] public void ActivatedAllowsMethodInjection() { - var pval = 12; + var pVal = 12; var builder = new ContainerBuilder(); builder.RegisterType() .InstancePerLifetimeScope() - .OnActivated(e => e.Instance.Method(pval)); + .OnActivated(e => e.Instance.Method(pVal)); var container = builder.Build(); var scope = container.BeginLifetimeScope(); var invokee = scope.Resolve(); - Assert.Equal(pval, invokee.Param); + Assert.Equal(pVal, invokee.Param); } [Fact] public void ActivatedAllowsTaskReturningHandler() { - var pval = 12; + var pVal = 12; var builder = new ContainerBuilder(); builder.RegisterType() .InstancePerLifetimeScope() .OnActivated(async e => { await Task.Delay(1); - e.Instance.Method(pval); + e.Instance.Method(pVal); }); var container = builder.Build(); var scope = container.BeginLifetimeScope(); var invokee = scope.Resolve(); - Assert.Equal(pval, invokee.Param); + Assert.Equal(pVal, invokee.Param); } [Fact] public void ActivatedCanReceiveParameters() { - const int provided = 12; + const int Provided = 12; var passed = 0; var builder = new ContainerBuilder(); @@ -53,14 +53,14 @@ public void ActivatedCanReceiveParameters() .OnActivated(e => passed = e.Parameters.TypedAs()); var container = builder.Build(); - container.Resolve(TypedParameter.From(provided)); - Assert.Equal(provided, passed); + container.Resolve(TypedParameter.From(Provided)); + Assert.Equal(Provided, passed); } [Fact] public void ActivatingCanReceiveParameters() { - const int provided = 12; + const int Provided = 12; var passed = 0; var builder = new ContainerBuilder(); @@ -68,8 +68,8 @@ public void ActivatingCanReceiveParameters() .OnActivating(e => passed = e.Parameters.TypedAs()); var container = builder.Build(); - container.Resolve(TypedParameter.From(provided)); - Assert.Equal(provided, passed); + container.Resolve(TypedParameter.From(Provided)); + Assert.Equal(Provided, passed); } [Fact] @@ -611,7 +611,10 @@ private class BService : IService private class ReleasingClass : IReleasingService { - public bool Released { get; set; } + public bool Released + { + get; set; + } public void Release() { @@ -625,7 +628,10 @@ private interface IReleasingService private class MethodInjection { - public int Param { get; private set; } + public int Param + { + get; private set; + } public void Method(int param) { diff --git a/test/Autofac.Specification.Test/Lifetime/NestedScopeTests.cs b/test/Autofac.Specification.Test/Lifetime/NestedScopeTests.cs index 5e5668a80..f1318e48b 100644 --- a/test/Autofac.Specification.Test/Lifetime/NestedScopeTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/NestedScopeTests.cs @@ -15,11 +15,11 @@ public class NestedScopeTests public void BeginLifetimeScopeCannotBeCalledWithDuplicateTag() { var rootScope = new ContainerBuilder().Build(); - const string duplicateTagName = "ABC"; - var taggedScope = rootScope.BeginLifetimeScope(duplicateTagName); + const string DuplicateTagName = "ABC"; + var taggedScope = rootScope.BeginLifetimeScope(DuplicateTagName); var differentTaggedScope = taggedScope.BeginLifetimeScope("DEF"); - Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName)); - Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName, builder => builder.RegisterType())); + Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(DuplicateTagName)); + Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(DuplicateTagName, builder => builder.RegisterType())); } } diff --git a/test/Autofac.Specification.Test/LoadContextScopeTests.cs b/test/Autofac.Specification.Test/LoadContextScopeTests.cs index 0f05a9bfa..2bcb7233d 100644 --- a/test/Autofac.Specification.Test/LoadContextScopeTests.cs +++ b/test/Autofac.Specification.Test/LoadContextScopeTests.cs @@ -93,7 +93,7 @@ public void CanLoadInstanceOfAssemblyAndUnloadItAfterLifetimeScopeEndingInModule using var rootContainer = builder.Build(); - bool callbackInvoked = false; + var callbackInvoked = false; LoadAssemblyAndTest( rootContainer, diff --git a/test/Autofac.Specification.Test/Registration/Adapters/IToolbarButton.cs b/test/Autofac.Specification.Test/Registration/Adapters/IToolbarButton.cs index bbd45ee8e..9f3b68c1e 100644 --- a/test/Autofac.Specification.Test/Registration/Adapters/IToolbarButton.cs +++ b/test/Autofac.Specification.Test/Registration/Adapters/IToolbarButton.cs @@ -5,7 +5,13 @@ namespace Autofac.Specification.Test.Registration.Adapters; public interface IToolbarButton { - string Name { get; } + string Name + { + get; + } - Command Command { get; } + Command Command + { + get; + } } diff --git a/test/Autofac.Specification.Test/Registration/Adapters/ToolbarButton.cs b/test/Autofac.Specification.Test/Registration/Adapters/ToolbarButton.cs index f193dd5cd..59947d639 100644 --- a/test/Autofac.Specification.Test/Registration/Adapters/ToolbarButton.cs +++ b/test/Autofac.Specification.Test/Registration/Adapters/ToolbarButton.cs @@ -11,7 +11,13 @@ public ToolbarButton(Command command, string name = "") Name = name; } - public string Name { get; } + public string Name + { + get; + } - public Command Command { get; } + public Command Command + { + get; + } } diff --git a/test/Autofac.Specification.Test/Registration/AssemblyScanningTests.cs b/test/Autofac.Specification.Test/Registration/AssemblyScanningTests.cs index 015daa7b3..f06f153bf 100644 --- a/test/Autofac.Specification.Test/Registration/AssemblyScanningTests.cs +++ b/test/Autofac.Specification.Test/Registration/AssemblyScanningTests.cs @@ -19,7 +19,7 @@ public void OnlyServicesAssignableToASpecificTypeAreRegisteredFromAssemblies() .AssignableTo(typeof(IMyService))); Assert.Single(container.ComponentRegistry.Registrations); - Assert.True(container.TryResolve(typeof(MyComponent), out object obj)); + Assert.True(container.TryResolve(typeof(MyComponent), out var obj)); Assert.False(container.TryResolve(typeof(MyComponent2), out obj)); } diff --git a/test/Autofac.Specification.Test/Registration/KeyedRegistrationTests.cs b/test/Autofac.Specification.Test/Registration/KeyedRegistrationTests.cs index e5f73a3ac..49ec26b1d 100644 --- a/test/Autofac.Specification.Test/Registration/KeyedRegistrationTests.cs +++ b/test/Autofac.Specification.Test/Registration/KeyedRegistrationTests.cs @@ -15,7 +15,7 @@ public void TypeRegisteredWithKey() var c = cb.Build(); - Assert.True(c.TryResolveKeyed(key, typeof(object), out object o1)); + Assert.True(c.TryResolveKeyed(key, typeof(object), out var o1)); Assert.NotNull(o1); Assert.False(c.TryResolve(typeof(object), out _)); } @@ -30,7 +30,7 @@ public void TypeRegisteredWithName() var c = cb.Build(); - Assert.True(c.TryResolveNamed(name, typeof(object), out object o1)); + Assert.True(c.TryResolveNamed(name, typeof(object), out var o1)); Assert.NotNull(o1); Assert.False(c.TryResolve(typeof(object), out _)); } diff --git a/test/Autofac.Specification.Test/Registration/LambdaGenericOverloadRegistrationTests.cs b/test/Autofac.Specification.Test/Registration/LambdaGenericOverloadRegistrationTests.cs index e65285623..68fafc790 100644 --- a/test/Autofac.Specification.Test/Registration/LambdaGenericOverloadRegistrationTests.cs +++ b/test/Autofac.Specification.Test/Registration/LambdaGenericOverloadRegistrationTests.cs @@ -101,12 +101,18 @@ public MyComponentWithParams(MyDep1 dep1, string arg1, string arg2) Arg2 = arg2; } - public string Arg1 { get; } + public string Arg1 + { + get; + } - public string Arg2 { get; } + public string Arg2 + { + get; + } } - private static readonly Type[] AllDeps = new[] + private static readonly Type[] _allDeps = new[] { typeof(MyDep1), typeof(MyDep2), @@ -124,7 +130,7 @@ private ContainerBuilder GetBuilderWithDeps() { var builder = new ContainerBuilder(); - builder.RegisterTypes(AllDeps); + builder.RegisterTypes(_allDeps); return builder; } @@ -580,9 +586,9 @@ static bool MethodDelegateFuncHasIComponentContext(MethodInfo method) public static IEnumerable GetGenericOverloadTypeSets() { // Return a set of type arrays, each one with an additional type in the set. - for (var idx = 0; idx < AllDeps.Length; idx++) + for (var idx = 0; idx < _allDeps.Length; idx++) { - yield return new[] { AllDeps.Take(idx + 1).ToArray() }; + yield return new[] { _allDeps.Take(idx + 1).ToArray() }; } } } diff --git a/test/Autofac.Specification.Test/Registration/ModuleRegistrationTests.cs b/test/Autofac.Specification.Test/Registration/ModuleRegistrationTests.cs index 44054a608..690d1fb16 100644 --- a/test/Autofac.Specification.Test/Registration/ModuleRegistrationTests.cs +++ b/test/Autofac.Specification.Test/Registration/ModuleRegistrationTests.cs @@ -294,7 +294,10 @@ public Composite1(IEnumerable instance) internal class ObjectModule : Module { - public bool ConfigureCalled { get; private set; } + public bool ConfigureCalled + { + get; private set; + } protected override void Load(ContainerBuilder builder) { @@ -310,7 +313,10 @@ protected override void Load(ContainerBuilder builder) internal class StringModule : Module { - public bool ConfigureCalled { get; private set; } + public bool ConfigureCalled + { + get; private set; + } protected override void Load(ContainerBuilder builder) { diff --git a/test/Autofac.Specification.Test/Registration/ParameterTests.cs b/test/Autofac.Specification.Test/Registration/ParameterTests.cs index d36b1080b..5dcdeef62 100644 --- a/test/Autofac.Specification.Test/Registration/ParameterTests.cs +++ b/test/Autofac.Specification.Test/Registration/ParameterTests.cs @@ -27,6 +27,9 @@ public WithParam(int i, int j) Value = i + j; } - public int Value { get; private set; } + public int Value + { + get; private set; + } } } diff --git a/test/Autofac.Specification.Test/Registration/RegistrationOnlyIfTests.cs b/test/Autofac.Specification.Test/Registration/RegistrationOnlyIfTests.cs index 1df06ba0d..576b84f2e 100644 --- a/test/Autofac.Specification.Test/Registration/RegistrationOnlyIfTests.cs +++ b/test/Autofac.Specification.Test/Registration/RegistrationOnlyIfTests.cs @@ -151,8 +151,8 @@ public void IfNotRegistered_EvaluatesServiceMiddleware_WithDescriptor() builder.RegisterType().As().IfNotRegistered(typeof(IService)); - const string descriptor = "custom-middleware"; - builder.RegisterServiceMiddleware(typeof(IService), descriptor, PipelinePhase.ResolveRequestStart, (context, next) => + const string Descriptor = "custom-middleware"; + builder.RegisterServiceMiddleware(typeof(IService), Descriptor, PipelinePhase.ResolveRequestStart, (context, next) => { next(context); middlewareInvoked = true; @@ -319,7 +319,10 @@ public Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } private class Decorator : IService @@ -329,7 +332,10 @@ public Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } private class ServiceA : IService diff --git a/test/Autofac.Specification.Test/Registration/TypeRegistrationTests.cs b/test/Autofac.Specification.Test/Registration/TypeRegistrationTests.cs index 4fd021c2c..1ebb95421 100644 --- a/test/Autofac.Specification.Test/Registration/TypeRegistrationTests.cs +++ b/test/Autofac.Specification.Test/Registration/TypeRegistrationTests.cs @@ -38,7 +38,10 @@ public MyValueType(IMyService service) Service = service; } - public IMyService Service { get; } + public IMyService Service + { + get; + } } [Fact] @@ -146,7 +149,7 @@ public void RegisterTypesCanBeFilteredByAssignableTo() .AssignableTo(typeof(IMyService))); Assert.Single(container.ComponentRegistry.Registrations); - Assert.True(container.TryResolve(typeof(MyComponent), out object obj)); + Assert.True(container.TryResolve(typeof(MyComponent), out var obj)); Assert.False(container.TryResolve(typeof(MyComponent2), out obj)); } @@ -164,8 +167,8 @@ public void RegisterTypesIgnoresNonRegisterableTypes() typeof(MyComponent))); Assert.Equal(2, container.ComponentRegistry.Registrations.Count()); - Assert.True(container.TryResolve(typeof(MyComponent), out object _)); - Assert.True(container.TryResolve(typeof(MyOpenGeneric), out object _)); + Assert.True(container.TryResolve(typeof(MyComponent), out var _)); + Assert.True(container.TryResolve(typeof(MyOpenGeneric), out var _)); Assert.False(container.TryResolve(typeof(IMyService), out _)); Assert.False(container.TryResolve(typeof(MyDelegateType), out _)); Assert.False(container.TryResolve(typeof(MyAbstractClass), out _)); @@ -179,7 +182,7 @@ public void RegisterTypesIgnoresNullValues() b.RegisterTypes(null, typeof(MyComponent), null)); Assert.Single(container.ComponentRegistry.Registrations); - Assert.True(container.TryResolve(typeof(MyComponent), out object _)); + Assert.True(container.TryResolve(typeof(MyComponent), out var _)); } [Fact] diff --git a/test/Autofac.Specification.Test/Resolution/ConstructorFinderTests.cs b/test/Autofac.Specification.Test/Resolution/ConstructorFinderTests.cs index 14eccfd3d..994e0f049 100644 --- a/test/Autofac.Specification.Test/Resolution/ConstructorFinderTests.cs +++ b/test/Autofac.Specification.Test/Resolution/ConstructorFinderTests.cs @@ -116,7 +116,10 @@ private class A2 private class CustomConstructorFinder : IConstructorFinder { - public bool FindConstructorsCalled { get; private set; } + public bool FindConstructorsCalled + { + get; private set; + } public ConstructorInfo[] FindConstructors(Type targetType) { @@ -142,7 +145,10 @@ public MultipleConstructors(A1 a1, A2 a2, string s1) CalledCtor = 3; } - public int CalledCtor { get; private set; } + public int CalledCtor + { + get; private set; + } } private class PrivateConstructor @@ -152,6 +158,9 @@ private PrivateConstructor(A1 a1) A1 = a1; } - public A1 A1 { get; set; } + public A1 A1 + { + get; set; + } } } diff --git a/test/Autofac.Specification.Test/Resolution/ConstructorSelectorTests.cs b/test/Autofac.Specification.Test/Resolution/ConstructorSelectorTests.cs index 24d245e90..42fb9495c 100644 --- a/test/Autofac.Specification.Test/Resolution/ConstructorSelectorTests.cs +++ b/test/Autofac.Specification.Test/Resolution/ConstructorSelectorTests.cs @@ -100,6 +100,9 @@ public MultipleConstructors(A1 a1, A2 a2, string s1) CalledCtor = 3; } - public int CalledCtor { get; private set; } + public int CalledCtor + { + get; private set; + } } } diff --git a/test/Autofac.Specification.Test/Resolution/Graph1/B1.cs b/test/Autofac.Specification.Test/Resolution/Graph1/B1.cs index f529e33e8..f33724006 100644 --- a/test/Autofac.Specification.Test/Resolution/Graph1/B1.cs +++ b/test/Autofac.Specification.Test/Resolution/Graph1/B1.cs @@ -14,5 +14,8 @@ public B1(A1 a) A = a; } - public A1 A { get; private set; } + public A1 A + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Resolution/Graph1/C1.cs b/test/Autofac.Specification.Test/Resolution/Graph1/C1.cs index 264c1a9aa..b2cbd8d8c 100644 --- a/test/Autofac.Specification.Test/Resolution/Graph1/C1.cs +++ b/test/Autofac.Specification.Test/Resolution/Graph1/C1.cs @@ -14,5 +14,8 @@ public C1(B1 b) B = b; } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Resolution/Graph1/CD1.cs b/test/Autofac.Specification.Test/Resolution/Graph1/CD1.cs index 9f390a1e0..63b5b694a 100644 --- a/test/Autofac.Specification.Test/Resolution/Graph1/CD1.cs +++ b/test/Autofac.Specification.Test/Resolution/Graph1/CD1.cs @@ -15,7 +15,13 @@ public CD1(A1 a, B1 b) B = b; } - public A1 A { get; private set; } + public A1 A + { + get; private set; + } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Resolution/Graph1/E1.cs b/test/Autofac.Specification.Test/Resolution/Graph1/E1.cs index ef42f702a..9e5becb7a 100644 --- a/test/Autofac.Specification.Test/Resolution/Graph1/E1.cs +++ b/test/Autofac.Specification.Test/Resolution/Graph1/E1.cs @@ -15,7 +15,13 @@ public E1(B1 b, IC1 c) C = c; } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } - public IC1 C { get; private set; } + public IC1 C + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Resolution/Graph1/F1.cs b/test/Autofac.Specification.Test/Resolution/Graph1/F1.cs index 40f4dfc27..f9a4c59bf 100644 --- a/test/Autofac.Specification.Test/Resolution/Graph1/F1.cs +++ b/test/Autofac.Specification.Test/Resolution/Graph1/F1.cs @@ -12,5 +12,8 @@ public F1(IList aList) AList = aList; } - public IList AList { get; private set; } + public IList AList + { + get; private set; + } } diff --git a/test/Autofac.Specification.Test/Util/AsyncOnlyDisposeTracker.cs b/test/Autofac.Specification.Test/Util/AsyncOnlyDisposeTracker.cs index 311611ec0..4f6eb04bc 100644 --- a/test/Autofac.Specification.Test/Util/AsyncOnlyDisposeTracker.cs +++ b/test/Autofac.Specification.Test/Util/AsyncOnlyDisposeTracker.cs @@ -14,7 +14,10 @@ public AsyncOnlyDisposeTracker(bool completeAsync = false) public event EventHandler Disposing; - public bool IsAsyncDisposed { get; set; } + public bool IsAsyncDisposed + { + get; set; + } public async ValueTask DisposeAsync() { diff --git a/test/Autofac.Specification.Test/Util/DisposeTracker.cs b/test/Autofac.Specification.Test/Util/DisposeTracker.cs index 90c608463..6d5494cd2 100644 --- a/test/Autofac.Specification.Test/Util/DisposeTracker.cs +++ b/test/Autofac.Specification.Test/Util/DisposeTracker.cs @@ -7,7 +7,10 @@ public class DisposeTracker : IDisposable { public event EventHandler Disposing; - public bool IsDisposed { get; set; } + public bool IsDisposed + { + get; set; + } protected virtual void Dispose(bool disposing) { diff --git a/test/Autofac.Test.Compilation/AutofacCompile.cs b/test/Autofac.Test.Compilation/AutofacCompile.cs index 9e242669b..2b5ab116f 100644 --- a/test/Autofac.Test.Compilation/AutofacCompile.cs +++ b/test/Autofac.Test.Compilation/AutofacCompile.cs @@ -63,7 +63,7 @@ public AutofacCompile AssertNoWarnings() return this; } - private static readonly CSharpCompilationOptions DefaultCompilationOptions = + private static readonly CSharpCompilationOptions _defaultCompilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) .WithNullableContextOptions(NullableContextOptions.Enable); @@ -73,7 +73,7 @@ protected IEnumerable GetMessages() var syntaxTree = SyntaxFactory.ParseSyntaxTree(Render(), parseOptions); - var compilation = CSharpCompilation.Create("test.dll", new[] { syntaxTree }, _references, DefaultCompilationOptions); + var compilation = CSharpCompilation.Create("test.dll", new[] { syntaxTree }, _references, _defaultCompilationOptions); return compilation.GetDiagnostics(); } diff --git a/test/Autofac.Test.Scenarios.LoadContext/Service1.cs b/test/Autofac.Test.Scenarios.LoadContext/Service1.cs index ca5187b69..e6683c480 100644 --- a/test/Autofac.Test.Scenarios.LoadContext/Service1.cs +++ b/test/Autofac.Test.Scenarios.LoadContext/Service1.cs @@ -5,5 +5,8 @@ namespace A; public class Service1 { - public int Value { get; set; } + public int Value + { + get; set; + } } diff --git a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/DuplicatedNameAttribute.cs b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/DuplicatedNameAttribute.cs index 2c6c9cf98..0d56b4795 100644 --- a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/DuplicatedNameAttribute.cs +++ b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/DuplicatedNameAttribute.cs @@ -12,6 +12,9 @@ public DuplicatedNameAttribute(string name) Name = name ?? throw new ArgumentNullException("name"); } - public string Name { get; } + public string Name + { + get; + } } } diff --git a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/IHaveName.cs b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/IHaveName.cs index 31c6ddf37..62151ac7b 100644 --- a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/IHaveName.cs +++ b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/IHaveName.cs @@ -5,6 +5,9 @@ namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenar { public interface IHaveName { - string Name { get; } + string Name + { + get; + } } } diff --git a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/NameAttribute.cs b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/NameAttribute.cs index cbd5d5e70..19c982624 100644 --- a/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/NameAttribute.cs +++ b/test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/NameAttribute.cs @@ -12,6 +12,9 @@ public NameAttribute(string name) Name = name ?? throw new ArgumentNullException("name"); } - public string Name { get; } + public string Name + { + get; + } } } diff --git a/test/Autofac.Test/Builder/DelegateRegistrationBuilderTests.cs b/test/Autofac.Test/Builder/DelegateRegistrationBuilderTests.cs index 3025faf53..bfaeb19bc 100644 --- a/test/Autofac.Test/Builder/DelegateRegistrationBuilderTests.cs +++ b/test/Autofac.Test/Builder/DelegateRegistrationBuilderTests.cs @@ -21,7 +21,7 @@ public void ExposesImplementationType() cb.Register(c => "Hello").As(); var container = cb.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration( - new TypedService(typeof(object)), out IComponentRegistration cr)); + new TypedService(typeof(object)), out var cr)); Assert.Equal(typeof(string), cr.Activator.LimitType); } } diff --git a/test/Autofac.Test/Builder/PropertyInjectionTests.cs b/test/Autofac.Test/Builder/PropertyInjectionTests.cs index e4ac7bba8..e2eace7e2 100644 --- a/test/Autofac.Test/Builder/PropertyInjectionTests.cs +++ b/test/Autofac.Test/Builder/PropertyInjectionTests.cs @@ -113,7 +113,10 @@ public HasNullableValueTypeArray() } [SuppressMessage("CA1819", "CA1819", Justification = "Handles specific test case of an array property.")] - public double?[] DoubleArray { get; set; } + public double?[] DoubleArray + { + get; set; + } } private class HasNullableValueTypeCollection @@ -124,9 +127,15 @@ public HasNullableValueTypeCollection() DoubleCollectionInterface = DoubleCollection; } - public ReadOnlyCollection DoubleCollection { get; set; } + public ReadOnlyCollection DoubleCollection + { + get; set; + } - public IReadOnlyCollection DoubleCollectionInterface { get; set; } + public IReadOnlyCollection DoubleCollectionInterface + { + get; set; + } } private class HasNullableValueTypeList @@ -137,9 +146,15 @@ public HasNullableValueTypeList() DoubleListInterface = DoubleList; } - public List DoubleList { get; set; } + public List DoubleList + { + get; set; + } - public IList DoubleListInterface { get; set; } + public IList DoubleListInterface + { + get; set; + } } private class HasValueTypeArray @@ -149,7 +164,10 @@ public HasValueTypeArray() ByteArray = new byte[] { 1, 2, 3 }; } - public byte[] ByteArray { get; set; } + public byte[] ByteArray + { + get; set; + } } private class HasValueTypeCollection @@ -160,9 +178,15 @@ public HasValueTypeCollection() ByteCollectionInterface = ByteCollection; } - public Collection ByteCollection { get; set; } + public Collection ByteCollection + { + get; set; + } - public ICollection ByteCollectionInterface { get; set; } + public ICollection ByteCollectionInterface + { + get; set; + } } private class HasValueTypeList @@ -173,8 +197,14 @@ public HasValueTypeList() ByteListInterface = ByteList; } - public List ByteList { get; set; } + public List ByteList + { + get; set; + } - public IList ByteListInterface { get; set; } + public IList ByteListInterface + { + get; set; + } } } diff --git a/test/Autofac.Test/Builder/ProvidedInstanceRegistrationBuilderTests.cs b/test/Autofac.Test/Builder/ProvidedInstanceRegistrationBuilderTests.cs index 03612e5fe..771390726 100644 --- a/test/Autofac.Test/Builder/ProvidedInstanceRegistrationBuilderTests.cs +++ b/test/Autofac.Test/Builder/ProvidedInstanceRegistrationBuilderTests.cs @@ -14,7 +14,7 @@ public void LimitType_ExposesImplementationType() cb.RegisterInstance("Hello").As(); var container = cb.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration( - new TypedService(typeof(object)), out IComponentRegistration cr)); + new TypedService(typeof(object)), out var cr)); Assert.Equal(typeof(string), cr.Activator.LimitType); } diff --git a/test/Autofac.Test/Builder/ReflectiveRegistrationBuilderTests.cs b/test/Autofac.Test/Builder/ReflectiveRegistrationBuilderTests.cs index b9f6d9059..72f7412d3 100644 --- a/test/Autofac.Test/Builder/ReflectiveRegistrationBuilderTests.cs +++ b/test/Autofac.Test/Builder/ReflectiveRegistrationBuilderTests.cs @@ -16,7 +16,7 @@ public void ExposesImplementationType() var cb = new ContainerBuilder(); cb.RegisterType(typeof(A1)).As(); var container = cb.Build(); - Assert.True(container.ComponentRegistry.TryGetRegistration(new TypedService(typeof(object)), out IComponentRegistration cr)); + Assert.True(container.ComponentRegistry.TryGetRegistration(new TypedService(typeof(object)), out var cr)); Assert.Equal(typeof(A1), cr.Activator.LimitType); } @@ -101,6 +101,9 @@ public MultipleConstructors(A1 a1, A2 a2, string s1) CalledCtor = 3; } - public int CalledCtor { get; private set; } + public int CalledCtor + { + get; private set; + } } } diff --git a/test/Autofac.Test/Builder/RegistrationBuilderTests.cs b/test/Autofac.Test/Builder/RegistrationBuilderTests.cs index eac891695..e569e8c8a 100644 --- a/test/Autofac.Test/Builder/RegistrationBuilderTests.cs +++ b/test/Autofac.Test/Builder/RegistrationBuilderTests.cs @@ -10,9 +10,15 @@ public class RegistrationBuilderTests { internal class TestMetadata { - public int A { get; set; } - - public string B { get; set; } + public int A + { + get; set; + } + + public string B + { + get; set; + } } [Fact] diff --git a/test/Autofac.Test/ContainerBuilderTests.cs b/test/Autofac.Test/ContainerBuilderTests.cs index b690965cc..08be4132b 100644 --- a/test/Autofac.Test/ContainerBuilderTests.cs +++ b/test/Autofac.Test/ContainerBuilderTests.cs @@ -64,7 +64,7 @@ public void WhenComponentIsRegisteredDuringResolveItShouldRaiseTheRegisteredEven builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)); builder.RegisterType().PropertiesAutowired(); - IContainer container = builder.Build(); + var container = builder.Build(); var controller = container.Resolve(); controller.UseTheRepository(); @@ -82,7 +82,10 @@ private class Repository : IRepository private class Controller { - public Lazy> TheRepository { get; set; } + public Lazy> TheRepository + { + get; set; + } public void UseTheRepository() { diff --git a/test/Autofac.Test/Core/Activators/Reflection/ConstructorBinderTests.cs b/test/Autofac.Test/Core/Activators/Reflection/ConstructorBinderTests.cs index bb088ccca..727c37d5c 100644 --- a/test/Autofac.Test/Core/Activators/Reflection/ConstructorBinderTests.cs +++ b/test/Autofac.Test/Core/Activators/Reflection/ConstructorBinderTests.cs @@ -28,7 +28,10 @@ public ServiceWithInParameter(in int input) private class CtorWithDoubleParam { - public double Value { get; } + public double Value + { + get; + } public CtorWithDoubleParam(double value) { @@ -44,7 +47,10 @@ public enum Foo private class CtorWithInt { - public int Value { get; } + public int Value + { + get; + } public CtorWithInt(int value) { diff --git a/test/Autofac.Test/Core/Activators/Reflection/DefaultValueParameterTests.cs b/test/Autofac.Test/Core/Activators/Reflection/DefaultValueParameterTests.cs index 3bdc422c2..0bd639cae 100644 --- a/test/Autofac.Test/Core/Activators/Reflection/DefaultValueParameterTests.cs +++ b/test/Autofac.Test/Core/Activators/Reflection/DefaultValueParameterTests.cs @@ -50,7 +50,7 @@ public void DoesNotProvideValueWhenNoDefaultAvailable() { var dvp = new DefaultValueParameter(); var dp = GetTestParameter("s").DefaultValue; - Assert.False(dvp.CanSupplyValue(GetTestParameter("s"), new ContainerBuilder().Build(), out Func vp)); + Assert.False(dvp.CanSupplyValue(GetTestParameter("s"), new ContainerBuilder().Build(), out var vp)); } [Fact] @@ -59,7 +59,7 @@ public void ProvidesValueWhenDefaultInitialiserPresent() var dvp = new DefaultValueParameter(); var u = GetTestParameter("t"); var dp = u.DefaultValue; - Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out Func vp)); + Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out var vp)); Assert.Equal("Hello", vp()); } @@ -68,7 +68,7 @@ public void ProvidesValueWhenDefaultDateTime() { var dvp = new DefaultValueParameter(); var u = GetTestParameter("guid"); - Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out Func vp)); + Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out var vp)); Assert.Equal(default(Guid), vp()); } @@ -77,7 +77,7 @@ public void ProvidesValueWhenDefaultStructure() { var dvp = new DefaultValueParameter(); var u = GetTestParameter("dt"); - Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out Func vp)); + Assert.True(dvp.CanSupplyValue(u, new ContainerBuilder().Build(), out var vp)); Assert.Equal(default(DateTime), vp()); } @@ -86,7 +86,7 @@ public void DoesNotProvideValueWhenNoDefaultAvailableInDynamicAssembly() { var dvp = new DefaultValueParameter(); - Assert.False(dvp.CanSupplyValue(GetDynamicBuildParameter(0), new ContainerBuilder().Build(), out Func vp)); + Assert.False(dvp.CanSupplyValue(GetDynamicBuildParameter(0), new ContainerBuilder().Build(), out var vp)); } [Fact] @@ -94,7 +94,7 @@ public void ProvidesValueWhenDefaultInitialiserPresentInDynamicAssembly() { var dvp = new DefaultValueParameter(); - Assert.True(dvp.CanSupplyValue(GetDynamicBuildParameter(1), new ContainerBuilder().Build(), out Func vp)); + Assert.True(dvp.CanSupplyValue(GetDynamicBuildParameter(1), new ContainerBuilder().Build(), out var vp)); Assert.Equal("Hello", vp()); } @@ -103,6 +103,6 @@ public void DoesNotProvideValueInDynamicMethod() { var dvp = new DefaultValueParameter(); - Assert.False(dvp.CanSupplyValue(GetDynamicMethodParameter(), new ContainerBuilder().Build(), out Func vp)); + Assert.False(dvp.CanSupplyValue(GetDynamicMethodParameter(), new ContainerBuilder().Build(), out var vp)); } } diff --git a/test/Autofac.Test/Core/Activators/Reflection/ReflectionActivatorTests.cs b/test/Autofac.Test/Core/Activators/Reflection/ReflectionActivatorTests.cs index 46212f78d..fe70821d6 100644 --- a/test/Autofac.Test/Core/Activators/Reflection/ReflectionActivatorTests.cs +++ b/test/Autofac.Test/Core/Activators/Reflection/ReflectionActivatorTests.cs @@ -30,11 +30,11 @@ public void Pipeline_DependenciesNotAvailable_ThrowsException() public void Pipeline_ResolvesConstructorDependencies() { var o = new object(); - const string s = "s"; + const string S = "s"; var builder = new ContainerBuilder(); builder.RegisterInstance(o); - builder.RegisterInstance(s); + builder.RegisterInstance(S); var container = builder.Build(); using var target = Factory.CreateReflectionActivator(typeof(Dependent)); @@ -47,7 +47,7 @@ public void Pipeline_ResolvesConstructorDependencies() var dependent = (Dependent)instance; Assert.Same(o, dependent.TheObject); - Assert.Same(s, dependent.TheString); + Assert.Same(S, dependent.TheString); } [Fact] @@ -78,7 +78,7 @@ public void ByDefault_ChoosesConstructorWithMostResolvableParameters() } [Fact] - public void ByDefault_ChoosesMostParameterisedConstructor() + public void ByDefault_ChoosesMostParameterizedConstructor() { var parameters = new Parameter[] { @@ -220,12 +220,12 @@ public void ProvidedParameters_OverrideThoseInContext() [Fact] public void SetsMultipleConfiguredProperties() { - const int p1 = 1; - const int p2 = 2; + const int P1 = 1; + const int P2 = 2; var properties = new[] { - new NamedPropertyParameter("P1", p1), - new NamedPropertyParameter("P2", p2), + new NamedPropertyParameter("P1", P1), + new NamedPropertyParameter("P2", P2), }; using var target = Factory.CreateReflectionActivator(typeof(R), Enumerable.Empty(), properties); using var container = Factory.CreateEmptyContainer(); @@ -310,8 +310,8 @@ public void WhenValueTypeParameterIsSuppliedWithNull_TheDefaultForTheValueTypeIs [Fact] public void WhenValueTypeParameterSupplied_ItIsPassedToTheComponent() { - const int i = 42; - var parameters = new Parameter[] { new NamedParameter("i", i) }; + const int I = 42; + var parameters = new Parameter[] { new NamedParameter("i", I) }; using var target = Factory.CreateReflectionActivator(typeof(AcceptsIntParameter), parameters); @@ -325,7 +325,7 @@ public void WhenValueTypeParameterSupplied_ItIsPassedToTheComponent() var typedInstance = (AcceptsIntParameter)instance; - Assert.Equal(i, typedInstance.I); + Assert.Equal(I, typedInstance.I); } [Fact] @@ -373,7 +373,10 @@ public AcceptsIntParameter(int i) I = i; } - public int I { get; private set; } + public int I + { + get; private set; + } } private class AcceptsObjectParameter @@ -383,7 +386,10 @@ public AcceptsObjectParameter(object p) P = p; } - public object P { get; private set; } + public object P + { + get; private set; + } } private class InternalDefaultConstructor @@ -406,16 +412,28 @@ internal NoPublicConstructor() private class PrivateSetProperty { - public int GetProperty { get; private set; } + public int GetProperty + { + get; private set; + } - public int P { get; set; } + public int P + { + get; set; + } } private class R { - public int P1 { get; set; } + public int P1 + { + get; set; + } - public int P2 { get; set; } + public int P2 + { + get; set; + } } private class ThreeConstructors @@ -435,7 +453,10 @@ public ThreeConstructors(int i, string s) CalledConstructorParameterCount = 2; } - public int CalledConstructorParameterCount { get; private set; } + public int CalledConstructorParameterCount + { + get; private set; + } } private class WithGenericCtor diff --git a/test/Autofac.Test/Core/ContainerTests.cs b/test/Autofac.Test/Core/ContainerTests.cs index 6dc9b1e9a..d25d4200e 100644 --- a/test/Autofac.Test/Core/ContainerTests.cs +++ b/test/Autofac.Test/Core/ContainerTests.cs @@ -14,7 +14,7 @@ public class ContainerTests [Fact] public void ResolveByName() { - string name = "name"; + var name = "name"; using var activator = Factory.CreateProvidedInstanceActivator(new object()); using var r = Factory.CreateSingletonRegistration( @@ -26,7 +26,7 @@ public void ResolveByName() var c = new ContainerBuilder(builder).Build(); - Assert.True(c.TryResolveNamed(name, typeof(string), out object o)); + Assert.True(c.TryResolveNamed(name, typeof(string), out var o)); Assert.NotNull(o); Assert.False(c.IsRegistered()); @@ -215,6 +215,9 @@ protected override void AttachToComponentRegistration(IComponentRegistryBuilder private class ReplaceableComponent { - public bool IsReplaced { get; set; } + public bool IsReplaced + { + get; set; + } } } diff --git a/test/Autofac.Test/Core/DefaultPropertySelectorTests.cs b/test/Autofac.Test/Core/DefaultPropertySelectorTests.cs index 72f42612f..e147627f0 100644 --- a/test/Autofac.Test/Core/DefaultPropertySelectorTests.cs +++ b/test/Autofac.Test/Core/DefaultPropertySelectorTests.cs @@ -35,14 +35,22 @@ public void DefaultTests(bool preserveSetValue, string propertyName, bool expect private class HasProperties { - public Test PublicPropertyNoDefault { get; set; } + public Test PublicPropertyNoDefault + { + get; set; + } public Test PublicPropertyNoGet { - set { } + set + { + } } - public Test PublicPropertyNoSet { get; } + public Test PublicPropertyNoSet + { + get; + } public Test PublicPropertyThrowsOnGet { @@ -57,13 +65,19 @@ public Test PublicPropertyThrowsOnGet } } - public required Test PublicRequiredProperty { get; set; } + public required Test PublicRequiredProperty + { + get; set; + } public Test PublicPropertyWithDefault { get; set; } = new Test(); private Test PrivatePropertyWithDefault { get; set; } = new Test(); - private Test PrivatePropertyWithSet { get; set; } + private Test PrivatePropertyWithSet + { + get; set; + } } private class Test diff --git a/test/Autofac.Test/Core/DelegatePropertySelectorTests.cs b/test/Autofac.Test/Core/DelegatePropertySelectorTests.cs index 6516bf2ce..a230d6723 100644 --- a/test/Autofac.Test/Core/DelegatePropertySelectorTests.cs +++ b/test/Autofac.Test/Core/DelegatePropertySelectorTests.cs @@ -16,11 +16,20 @@ private sealed class InjectPropertyAttribute : Attribute private class HasProperties { [InjectProperty] - public int PublicProperty { get; set; } + public int PublicProperty + { + get; set; + } - public int PropNoSetter { get; } + public int PropNoSetter + { + get; + } - private int PrivateProperty { get; set; } + private int PrivateProperty + { + get; set; + } } [Fact] diff --git a/test/Autofac.Test/Core/ImplicitRegistrationSourceTests.cs b/test/Autofac.Test/Core/ImplicitRegistrationSourceTests.cs index 41b01d39f..6d7f27c1a 100644 --- a/test/Autofac.Test/Core/ImplicitRegistrationSourceTests.cs +++ b/test/Autofac.Test/Core/ImplicitRegistrationSourceTests.cs @@ -119,7 +119,10 @@ public Mapped(T instance) Instance = instance; } - public T Instance { get; } + public T Instance + { + get; + } } private class MappedImplicitRegistrationSource : ImplicitRegistrationSource diff --git a/test/Autofac.Test/Core/KeyedServiceKeyParameterTests.cs b/test/Autofac.Test/Core/KeyedServiceKeyParameterTests.cs index f0a91efed..cfd8dbe5d 100644 --- a/test/Autofac.Test/Core/KeyedServiceKeyParameterTests.cs +++ b/test/Autofac.Test/Core/KeyedServiceKeyParameterTests.cs @@ -79,6 +79,9 @@ public NeedsConstructorKey([ServiceKey] object key) Key = key; } - public object Key { get; } + public object Key + { + get; + } } } diff --git a/test/Autofac.Test/Core/KeyedServiceParameterInjectorTests.cs b/test/Autofac.Test/Core/KeyedServiceParameterInjectorTests.cs index e23fb1d92..f76b9780c 100644 --- a/test/Autofac.Test/Core/KeyedServiceParameterInjectorTests.cs +++ b/test/Autofac.Test/Core/KeyedServiceParameterInjectorTests.cs @@ -116,6 +116,9 @@ public NeedsConstructorKey([ServiceKey] object key) Key = key; } - public object Key { get; } + public object Key + { + get; + } } } diff --git a/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs b/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs index 52de9dc46..157136a5c 100644 --- a/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs +++ b/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs @@ -16,17 +16,17 @@ public class LifetimeScopeTests [Fact] public void AdaptersInNestedScopeOverrideAdaptersInParent() { - const string parentInstance = "p"; - const string childInstance = "c"; + const string ParentInstance = "p"; + const string ChildInstance = "c"; var builder = new ContainerBuilder(); - builder.ComponentRegistryBuilder.AddRegistrationSource(new ObjectRegistrationSource(parentInstance)); + builder.ComponentRegistryBuilder.AddRegistrationSource(new ObjectRegistrationSource(ParentInstance)); var parent = builder.Build(); var child = parent.BeginLifetimeScope(lifetimeScopeBuilder => - lifetimeScopeBuilder.RegisterSource(new ObjectRegistrationSource(childInstance))); + lifetimeScopeBuilder.RegisterSource(new ObjectRegistrationSource(ChildInstance))); var fromChild = child.Resolve(); - Assert.Same(childInstance, fromChild); + Assert.Same(ChildInstance, fromChild); } [Fact] @@ -61,13 +61,13 @@ public void NestedLifetimeScopesMaintainServiceLimitTypes() var service = new TypedService(typeof(Person)); using (var unconfigured = container.BeginLifetimeScope()) { - Assert.True(unconfigured.ComponentRegistry.TryGetRegistration(service, out IComponentRegistration reg), "The registration should have been found in the unconfigured scope."); + Assert.True(unconfigured.ComponentRegistry.TryGetRegistration(service, out var reg), "The registration should have been found in the unconfigured scope."); Assert.Equal(typeof(Person), reg.Activator.LimitType); } using (var configured = container.BeginLifetimeScope(b => { })) { - Assert.True(configured.ComponentRegistry.TryGetRegistration(service, out IComponentRegistration reg), "The registration should have been found in the configured scope."); + Assert.True(configured.ComponentRegistry.TryGetRegistration(service, out var reg), "The registration should have been found in the configured scope."); Assert.Equal(typeof(Person), reg.Activator.LimitType); } } @@ -163,7 +163,10 @@ private class SimplifiedRegistrationSource : IRegistrationSource { private readonly ITest _instance; - public bool IsAdapterForIndividualComponents { get; } + public bool IsAdapterForIndividualComponents + { + get; + } public SimplifiedRegistrationSource(ITest instance) => _instance = instance; @@ -184,8 +187,8 @@ public IEnumerable RegistrationsFor(Service service, Fun private static bool IsTestType(Type serviceType) => typeof(ITest).IsAssignableFrom(serviceType); [SuppressMessage("CA2000", "CA2000", Justification = "The registration disposes of the activator automatically.")] - private static ComponentRegistration CreateRegistration(Service service, Type serviceType, Func, object> factory) => - new( + private static ComponentRegistration CreateRegistration(Service service, Type serviceType, Func, object> factory) + => new( Guid.NewGuid(), new DelegateActivator(serviceType, factory), CurrentScopeLifetime.Instance, @@ -202,7 +205,10 @@ public DependsOnRegisteredInstance(object instance) Instance = instance; } - internal object Instance { get; set; } + internal object Instance + { + get; set; + } } private class Person diff --git a/test/Autofac.Test/Core/Lifetime/MatchingScopeLifetimeTests.cs b/test/Autofac.Test/Core/Lifetime/MatchingScopeLifetimeTests.cs index 7047c7f2c..65703fe3e 100644 --- a/test/Autofac.Test/Core/Lifetime/MatchingScopeLifetimeTests.cs +++ b/test/Autofac.Test/Core/Lifetime/MatchingScopeLifetimeTests.cs @@ -13,25 +13,25 @@ public class MatchingScopeLifetimeTests public void WhenNoMatchingScopeIsPresent_TheExceptionMessageIncludesTheTag() { using var container = Factory.CreateEmptyContainer(); - const string tag = "abcdefg"; - var msl = new MatchingScopeLifetime(tag); + const string Tag = "abcdefg"; + var msl = new MatchingScopeLifetime(Tag); var rootScope = (ISharingLifetimeScope)container.Resolve(); var ex = Assert.Throws(() => msl.FindScope(rootScope)); - Assert.Contains(tag, ex.Message, StringComparison.Ordinal); + Assert.Contains(Tag, ex.Message, StringComparison.Ordinal); } [Fact] public void WhenNoMatchingScopeIsPresent_TheExceptionMessageIncludesTheTags() { using var container = Factory.CreateEmptyContainer(); - const string tag1 = "abc"; - const string tag2 = "def"; - var msl = new MatchingScopeLifetime(tag1, tag2); + const string Tag1 = "abc"; + const string Tag2 = "def"; + var msl = new MatchingScopeLifetime(Tag1, Tag2); var rootScope = (ISharingLifetimeScope)container.Resolve(); var ex = Assert.Throws(() => msl.FindScope(rootScope)); - Assert.Contains(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", tag1, tag2), ex.Message, StringComparison.Ordinal); + Assert.Contains(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", Tag1, Tag2), ex.Message, StringComparison.Ordinal); } [Fact] @@ -46,10 +46,10 @@ public void WhenTagsToMatchIsNull_ExceptionThrown() [Fact] public void MatchesAgainstSingleTaggedScope() { - const string tag = "Tag"; - var msl = new MatchingScopeLifetime(tag); + const string Tag = "Tag"; + var msl = new MatchingScopeLifetime(Tag); using var container = Factory.CreateEmptyContainer(); - var lifetimeScope = (ISharingLifetimeScope)container.BeginLifetimeScope(tag); + var lifetimeScope = (ISharingLifetimeScope)container.BeginLifetimeScope(Tag); Assert.Equal(lifetimeScope, msl.FindScope(lifetimeScope)); } @@ -57,16 +57,16 @@ public void MatchesAgainstSingleTaggedScope() [Fact] public void MatchesAgainstMultipleTaggedScopes() { - const string tag1 = "Tag1"; - const string tag2 = "Tag2"; + const string Tag1 = "Tag1"; + const string Tag2 = "Tag2"; - var msl = new MatchingScopeLifetime(tag1, tag2); + var msl = new MatchingScopeLifetime(Tag1, Tag2); using var container = Factory.CreateEmptyContainer(); - var tag1Scope = (ISharingLifetimeScope)container.BeginLifetimeScope(tag1); + var tag1Scope = (ISharingLifetimeScope)container.BeginLifetimeScope(Tag1); Assert.Equal(tag1Scope, msl.FindScope(tag1Scope)); - var tag2Scope = (ISharingLifetimeScope)container.BeginLifetimeScope(tag2); + var tag2Scope = (ISharingLifetimeScope)container.BeginLifetimeScope(Tag2); Assert.Equal(tag2Scope, msl.FindScope(tag2Scope)); } } diff --git a/test/Autofac.Test/Core/NamedPropertyParameterTests.cs b/test/Autofac.Test/Core/NamedPropertyParameterTests.cs index 171cf0127..f93e90344 100644 --- a/test/Autofac.Test/Core/NamedPropertyParameterTests.cs +++ b/test/Autofac.Test/Core/NamedPropertyParameterTests.cs @@ -85,27 +85,27 @@ private ParameterInfo MethodParameter() public void MatchesPropertySetterByName() { var cp = new NamedPropertyParameter(HasInjectionPoints.PropertyName, ""); - Assert.True(cp.CanSupplyValue(PropertySetValueParameter(), new ContainerBuilder().Build(), out Func vp)); + Assert.True(cp.CanSupplyValue(PropertySetValueParameter(), new ContainerBuilder().Build(), out var vp)); } [Fact] public void DoesNotMatchePropertySetterWithDifferentName() { var cp = new NamedPropertyParameter(HasInjectionPoints.PropertyName, ""); - Assert.False(cp.CanSupplyValue(WrongPropertySetValueParameter(), new ContainerBuilder().Build(), out Func vp)); + Assert.False(cp.CanSupplyValue(WrongPropertySetValueParameter(), new ContainerBuilder().Build(), out var vp)); } [Fact] public void DoesNotMatchConstructorParameters() { var cp = new NamedPropertyParameter(HasInjectionPoints.PropertyName, ""); - Assert.False(cp.CanSupplyValue(ConstructorParameter(), new ContainerBuilder().Build(), out Func vp)); + Assert.False(cp.CanSupplyValue(ConstructorParameter(), new ContainerBuilder().Build(), out var vp)); } [Fact] public void DoesNotMatchRegularMethodParameters() { var cp = new NamedPropertyParameter(HasInjectionPoints.PropertyName, ""); - Assert.False(cp.CanSupplyValue(MethodParameter(), new ContainerBuilder().Build(), out Func vp)); + Assert.False(cp.CanSupplyValue(MethodParameter(), new ContainerBuilder().Build(), out var vp)); } } diff --git a/test/Autofac.Test/Core/Pipeline/PipelineBuilderTests.cs b/test/Autofac.Test/Core/Pipeline/PipelineBuilderTests.cs index 76f612a19..569d3fed4 100644 --- a/test/Autofac.Test/Core/Pipeline/PipelineBuilderTests.cs +++ b/test/Autofac.Test/Core/Pipeline/PipelineBuilderTests.cs @@ -445,7 +445,10 @@ public PipelineRequestContextStub() Operation = new ResolveOperation(new LifetimeScopeStub(), _diagnosticSource); } - public override IResolveOperation Operation { get; } + public override IResolveOperation Operation + { + get; + } public override ISharingLifetimeScope ActivationScope { get; protected set; } = null!; @@ -455,7 +458,10 @@ public PipelineRequestContextStub() public override IComponentRegistration DecoratorTarget => _resolveRequest.DecoratorTarget; - public override object Instance { get; set; } + public override object Instance + { + get; set; + } public override bool NewInstanceActivated => Instance is { } && PhaseReached == PipelinePhase.Activation; @@ -469,14 +475,25 @@ protected set } } - public override PipelinePhase PhaseReached { get; set; } + public override PipelinePhase PhaseReached + { + get; set; + } - public override DecoratorContext DecoratorContext { get; set; } + public override DecoratorContext DecoratorContext + { + get; set; + } public override event EventHandler RequestCompleting { - add { } - remove { } + add + { + } + + remove + { + } } public override void ChangeScope(ISharingLifetimeScope newScope) => throw new NotImplementedException(); @@ -502,20 +519,35 @@ private class LifetimeScopeStub : ISharingLifetimeScope public event EventHandler ChildLifetimeScopeBeginning { - add { } - remove { } + add + { + } + + remove + { + } } public event EventHandler CurrentScopeEnding { - add { } - remove { } + add + { + } + + remove + { + } } public event EventHandler ResolveOperationBeginning { - add { } - remove { } + add + { + } + + remove + { + } } public ILifetimeScope BeginLifetimeScope() diff --git a/test/Autofac.Test/Core/PreserveExistingDefaultsTests.cs b/test/Autofac.Test/Core/PreserveExistingDefaultsTests.cs index ceb74d274..545d66b60 100644 --- a/test/Autofac.Test/Core/PreserveExistingDefaultsTests.cs +++ b/test/Autofac.Test/Core/PreserveExistingDefaultsTests.cs @@ -199,11 +199,20 @@ public void NestedScope_PreserveStillSupportsIEnumerable() private class ComplexConsumer { - public int Number { get; private set; } + public int Number + { + get; private set; + } - public string Text { get; private set; } + public string Text + { + get; private set; + } - public object Value { get; set; } + public object Value + { + get; set; + } public ComplexConsumer(int number, string text) { diff --git a/test/Autofac.Test/Core/PropertyInjectionInitOnlyTests.cs b/test/Autofac.Test/Core/PropertyInjectionInitOnlyTests.cs index 0031efcfb..79b7bc839 100644 --- a/test/Autofac.Test/Core/PropertyInjectionInitOnlyTests.cs +++ b/test/Autofac.Test/Core/PropertyInjectionInitOnlyTests.cs @@ -9,7 +9,10 @@ public class PropertyInjectionInitOnlyTests { private class HasInitOnlyProperties { - public string InjectedString { get; init; } + public string InjectedString + { + get; init; + } } [Fact] diff --git a/test/Autofac.Test/Core/Registration/ComponentRegistryTests.cs b/test/Autofac.Test/Core/Registration/ComponentRegistryTests.cs index 00f5c2a69..3bbc26c67 100644 --- a/test/Autofac.Test/Core/Registration/ComponentRegistryTests.cs +++ b/test/Autofac.Test/Core/Registration/ComponentRegistryTests.cs @@ -70,7 +70,7 @@ public void WhenMultipleProvidersOfServiceExist_DefaultRegistrationIsMostRecent( var registry = registryBuilder.Build(); - Assert.True(registry.TryGetRegistration(new TypedService(typeof(object)), out IComponentRegistration defaultRegistration)); + Assert.True(registry.TryGetRegistration(new TypedService(typeof(object)), out var defaultRegistration)); Assert.Same(r2, defaultRegistration); } @@ -101,7 +101,7 @@ public void WhenRegistrationProvidedExplicitlyAndThroughRegistrationSource_Expli registryBuilder.AddRegistrationSource(new ObjectRegistrationSource()); var registry = registryBuilder.Build(); - registry.TryGetRegistration(new TypedService(typeof(object)), out IComponentRegistration defaultForObject); + registry.TryGetRegistration(new TypedService(typeof(object)), out var defaultForObject); Assert.Same(r, defaultForObject); } @@ -178,7 +178,10 @@ public IEnumerable RegistrationsFor( public bool IsAdapterForIndividualComponents { - get { return false; } + get + { + return false; + } } } @@ -220,7 +223,7 @@ public void LastRegistrationSourceRegisteredIsTheDefault() registryBuilder.AddRegistrationSource(new ObjectRegistrationSource(second)); var registry = registryBuilder.Build(); - registry.TryGetRegistration(new TypedService(typeof(object)), out IComponentRegistration def); + registry.TryGetRegistration(new TypedService(typeof(object)), out var def); var invoker = def.Activator.GetPipelineInvoker(registry); diff --git a/test/Autofac.Test/Core/Registration/ScopeRestrictedRegisteredServicesTrackerTests.cs b/test/Autofac.Test/Core/Registration/ScopeRestrictedRegisteredServicesTrackerTests.cs index f5b6f52fb..fd80da98f 100644 --- a/test/Autofac.Test/Core/Registration/ScopeRestrictedRegisteredServicesTrackerTests.cs +++ b/test/Autofac.Test/Core/Registration/ScopeRestrictedRegisteredServicesTrackerTests.cs @@ -10,7 +10,7 @@ namespace Autofac.Test.Core.Registration; public sealed class ScopeRestrictedRegisteredServicesTrackerTests { - private static readonly IComponentRegistration ObjectRegistration = + private static readonly IComponentRegistration _objectRegistration = RegistrationBuilder.ForType().SingleInstance().CreateRegistration(); private class ObjectRegistrationSource : IRegistrationSource @@ -19,7 +19,7 @@ public IEnumerable RegistrationsFor( Service service, Func> registrationAccessor) { - yield return ObjectRegistration; + yield return _objectRegistration; } public bool IsAdapterForIndividualComponents => false; @@ -37,7 +37,7 @@ public void SingletonsFromRegistrationSourceAreWrappedWithLifetimeDecorator() var typedService = new TypedService(typeof(object)); var registry = builder.Build(); - registry.TryGetRegistration(typedService, out IComponentRegistration registration); + registry.TryGetRegistration(typedService, out var registration); Assert.IsType(registration); } @@ -50,12 +50,12 @@ public void SingletonsRegisteredDirectlyAreWrappedWithLifetimeDecorator() using var builder = new ComponentRegistryBuilder(tracker, new Dictionary()); - builder.Register(ObjectRegistration); + builder.Register(_objectRegistration); var registry = builder.Build(); var typedService = new TypedService(typeof(object)); - registry.TryGetRegistration(typedService, out IComponentRegistration registration); + registry.TryGetRegistration(typedService, out var registration); Assert.IsType(registration); } diff --git a/test/Autofac.Test/Core/Registration/SourceRegistrarTests.cs b/test/Autofac.Test/Core/Registration/SourceRegistrarTests.cs index 9f205234f..88f354f43 100644 --- a/test/Autofac.Test/Core/Registration/SourceRegistrarTests.cs +++ b/test/Autofac.Test/Core/Registration/SourceRegistrarTests.cs @@ -8,8 +8,8 @@ namespace Autofac.Test.Core.Registration; public sealed class SourceRegistrarTests { - private static readonly object O1 = new(); - private static readonly object O2 = new(); + private static readonly object _o1 = new(); + private static readonly object _o2 = new(); [Fact] public void Ctor_RequiresContainerBuilder() @@ -24,12 +24,12 @@ public void RegisterSource_ChainsSourceRegistrations() var registrar = new SourceRegistrar(builder); registrar.RegisterSource() - .RegisterSource(new ObjectRegistrationSource(O2)); + .RegisterSource(new ObjectRegistrationSource(_o2)); var container = builder.Build(); var objects = container.Resolve>(); - Assert.Contains(O1, objects); - Assert.Contains(O2, objects); + Assert.Contains(_o1, objects); + Assert.Contains(_o2, objects); } [Fact] @@ -42,7 +42,7 @@ public void RegisterSource_RequiresRegistrationSource() private class SourceA : ObjectRegistrationSource { public SourceA() - : base(O1) + : base(_o1) { } } diff --git a/test/Autofac.Test/Core/ResolvedParameterTests.cs b/test/Autofac.Test/Core/ResolvedParameterTests.cs index 29b295d45..a40ab2919 100644 --- a/test/Autofac.Test/Core/ResolvedParameterTests.cs +++ b/test/Autofac.Test/Core/ResolvedParameterTests.cs @@ -34,7 +34,10 @@ private class ConcreteSomething : ISomething private class SomethingDecorator : ISomething { - public ISomething Decorated { get; private set; } + public ISomething Decorated + { + get; private set; + } public SomethingDecorator(ISomething decorated) { @@ -89,7 +92,7 @@ public void AResolvedParameterForAKeyedServiceMatchesParametersOfTheServiceTypeW var container = builder.Build(); var rp = ResolvedParameter.ForKeyed(k); var cp = GetCharParameter(); - Assert.True(rp.CanSupplyValue(cp, container, out Func vp)); + Assert.True(rp.CanSupplyValue(cp, container, out var vp)); } [Fact] @@ -97,7 +100,7 @@ public void AResolvedParameterForAKeyedServiceDoesNotMatchParametersOfTheService { var rp = ResolvedParameter.ForKeyed(new object()); var cp = GetCharParameter(); - var canSupply = rp.CanSupplyValue(cp, new ContainerBuilder().Build(), out Func vp); + var canSupply = rp.CanSupplyValue(cp, new ContainerBuilder().Build(), out var vp); Assert.False(canSupply); } diff --git a/test/Autofac.Test/Core/ServiceKeyAttributeCacheTests.cs b/test/Autofac.Test/Core/ServiceKeyAttributeCacheTests.cs index 525fec9fa..06f516589 100644 --- a/test/Autofac.Test/Core/ServiceKeyAttributeCacheTests.cs +++ b/test/Autofac.Test/Core/ServiceKeyAttributeCacheTests.cs @@ -45,7 +45,10 @@ public NeedsConstructorKey([ServiceKey] object key) Key = key; } - public object Key { get; } + public object Key + { + get; + } } private sealed class NeedsPropertyKey diff --git a/test/Autofac.Test/Features/AttributeFilters/WithAttributeFilterTestFixture.cs b/test/Autofac.Test/Features/AttributeFilters/WithAttributeFilterTestFixture.cs index 92dc0261f..f83993e2d 100644 --- a/test/Autofac.Test/Features/AttributeFilters/WithAttributeFilterTestFixture.cs +++ b/test/Autofac.Test/Features/AttributeFilters/WithAttributeFilterTestFixture.cs @@ -308,7 +308,7 @@ public void MetadataFilterIsAppliedOnConstructorDependencyMultiple() [Fact] public void ComponentsThatAreNotUsedDoNotGetActivated() { - int adapterActivationCount = 0; + var adapterActivationCount = 0; var builder = new ContainerBuilder(); builder.RegisterType() .WithMetadata(m => m.For(am => am.Target, "Solution")) @@ -399,7 +399,10 @@ private class ToolWindowAdapter : IAdapter private class IdentifiableObject { - public string Id { get; set; } + public string Id + { + get; set; + } } private class ManagerWithManyIndividualConcrete @@ -416,13 +419,25 @@ public ManagerWithManyIndividualConcrete( Third = third; } - public ILogger Logger { get; set; } + public ILogger Logger + { + get; set; + } - public IdentifiableObject First { get; set; } + public IdentifiableObject First + { + get; set; + } - public IdentifiableObject Second { get; set; } + public IdentifiableObject Second + { + get; set; + } - public IdentifiableObject Third { get; set; } + public IdentifiableObject Third + { + get; set; + } } private class ManagerWithLazySingle @@ -432,7 +447,10 @@ public ManagerWithLazySingle([KeyFilter("Manager")] Lazy logger) Logger = logger; } - public Lazy Logger { get; set; } + public Lazy Logger + { + get; set; + } } private class ManagerWithMetaSingle @@ -442,7 +460,10 @@ public ManagerWithMetaSingle([KeyFilter("Manager")] Meta Logger = logger; } - public Meta Logger { get; set; } + public Meta Logger + { + get; set; + } } private class ManagerWithOwnedSingle @@ -452,7 +473,10 @@ public ManagerWithOwnedSingle([KeyFilter("Manager")] Owned logger) Logger = logger; } - public Owned Logger { get; set; } + public Owned Logger + { + get; set; + } } private class ManagerWithLazyMany @@ -462,7 +486,10 @@ public ManagerWithLazyMany([KeyFilter("Manager")] IEnumerable> log Loggers = loggers; } - public IEnumerable> Loggers { get; set; } + public IEnumerable> Loggers + { + get; set; + } } private class ManagerWithMetaMany @@ -472,7 +499,10 @@ public ManagerWithMetaMany([KeyFilter("Manager")] IEnumerable> Loggers { get; set; } + public IEnumerable> Loggers + { + get; set; + } } private class ManagerWithOwnedMany @@ -482,7 +512,10 @@ public ManagerWithOwnedMany([KeyFilter("Manager")] IEnumerable> l Loggers = loggers; } - public IEnumerable> Loggers { get; set; } + public IEnumerable> Loggers + { + get; set; + } } private class SolutionExplorerKeyed @@ -495,9 +528,15 @@ public SolutionExplorerKeyed( Logger = logger; } - public List Adapters { get; set; } + public List Adapters + { + get; set; + } - public ILogger Logger { get; set; } + public ILogger Logger + { + get; set; + } } private class SolutionExplorerMetadata @@ -510,9 +549,15 @@ public SolutionExplorerMetadata( Logger = logger; } - public List Adapters { get; set; } + public List Adapters + { + get; set; + } - public ILogger Logger { get; set; } + public ILogger Logger + { + get; set; + } } private class SolutionExplorerMixed @@ -525,14 +570,23 @@ public SolutionExplorerMixed( Logger = logger; } - public List Adapters { get; set; } + public List Adapters + { + get; set; + } - public ILogger Logger { get; set; } + public ILogger Logger + { + get; set; + } } private class AdapterMetadata { - public string Target { get; set; } + public string Target + { + get; set; + } } private class EmptyMetadata @@ -541,7 +595,10 @@ private class EmptyMetadata private class RequiredParameterWithKeyFilter { - public int Parameter { get; set; } + public int Parameter + { + get; set; + } public RequiredParameterWithKeyFilter([KeyFilter(0)] int parameter) { @@ -551,7 +608,10 @@ public RequiredParameterWithKeyFilter([KeyFilter(0)] int parameter) private class OptionalParameterWithKeyFilter { - public int Parameter { get; set; } + public int Parameter + { + get; set; + } public OptionalParameterWithKeyFilter([KeyFilter(0)] int parameter = 15) { diff --git a/test/Autofac.Test/Features/Collections/CollectionOrderingTests.cs b/test/Autofac.Test/Features/Collections/CollectionOrderingTests.cs index 35e863680..ab8e834f5 100644 --- a/test/Autofac.Test/Features/Collections/CollectionOrderingTests.cs +++ b/test/Autofac.Test/Features/Collections/CollectionOrderingTests.cs @@ -37,12 +37,18 @@ public Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } private class Command { - public string CommandId { get; } + public string CommandId + { + get; + } public Command(string commandId) { @@ -52,12 +58,18 @@ public Command(string commandId) private interface ICommandAdaptor { - Command Command { get; } + Command Command + { + get; + } } private class CommandAdaptor : ICommandAdaptor { - public Command Command { get; } + public Command Command + { + get; + } public CommandAdaptor(Command command) { @@ -403,12 +415,12 @@ public void WhenResolvedThroughAdaptor() [Fact] public void WhenResolvedWithDecorator() { - const string from = "from"; + const string From = "from"; var cb = new ContainerBuilder(); - cb.RegisterType().Named(from); - cb.RegisterType().Named(from); - cb.RegisterType().Named(from); - cb.RegisterDecorator(s => new Decorator(s), from); + cb.RegisterType().Named(From); + cb.RegisterType().Named(From); + cb.RegisterType().Named(From); + cb.RegisterDecorator(s => new Decorator(s), From); var container = cb.Build(); var services = container.Resolve>().Cast().ToArray(); diff --git a/test/Autofac.Test/Features/Collections/CollectionRegistrationSourceTests.cs b/test/Autofac.Test/Features/Collections/CollectionRegistrationSourceTests.cs index 8806255cc..271088dfa 100644 --- a/test/Autofac.Test/Features/Collections/CollectionRegistrationSourceTests.cs +++ b/test/Autofac.Test/Features/Collections/CollectionRegistrationSourceTests.cs @@ -115,17 +115,17 @@ public void ResolvesAllAvailableElementsWhenArrayIsRequested() public void ResolvesAllAvailableElementsWhenCollectionIsRequested() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); var strings = c.Resolve>(); Assert.Equal(2, strings.Count); - Assert.Contains(s1, strings); - Assert.Contains(s2, strings); + Assert.Contains(S1, strings); + Assert.Contains(S2, strings); Assert.IsType>(strings); } @@ -149,17 +149,17 @@ public void ResolvesAllAvailableElementsWhenEnumerableIsRequested() public void ResolvesAllAvailableElementsWhenListIsRequested() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); var strings = c.Resolve>(); Assert.Equal(2, strings.Count); - Assert.Contains(s1, strings); - Assert.Contains(s2, strings); + Assert.Contains(S1, strings); + Assert.Contains(S2, strings); Assert.IsType>(strings); } @@ -167,34 +167,34 @@ public void ResolvesAllAvailableElementsWhenListIsRequested() public void ResolvesAllAvailableElementsWhenReadOnlyCollectionIsRequested() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); var strings = c.Resolve>(); Assert.Equal(2, strings.Count); - Assert.Contains(s1, strings); - Assert.Contains(s2, strings); + Assert.Contains(S1, strings); + Assert.Contains(S2, strings); } [Fact] public void ResolvesAllAvailableElementsWhenReadOnlyListIsRequested() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); var strings = c.Resolve>(); Assert.Equal(2, strings.Count); - Assert.Contains(s1, strings); - Assert.Contains(s2, strings); + Assert.Contains(S1, strings); + Assert.Contains(S2, strings); } [Fact] @@ -217,10 +217,10 @@ public void ResolvesCollectionItemsFromCurrentLifetimeScope() public void ResolvingClosedCollectionTypeThrowsException() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); Assert.Throws(() => c.Resolve>()); @@ -230,10 +230,10 @@ public void ResolvingClosedCollectionTypeThrowsException() public void ResolvingClosedListTypeThrowsException() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); Assert.Throws(() => c.Resolve>()); @@ -243,10 +243,10 @@ public void ResolvingClosedListTypeThrowsException() public void ResolvingClosedReadOnlyCollectionTypeThrowsException() { var cb = new ContainerBuilder(); - const string s1 = "Hello"; - const string s2 = "World"; - cb.RegisterInstance(s1); - cb.RegisterInstance(s2); + const string S1 = "Hello"; + const string S2 = "World"; + cb.RegisterInstance(S1); + cb.RegisterInstance(S2); var c = cb.Build(); Assert.Throws(() => c.Resolve>()); diff --git a/test/Autofac.Test/Features/Decorators/DecoratorContextTests.cs b/test/Autofac.Test/Features/Decorators/DecoratorContextTests.cs index 24f3bdd78..e55872dda 100644 --- a/test/Autofac.Test/Features/Decorators/DecoratorContextTests.cs +++ b/test/Autofac.Test/Features/Decorators/DecoratorContextTests.cs @@ -10,13 +10,13 @@ public class DecoratorContextTests [Fact] public void CreateSetsContextToPreDecoratedState() { - const string implementationInstance = "Initial"; + const string ImplementationInstance = "Initial"; - var context = DecoratorContext.Create(Factory.CreateEmptyContext(), typeof(string), typeof(string), implementationInstance); + var context = DecoratorContext.Create(Factory.CreateEmptyContext(), typeof(string), typeof(string), ImplementationInstance); Assert.Equal(typeof(string), context.ServiceType); Assert.Equal(typeof(string), context.ImplementationType); - Assert.Equal(implementationInstance, context.CurrentInstance); + Assert.Equal(ImplementationInstance, context.CurrentInstance); Assert.Empty(context.AppliedDecoratorTypes); Assert.Empty(context.AppliedDecorators); } @@ -24,21 +24,21 @@ public void CreateSetsContextToPreDecoratedState() [Fact] public void UpdateAddsDecoratorStateToContext() { - const string implementationInstance = "Initial"; - var context = DecoratorContext.Create(Factory.CreateEmptyContext(), typeof(string), typeof(string), implementationInstance); + const string ImplementationInstance = "Initial"; + var context = DecoratorContext.Create(Factory.CreateEmptyContext(), typeof(string), typeof(string), ImplementationInstance); - const string decoratorA = "DecoratorA"; - context = context.UpdateContext(decoratorA); + const string DecoratorA = "DecoratorA"; + context = context.UpdateContext(DecoratorA); - Assert.Equal(decoratorA, context.CurrentInstance); + Assert.Equal(DecoratorA, context.CurrentInstance); Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string) }); - Assert.Equal(context.AppliedDecorators, new[] { decoratorA }); + Assert.Equal(context.AppliedDecorators, new[] { DecoratorA }); - const string decoratorB = "DecoratorB"; - context = context.UpdateContext(decoratorB); + const string DecoratorB = "DecoratorB"; + context = context.UpdateContext(DecoratorB); - Assert.Equal(decoratorB, context.CurrentInstance); + Assert.Equal(DecoratorB, context.CurrentInstance); Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string), typeof(string) }); - Assert.Equal(context.AppliedDecorators, new[] { decoratorA, decoratorB }); + Assert.Equal(context.AppliedDecorators, new[] { DecoratorA, DecoratorB }); } } diff --git a/test/Autofac.Test/Features/Decorators/DecoratorTests.cs b/test/Autofac.Test/Features/Decorators/DecoratorTests.cs index af495372b..b06a51da0 100644 --- a/test/Autofac.Test/Features/Decorators/DecoratorTests.cs +++ b/test/Autofac.Test/Features/Decorators/DecoratorTests.cs @@ -9,7 +9,10 @@ public class DecoratorTests { private interface IDecoratedService : IService { - IDecoratedService Decorated { get; } + IDecoratedService Decorated + { + get; + } } private interface IService @@ -27,7 +30,10 @@ private class NestedService private class AutoWiredService : IAutoWiredService { - public NestedService NestedService { get; set; } + public NestedService NestedService + { + get; set; + } public bool NestedServiceIsNotNull() { @@ -226,7 +232,10 @@ protected Decorator(IDecoratedService decorated) Decorated = decorated; } - public IDecoratedService Decorated { get; } + public IDecoratedService Decorated + { + get; + } } private class DecoratorA : Decorator diff --git a/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs b/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs index d9391c012..193473ec9 100644 --- a/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs +++ b/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs @@ -29,7 +29,10 @@ private interface ISomeOtherService private interface IDecoratedService : IService { - IDecoratedService Decorated { get; } + IDecoratedService Decorated + { + get; + } } private class ImplementorA : IDecoratedService @@ -46,7 +49,10 @@ private class ImplementorWithParameters : IDecoratedService { public IDecoratedService Decorated => this; - public string Parameter { get; } + public string Parameter + { + get; + } public ImplementorWithParameters(string parameter) { @@ -66,7 +72,10 @@ protected Decorator(IDecoratedService decorated) Decorated = decorated; } - public IDecoratedService Decorated { get; } + public IDecoratedService Decorated + { + get; + } } private class DecoratorA : Decorator @@ -95,7 +104,10 @@ public StringImplementor(IDecoratedService decorated) private interface IDecoratorWithParameter { - string Parameter { get; } + string Parameter + { + get; + } } private class DecoratorWithParameter : Decorator, IDecoratorWithParameter @@ -106,12 +118,18 @@ public DecoratorWithParameter(IDecoratedService decorated, string parameter) Parameter = parameter; } - public string Parameter { get; } + public string Parameter + { + get; + } } private interface IDecoratorWithContext { - IDecoratorContext Context { get; } + IDecoratorContext Context + { + get; + } } private class DecoratorWithContextA : Decorator, IDecoratorWithContext @@ -122,7 +140,10 @@ public DecoratorWithContextA(IDecoratedService decorated, IDecoratorContext c Context = context; } - public IDecoratorContext Context { get; } + public IDecoratorContext Context + { + get; + } } private class DecoratorWithContextB : Decorator, IDecoratorWithContext @@ -133,12 +154,18 @@ public DecoratorWithContextB(IDecoratedService decorated, IDecoratorContext c Context = context; } - public IDecoratorContext Context { get; } + public IDecoratorContext Context + { + get; + } } private class DisposableImplementor : IDecoratedService, IDisposable { - public int DisposeCallCount { get; private set; } + public int DisposeCallCount + { + get; private set; + } public IDecoratedService Decorated => this; @@ -150,7 +177,10 @@ public void Dispose() private class DisposableDecorator : Decorator, IDisposable { - public int DisposeCallCount { get; private set; } + public int DisposeCallCount + { + get; private set; + } public DisposableDecorator(IDecoratedService decorated) : base(decorated) @@ -550,17 +580,17 @@ public void DecoratorInheritsDecoratedLifetimeWhenInstancePerLifetimeScope() [Fact] public void DecoratorInheritsDecoratedLifetimeWhenInstancePerMatchingLifetimeScope() { - const string tag = "foo"; + const string Tag = "foo"; var builder = new ContainerBuilder(); builder.RegisterGeneric(typeof(ImplementorA<>)) .As(typeof(IDecoratedService<>)) - .InstancePerMatchingLifetimeScope(tag); + .InstancePerMatchingLifetimeScope(Tag); builder.RegisterGenericDecorator(typeof(DecoratorA<>), typeof(IDecoratedService<>)); var container = builder.Build(); - using (var scope = container.BeginLifetimeScope(tag)) + using (var scope = container.BeginLifetimeScope(Tag)) { var first = scope.Resolve>(); var second = scope.Resolve>(); @@ -773,20 +803,20 @@ public void DecoratorAndDecoratedBothDisposedWhenInstancePerLifetimeScope() [Fact] public void DecoratorAndDecoratedBothDisposedWhenInstancePerMatchingLifetimeScope() { - const string tag = "foo"; + const string Tag = "foo"; var builder = new ContainerBuilder(); builder.RegisterGeneric(typeof(DisposableImplementor<>)) .As(typeof(IDecoratedService<>)) - .InstancePerMatchingLifetimeScope(tag); + .InstancePerMatchingLifetimeScope(Tag); builder.RegisterGenericDecorator(typeof(DisposableDecorator<>), typeof(IDecoratedService<>)); var container = builder.Build(); DisposableDecorator decorator; DisposableImplementor decorated; - using (var scope = container.BeginLifetimeScope(tag)) + using (var scope = container.BeginLifetimeScope(Tag)) { var instance = scope.Resolve>(); decorator = (DisposableDecorator)instance; @@ -900,7 +930,10 @@ private interface ICommandHandler private class TransactionalCommandHandlerDecorator : ICommandHandler { - public ICommandHandler Handler { get; } + public ICommandHandler Handler + { + get; + } public TransactionalCommandHandlerDecorator(ICommandHandler handler) { diff --git a/test/Autofac.Test/Features/GeneratedFactories/GeneratedFactoriesTests.cs b/test/Autofac.Test/Features/GeneratedFactories/GeneratedFactoriesTests.cs index 218c7e043..1f18f5679 100644 --- a/test/Autofac.Test/Features/GeneratedFactories/GeneratedFactoriesTests.cs +++ b/test/Autofac.Test/Features/GeneratedFactories/GeneratedFactoriesTests.cs @@ -12,7 +12,10 @@ public class GeneratedFactoriesTests { private class A { - public T P { get; private set; } + public T P + { + get; private set; + } public delegate A Factory(T p); @@ -81,9 +84,15 @@ public Shareholding(string symbol, uint holding, QuoteService qs) private readonly QuoteService _qs; - public string Symbol { get; private set; } + public string Symbol + { + get; private set; + } - public uint Holding { get; set; } + public uint Holding + { + get; set; + } public decimal Quote() { @@ -141,7 +150,10 @@ private class StringHolder { public delegate StringHolder Factory(); - public string S { get; set; } + public string S + { + get; set; + } } [Fact] @@ -210,7 +222,10 @@ public void CanNameGeneratedFactories() // is chosen in the presence of implicit collection support. private class HasCharIntCtor { - public string Str { get; private set; } + public string Str + { + get; private set; + } public HasCharIntCtor(char c, int i) { @@ -375,11 +390,20 @@ private class DuplicateConstructorParameterTypes { public delegate DuplicateConstructorParameterTypes Factory(int a, int b, string c); - public int A { get; set; } + public int A + { + get; set; + } - public int B { get; set; } + public int B + { + get; set; + } - public string C { get; set; } + public string C + { + get; set; + } // This constructor should not be able to be resolved into a Func // because of the redundant types in the constructor. diff --git a/test/Autofac.Test/Features/Indexed/KeyedServiceIndexTests.cs b/test/Autofac.Test/Features/Indexed/KeyedServiceIndexTests.cs index bdd3a538f..621284c23 100644 --- a/test/Autofac.Test/Features/Indexed/KeyedServiceIndexTests.cs +++ b/test/Autofac.Test/Features/Indexed/KeyedServiceIndexTests.cs @@ -26,7 +26,7 @@ public void TryGetValueRetrievesComponentsFromContextByKey() var idx = CreateTarget(cpt, key); - Assert.True(idx.TryGetValue(key, out string val)); + Assert.True(idx.TryGetValue(key, out var val)); Assert.Same(cpt, val); } diff --git a/test/Autofac.Test/Features/LazyDependencies/LazyRegistrationSourceTests.cs b/test/Autofac.Test/Features/LazyDependencies/LazyRegistrationSourceTests.cs index 2b9fd1eea..a47bb567c 100644 --- a/test/Autofac.Test/Features/LazyDependencies/LazyRegistrationSourceTests.cs +++ b/test/Autofac.Test/Features/LazyDependencies/LazyRegistrationSourceTests.cs @@ -68,6 +68,9 @@ public A(Lazy b) private class B { - public A A { get; set; } + public A A + { + get; set; + } } } diff --git a/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs b/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs index ea756ee7e..168bb3580 100644 --- a/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs +++ b/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs @@ -107,7 +107,10 @@ public Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } [SuppressMessage("CA1034", "CA1034", Justification = "Type is used as a test scenario/context holder.")] @@ -138,7 +141,10 @@ public void ParametersGoToTheDecoratedInstance() public interface IParameterizedService { - IEnumerable Parameters { get; } + IEnumerable Parameters + { + get; + } } public class ParameterizedImplementer : IParameterizedService @@ -148,7 +154,10 @@ public ParameterizedImplementer(IEnumerable parameters) Parameters = parameters; } - public IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } } public class ParameterizedDecorator1 : IParameterizedService @@ -159,9 +168,15 @@ public ParameterizedDecorator1(IParameterizedService implementer, IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } } public class ParameterizedDecorator2 : IParameterizedService @@ -172,9 +187,15 @@ public ParameterizedDecorator2(IParameterizedService implementer, IEnumerable Parameters { get; } + public IEnumerable Parameters + { + get; + } } } @@ -185,11 +206,11 @@ public class DecoratingANamedService public DecoratingANamedService() { - const string from = "from"; + const string From = "from"; var builder = new ContainerBuilder(); - builder.RegisterType().Named(from); - builder.RegisterType().Named(from); - builder.RegisterDecorator(s => new Decorator(s), from); + builder.RegisterType().Named(From); + builder.RegisterType().Named(From); + builder.RegisterDecorator(s => new Decorator(s), From); _container = builder.Build(); } diff --git a/test/Autofac.Test/Features/Metadata/TestTypes/IMyMetaInterface.cs b/test/Autofac.Test/Features/Metadata/TestTypes/IMyMetaInterface.cs index 5fde318f5..a127b99a8 100644 --- a/test/Autofac.Test/Features/Metadata/TestTypes/IMyMetaInterface.cs +++ b/test/Autofac.Test/Features/Metadata/TestTypes/IMyMetaInterface.cs @@ -5,5 +5,8 @@ namespace Autofac.Test.Features.Metadata.TestTypes; public interface IMyMetaInterface { - int TheInt { get; } + int TheInt + { + get; + } } diff --git a/test/Autofac.Test/Features/Metadata/TestTypes/MyMeta.cs b/test/Autofac.Test/Features/Metadata/TestTypes/MyMeta.cs index b9c987197..06b26bd80 100644 --- a/test/Autofac.Test/Features/Metadata/TestTypes/MyMeta.cs +++ b/test/Autofac.Test/Features/Metadata/TestTypes/MyMeta.cs @@ -5,5 +5,8 @@ namespace Autofac.Test.Features.Metadata.TestTypes; public class MyMeta { - public int TheInt { get; set; } + public int TheInt + { + get; set; + } } diff --git a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDefault.cs b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDefault.cs index 3294a9a91..47bc2cf84 100644 --- a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDefault.cs +++ b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDefault.cs @@ -8,5 +8,8 @@ namespace Autofac.Test.Features.Metadata.TestTypes; public class MyMetaWithDefault { [DefaultValue(42)] - public int TheInt { get; set; } + public int TheInt + { + get; set; + } } diff --git a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDictionary.cs b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDictionary.cs index 55bd030f8..45e1681ab 100644 --- a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDictionary.cs +++ b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDictionary.cs @@ -12,5 +12,8 @@ public MyMetaWithDictionary(IDictionary metadata) TheName = (string)metadata["Name"]; } - public string TheName { get; set; } + public string TheName + { + get; set; + } } diff --git a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithReadOnlyProperty.cs b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithReadOnlyProperty.cs index eae8aa4d6..439455580 100644 --- a/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithReadOnlyProperty.cs +++ b/test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithReadOnlyProperty.cs @@ -5,7 +5,10 @@ namespace Autofac.Test.Features.Metadata.TestTypes; public class MyMetaWithReadOnlyProperty { - public int TheInt { get; set; } + public int TheInt + { + get; set; + } public string ReadOnly { diff --git a/test/Autofac.Test/Features/OpenGenerics/OpenGenericDecoratorTests.cs b/test/Autofac.Test/Features/OpenGenerics/OpenGenericDecoratorTests.cs index d6f74cc4e..965ac9971 100644 --- a/test/Autofac.Test/Features/OpenGenerics/OpenGenericDecoratorTests.cs +++ b/test/Autofac.Test/Features/OpenGenerics/OpenGenericDecoratorTests.cs @@ -7,14 +7,20 @@ public class OpenGenericDecoratorTests { private interface IService { - IService Decorated { get; } + IService Decorated + { + get; + } } private class ImplementorA : IService { public IService Decorated { - get { return this; } + get + { + return this; + } } } @@ -22,7 +28,10 @@ private class ImplementorB : IService { public IService Decorated { - get { return this; } + get + { + return this; + } } } @@ -30,7 +39,10 @@ private class StringImplementor : IService { public IService Decorated { - get { return this; } + get + { + return this; + } } } @@ -41,7 +53,10 @@ protected Decorator(IService decorated) Decorated = decorated; } - public IService Decorated { get; } + public IService Decorated + { + get; + } } private class DecoratorA : Decorator @@ -60,7 +75,10 @@ public DecoratorB(IService decorated, string parameter) Parameter = parameter; } - public string Parameter { get; } + public string Parameter + { + get; + } } private const string ParameterValue = "Abc"; diff --git a/test/Autofac.Test/Features/OpenGenerics/OpenGenericRegistrationExtensionsTests.cs b/test/Autofac.Test/Features/OpenGenerics/OpenGenericRegistrationExtensionsTests.cs index 900acbca4..d6a6bebe6 100644 --- a/test/Autofac.Test/Features/OpenGenerics/OpenGenericRegistrationExtensionsTests.cs +++ b/test/Autofac.Test/Features/OpenGenerics/OpenGenericRegistrationExtensionsTests.cs @@ -24,7 +24,10 @@ public G(int i) I = i; } - public int I { get; private set; } + public int I + { + get; private set; + } } [Fact] @@ -39,8 +42,8 @@ public void BuildGenericRegistration() .As(serviceType); var c = cb.Build(); - object g1 = c.Resolve(concreteServiceType); - object g2 = c.Resolve(concreteServiceType); + var g1 = c.Resolve(concreteServiceType); + var g2 = c.Resolve(concreteServiceType); Assert.NotNull(g1); Assert.NotNull(g2); @@ -55,14 +58,14 @@ public void ExposesImplementationType() cb.RegisterGeneric(typeof(G<>)).As(typeof(IG<>)); var container = cb.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration( - new TypedService(typeof(IG)), out IComponentRegistration cr)); + new TypedService(typeof(IG)), out var cr)); Assert.Equal(typeof(G), cr.Activator.LimitType); } [Fact] public void FiresPreparing() { - int preparingFired = 0; + var preparingFired = 0; var cb = new ContainerBuilder(); cb.RegisterGeneric(typeof(G<>)) .As(typeof(IG<>)) @@ -94,13 +97,13 @@ public void SuppliesParameterToConcreteComponent() [Fact] public void WhenRegistrationNamedGenericRegistrationsSuppliedViaName() { - const string name = "n"; + const string Name = "n"; var cb = new ContainerBuilder(); cb.RegisterGeneric(typeof(G<>)) - .Named(name, typeof(IG<>)); + .Named(Name, typeof(IG<>)); var c = cb.Build(); - Assert.True(c.IsRegisteredWithName>(name)); - Assert.True(c.IsRegisteredWithName>(name)); + Assert.True(c.IsRegisteredWithName>(Name)); + Assert.True(c.IsRegisteredWithName>(Name)); } [Fact] diff --git a/test/Autofac.Test/Features/OwnedInstances/OwnedInstanceRegistrationSourceTests.cs b/test/Autofac.Test/Features/OwnedInstances/OwnedInstanceRegistrationSourceTests.cs index 372c4e972..d81cb8332 100644 --- a/test/Autofac.Test/Features/OwnedInstances/OwnedInstanceRegistrationSourceTests.cs +++ b/test/Autofac.Test/Features/OwnedInstances/OwnedInstanceRegistrationSourceTests.cs @@ -109,7 +109,10 @@ public ClassWithFactory(string name) public delegate Owned OwnedFactory(string name); - public string Name { get; set; } + public string Name + { + get; set; + } } private class ExposesScopeTag diff --git a/test/Autofac.Test/Features/ResolveAnything/ResolveAnythingTests.cs b/test/Autofac.Test/Features/ResolveAnything/ResolveAnythingTests.cs index 62e3ba074..6c9f06c6b 100644 --- a/test/Autofac.Test/Features/ResolveAnything/ResolveAnythingTests.cs +++ b/test/Autofac.Test/Features/ResolveAnything/ResolveAnythingTests.cs @@ -274,6 +274,9 @@ public RegisterTypeWithCtorParam(string stringParam = "MyString") StringParam = stringParam; } - public string StringParam { get; } + public string StringParam + { + get; + } } } diff --git a/test/Autofac.Test/Features/Scanning/OpenGenericScanningRegistrationTests.cs b/test/Autofac.Test/Features/Scanning/OpenGenericScanningRegistrationTests.cs index 6b81ef0ac..3e54dd572 100644 --- a/test/Autofac.Test/Features/Scanning/OpenGenericScanningRegistrationTests.cs +++ b/test/Autofac.Test/Features/Scanning/OpenGenericScanningRegistrationTests.cs @@ -14,7 +14,7 @@ namespace Autofac.Test.Features.Scanning; public class OpenGenericScanningRegistrationTests { - private static readonly Assembly ScenarioAssembly = typeof(AComponent).GetTypeInfo().Assembly; + private static readonly Assembly _scenarioAssembly = typeof(AComponent).GetTypeInfo().Assembly; [Fact] public void WhenAssemblyIsScannedOpenGenericTypesCanBeResolved() @@ -88,7 +88,7 @@ public void WhenMappingToMultipleTypedServicesEachExposedAsService() public void WhenExceptionsProvideConfigurationComponentConfiguredAppropriately() { var cb = new ContainerBuilder(); - cb.RegisterAssemblyOpenGenericTypes(ScenarioAssembly) + cb.RegisterAssemblyOpenGenericTypes(_scenarioAssembly) .Except(typeof(RedoOpenGenericCommand<>), ac => ac.SingleInstance()); var c = cb.Build(); @@ -270,9 +270,9 @@ public void MetadataCanBeScannedFromAMatchingAttributeInterface() var c = cb.Build(); - c.ComponentRegistry.TryGetRegistration(new TypedService(typeof(OpenGenericScannedComponentWithName)), out IComponentRegistration r); + c.ComponentRegistry.TryGetRegistration(new TypedService(typeof(OpenGenericScannedComponentWithName)), out var r); - r.Metadata.TryGetValue("Name", out object name); + r.Metadata.TryGetValue("Name", out var name); Assert.Equal("My Name", name); } diff --git a/test/Autofac.Test/Features/Scanning/ScanningRegistrationTests.cs b/test/Autofac.Test/Features/Scanning/ScanningRegistrationTests.cs index d6e6fb4a8..0e5a27946 100644 --- a/test/Autofac.Test/Features/Scanning/ScanningRegistrationTests.cs +++ b/test/Autofac.Test/Features/Scanning/ScanningRegistrationTests.cs @@ -14,7 +14,7 @@ namespace Autofac.Test.Features.Scanning; public class ScanningRegistrationTests { - private static readonly Assembly ScenarioAssembly = typeof(AComponent).GetTypeInfo().Assembly; + private static readonly Assembly _scenarioAssembly = typeof(AComponent).GetTypeInfo().Assembly; [Fact] public void WhenAssemblyIsScannedTypesRegisteredByDefault() @@ -292,7 +292,7 @@ public void WhenTypedServicesAreSpecifiedImplicitFilterApplied() public void WhenExceptionsProvideConfigurationComponentConfiguredAppropriately() { var cb = new ContainerBuilder(); - cb.RegisterAssemblyTypes(ScenarioAssembly) + cb.RegisterAssemblyTypes(_scenarioAssembly) .Except(ac => ac.SingleInstance()); var c = cb.Build(); var a1 = c.Resolve(); @@ -332,7 +332,7 @@ public void WhenTransformingTypesToServicesNonAssignableServicesAreExcluded() { var cb = new ContainerBuilder(); - cb.RegisterAssemblyTypes(ScenarioAssembly) + cb.RegisterAssemblyTypes(_scenarioAssembly) .As(t => new KeyedService("foo", typeof(ScanningRegistrationTests))); var c = cb.Build(); @@ -345,7 +345,7 @@ public void WhenTransformingTypesToServicesComponentsWithNoServicesAreExcluded() { var cb = new ContainerBuilder(); - cb.RegisterAssemblyTypes(ScenarioAssembly) + cb.RegisterAssemblyTypes(_scenarioAssembly) .As(t => new KeyedService("foo", typeof(ScanningRegistrationTests))); var c = cb.Build(); @@ -373,9 +373,9 @@ public void ByDefaultIDisposableIsNotAServiceInterface() [Fact] public void WhenDerivingKeysDynamically_TheCorrectOverloadIsChosen() { - const string key = "a-key"; - var c = RegisterScenarioAssembly(a => a.Keyed(t => key)); - Assert.True(c.IsRegisteredWithKey(key)); + const string Key = "a-key"; + var c = RegisterScenarioAssembly(a => a.Keyed(t => Key)); + Assert.True(c.IsRegisteredWithKey(Key)); } [Fact] @@ -383,7 +383,7 @@ public void PreserveExistingDefaults() { var cb = new ContainerBuilder(); cb.RegisterType().As(); - cb.RegisterAssemblyTypes(ScenarioAssembly) + cb.RegisterAssemblyTypes(_scenarioAssembly) .As() .PreserveExistingDefaults(); @@ -395,7 +395,7 @@ public void PreserveExistingDefaults() public static IContainer RegisterScenarioAssembly(Action> configuration = null) { var cb = new ContainerBuilder(); - var config = cb.RegisterAssemblyTypes(ScenarioAssembly); + var config = cb.RegisterAssemblyTypes(_scenarioAssembly); configuration?.Invoke(config); return cb.Build(); @@ -415,9 +415,9 @@ public void MetadataCanBeScannedFromAMatchingAttributeInterface() .Where(t => t == typeof(ScannedComponentWithName)) .WithMetadataFrom()); - c.ComponentRegistry.TryGetRegistration(new TypedService(typeof(ScannedComponentWithName)), out IComponentRegistration r); + c.ComponentRegistry.TryGetRegistration(new TypedService(typeof(ScannedComponentWithName)), out var r); - r.Metadata.TryGetValue("Name", out object name); + r.Metadata.TryGetValue("Name", out var name); Assert.Equal("My Name", name); } @@ -425,13 +425,13 @@ public void MetadataCanBeScannedFromAMatchingAttributeInterface() [Fact] public void ScanningKeyedRegistrationsFilterByAssignabilityBeforeMappingKey() { - const string k = "key"; + const string K = "key"; var c = RegisterScenarioAssembly(a => a.Keyed(t => { Assert.True(typeof(IAService).IsAssignableFrom(t)); - return k; + return K; })); - Assert.True(c.IsRegisteredWithKey(k)); + Assert.True(c.IsRegisteredWithKey(K)); } [Fact] @@ -449,7 +449,7 @@ public void InternalClassesAreFoundByDefault() { // Issue #897: It may not be obvious, but our long-running behavior has been to include non-public types. var c = RegisterScenarioAssembly(); - var internalType = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.InternalComponent", true); + var internalType = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.InternalComponent", true); Assert.True(c.IsRegistered(internalType)); } @@ -458,7 +458,7 @@ public void InternalClassesCanBeFilteredOut() { // Issue #897: It may not be obvious, but our long-running behavior has been to include non-public types. var c = RegisterScenarioAssembly(conf => conf.PublicOnly()); - var internalType = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.InternalComponent", true); + var internalType = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.InternalComponent", true); Assert.False(c.IsRegistered(internalType)); } @@ -467,8 +467,8 @@ public void NonPublicNestedClassesAreFoundByDefault() { // Issue #897: It may not be obvious, but our long-running behavior has been to include non-public types. var c = RegisterScenarioAssembly(); - var privateType = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+PrivateComponent", true); - _ = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+InternalComponent", true); + var privateType = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+PrivateComponent", true); + _ = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+InternalComponent", true); c.AssertRegistered(); Assert.True(c.IsRegistered(privateType)); } @@ -478,8 +478,8 @@ public void NonPublicNestedClassesCanBeFilteredOut() { // Issue #897: It may not be obvious, but our long-running behavior has been to include non-public types. var c = RegisterScenarioAssembly(conf => conf.PublicOnly()); - var privateType = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+PrivateComponent", true); - var internalType = ScenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+InternalComponent", true); + var privateType = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+PrivateComponent", true); + var internalType = _scenarioAssembly.GetType("Autofac.Test.Scenarios.ScannedAssembly.NestedComponent+InternalComponent", true); c.AssertRegistered(); Assert.False(c.IsRegistered(privateType)); } diff --git a/test/Autofac.Test/Mocks.cs b/test/Autofac.Test/Mocks.cs index e6e1ae357..ba07f8c28 100644 --- a/test/Autofac.Test/Mocks.cs +++ b/test/Autofac.Test/Mocks.cs @@ -78,33 +78,66 @@ public ValueTask DisposeAsync() return default; } - public bool IsDisposed { get; private set; } + public bool IsDisposed + { + get; private set; + } - public Guid Id { get; } + public Guid Id + { + get; + } - public IInstanceActivator Activator { get; } + public IInstanceActivator Activator + { + get; + } - public IComponentLifetime Lifetime { get; } + public IComponentLifetime Lifetime + { + get; + } - public InstanceSharing Sharing { get; } + public InstanceSharing Sharing + { + get; + } - public InstanceOwnership Ownership { get; } + public InstanceOwnership Ownership + { + get; + } public IEnumerable Services { get; } = Array.Empty(); - public IDictionary Metadata { get; } + public IDictionary Metadata + { + get; + } - public IComponentRegistration Target { get; } + public IComponentRegistration Target + { + get; + } - public bool IsAdapterForIndividualComponent { get; } + public bool IsAdapterForIndividualComponent + { + get; + } public event EventHandler PipelineBuilding; public IResolvePipeline ResolvePipeline { get; } = new ResolvePipelineBuilder(PipelineType.Registration).Build(); - public bool IsServiceOverride { get; set; } + public bool IsServiceOverride + { + get; set; + } - public RegistrationOptions Options { get; set; } + public RegistrationOptions Options + { + get; set; + } public void BuildResolvePipeline(IComponentRegistryServices registryServices) { diff --git a/test/Autofac.Test/NamedParameterTests.cs b/test/Autofac.Test/NamedParameterTests.cs index 692d0190b..755541ecb 100644 --- a/test/Autofac.Test/NamedParameterTests.cs +++ b/test/Autofac.Test/NamedParameterTests.cs @@ -30,7 +30,7 @@ public void MatchesIdenticallyNamedParameter() var namedParam = new NamedParameter("a", new A()); using var container = Factory.CreateEmptyContainer(); - Assert.True(namedParam.CanSupplyValue(param, container, out Func vp)); + Assert.True(namedParam.CanSupplyValue(param, container, out var vp)); } private static ParameterInfo AParamOfCConstructor() @@ -52,6 +52,6 @@ public void DoesNotMatchDifferentlyNamedParameter() var namedParam = new NamedParameter("b", new B()); using var container = Factory.CreateEmptyContainer(); - Assert.False(namedParam.CanSupplyValue(param, container, out Func vp)); + Assert.False(namedParam.CanSupplyValue(param, container, out var vp)); } } diff --git a/test/Autofac.Test/ResolutionExtensionsTests.cs b/test/Autofac.Test/ResolutionExtensionsTests.cs index dd9ec8155..c9f9f9b4c 100644 --- a/test/Autofac.Test/ResolutionExtensionsTests.cs +++ b/test/Autofac.Test/ResolutionExtensionsTests.cs @@ -66,77 +66,77 @@ public void WhenParametersProvided_ResolveOptionalSuppliesThemToComponent() var cb = new ContainerBuilder(); cb.RegisterType(); var container = cb.Build(); - const string param1 = "Hello"; - const int param2 = 42; + const string Param1 = "Hello"; + const int Param2 = 42; var result = container.ResolveOptional( - new NamedParameter("a", param1), - new NamedParameter("b", param2)); + new NamedParameter("a", Param1), + new NamedParameter("b", Param2)); Assert.NotNull(result); - Assert.Equal(param1, result.A); - Assert.Equal(param2, result.B); + Assert.Equal(Param1, result.A); + Assert.Equal(Param2, result.B); } [Fact] public void WhenPredicateAndValueParameterSupplied_PassedToComponent() { - const string a = "Hello"; - const int b = 42; + const string A = "Hello"; + const int B = 42; var builder = new ContainerBuilder(); builder.RegisterType() .WithParameter( (pi, c) => pi.Name == "a", - (pi, c) => a) + (pi, c) => A) .WithParameter( (pi, c) => pi.Name == "b", - (pi, c) => b); + (pi, c) => B); var container = builder.Build(); var result = container.Resolve(); - Assert.Equal(a, result.A); - Assert.Equal(b, result.B); + Assert.Equal(A, result.A); + Assert.Equal(B, result.B); } [Fact] public void RegisterPropertyWithExpression() { - const string a = "Hello"; - const bool b = true; + const string A = "Hello"; + const bool B = true; var builder = new ContainerBuilder(); builder.RegisterType() - .WithProperty(x => x.A, a) - .WithProperty(x => x.B, b); + .WithProperty(x => x.A, A) + .WithProperty(x => x.B, B); var container = builder.Build(); var result = container.Resolve(); - Assert.Equal(a, result.A); - Assert.Equal(b, result.B); + Assert.Equal(A, result.A); + Assert.Equal(B, result.B); } [Fact] public void RegisterPropertyWithExpressionFieldExceptions() { - const string a = "Hello"; + const string A = "Hello"; var builder = new ContainerBuilder(); Assert.Throws(() => - builder.RegisterType().WithProperty(x => x._field, a)); + builder.RegisterType().WithProperty(x => x._field, A)); } [Fact] public void WhenServiceIsRegistered_TryResolveNamedReturnsTrue() { - const string name = "name"; + const string Name = "name"; var cb = new ContainerBuilder(); - cb.RegisterType().Named(name); + cb.RegisterType().Named(Name); var container = cb.Build(); - Assert.True(container.TryResolveNamed(name, out var o)); + Assert.True(container.TryResolveNamed(Name, out var o)); Assert.NotNull(o); } diff --git a/test/Autofac.Test/Scenarios/Adapters/IToolbarButton.cs b/test/Autofac.Test/Scenarios/Adapters/IToolbarButton.cs index f53bd290e..e5bd60edc 100644 --- a/test/Autofac.Test/Scenarios/Adapters/IToolbarButton.cs +++ b/test/Autofac.Test/Scenarios/Adapters/IToolbarButton.cs @@ -5,7 +5,13 @@ namespace Autofac.Test.Scenarios.Adapters; public interface IToolbarButton { - string Name { get; } + string Name + { + get; + } - Command Command { get; } + Command Command + { + get; + } } diff --git a/test/Autofac.Test/Scenarios/Adapters/ToolbarButton.cs b/test/Autofac.Test/Scenarios/Adapters/ToolbarButton.cs index a49289190..ee25f744f 100644 --- a/test/Autofac.Test/Scenarios/Adapters/ToolbarButton.cs +++ b/test/Autofac.Test/Scenarios/Adapters/ToolbarButton.cs @@ -11,7 +11,13 @@ public ToolbarButton(Command command, string name = "") Name = name; } - public string Name { get; } + public string Name + { + get; + } - public Command Command { get; } + public Command Command + { + get; + } } diff --git a/test/Autofac.Test/Scenarios/Dependencies/Dependent.cs b/test/Autofac.Test/Scenarios/Dependencies/Dependent.cs index dd1a21f29..a56534d6a 100644 --- a/test/Autofac.Test/Scenarios/Dependencies/Dependent.cs +++ b/test/Autofac.Test/Scenarios/Dependencies/Dependent.cs @@ -5,9 +5,15 @@ namespace Autofac.Test.Scenarios.Dependencies; public class Dependent { - public object TheObject { get; private set; } + public object TheObject + { + get; private set; + } - public string TheString { get; private set; } + public string TheString + { + get; private set; + } public Dependent(object o, string s) { diff --git a/test/Autofac.Test/Scenarios/Dependencies/DependsByCtor.cs b/test/Autofac.Test/Scenarios/Dependencies/DependsByCtor.cs index 06dc2d406..7ba59ccf2 100644 --- a/test/Autofac.Test/Scenarios/Dependencies/DependsByCtor.cs +++ b/test/Autofac.Test/Scenarios/Dependencies/DependsByCtor.cs @@ -10,5 +10,8 @@ public DependsByCtor(DependsByProp o) Dep = o; } - public DependsByProp Dep { get; private set; } + public DependsByProp Dep + { + get; private set; + } } diff --git a/test/Autofac.Test/Scenarios/Dependencies/DependsByProp.cs b/test/Autofac.Test/Scenarios/Dependencies/DependsByProp.cs index c4eaebc92..71449411b 100644 --- a/test/Autofac.Test/Scenarios/Dependencies/DependsByProp.cs +++ b/test/Autofac.Test/Scenarios/Dependencies/DependsByProp.cs @@ -5,5 +5,8 @@ namespace Autofac.Test.Scenarios.Dependencies; public class DependsByProp { - public DependsByCtor Dep { get; set; } + public DependsByCtor Dep + { + get; set; + } } diff --git a/test/Autofac.Test/Scenarios/Graph1/B1.cs b/test/Autofac.Test/Scenarios/Graph1/B1.cs index f9c749e79..317766c9f 100644 --- a/test/Autofac.Test/Scenarios/Graph1/B1.cs +++ b/test/Autofac.Test/Scenarios/Graph1/B1.cs @@ -14,5 +14,8 @@ public B1(A1 a) A = a; } - public A1 A { get; private set; } + public A1 A + { + get; private set; + } } diff --git a/test/Autofac.Test/Scenarios/Graph1/C1.cs b/test/Autofac.Test/Scenarios/Graph1/C1.cs index f517923b7..cbac5194c 100644 --- a/test/Autofac.Test/Scenarios/Graph1/C1.cs +++ b/test/Autofac.Test/Scenarios/Graph1/C1.cs @@ -14,5 +14,8 @@ public C1(B1 b) B = b; } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } } diff --git a/test/Autofac.Test/Scenarios/Graph1/CD1.cs b/test/Autofac.Test/Scenarios/Graph1/CD1.cs index fe3e88644..78e4abcc4 100644 --- a/test/Autofac.Test/Scenarios/Graph1/CD1.cs +++ b/test/Autofac.Test/Scenarios/Graph1/CD1.cs @@ -15,7 +15,13 @@ public CD1(A1 a, B1 b) B = b; } - public A1 A { get; private set; } + public A1 A + { + get; private set; + } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } } diff --git a/test/Autofac.Test/Scenarios/Graph1/E1.cs b/test/Autofac.Test/Scenarios/Graph1/E1.cs index d57fc95b1..51ceccdb5 100644 --- a/test/Autofac.Test/Scenarios/Graph1/E1.cs +++ b/test/Autofac.Test/Scenarios/Graph1/E1.cs @@ -15,7 +15,13 @@ public E1(B1 b, IC1 c) C = c; } - public B1 B { get; private set; } + public B1 B + { + get; private set; + } - public IC1 C { get; private set; } + public IC1 C + { + get; private set; + } } diff --git a/test/Autofac.Test/Scenarios/Graph1/F1.cs b/test/Autofac.Test/Scenarios/Graph1/F1.cs index a74c2773a..d17142c61 100644 --- a/test/Autofac.Test/Scenarios/Graph1/F1.cs +++ b/test/Autofac.Test/Scenarios/Graph1/F1.cs @@ -7,7 +7,10 @@ namespace Autofac.Test.Scenarios.Graph1; // and E depends on IC1 and B1. public class F1 { - public IList AList { get; private set; } + public IList AList + { + get; private set; + } public F1(IList aList) { diff --git a/test/Autofac.Test/Scenarios/Parameterization/Parameterized.cs b/test/Autofac.Test/Scenarios/Parameterization/Parameterized.cs index dd60d5e0e..5b52e2941 100644 --- a/test/Autofac.Test/Scenarios/Parameterization/Parameterized.cs +++ b/test/Autofac.Test/Scenarios/Parameterization/Parameterized.cs @@ -5,9 +5,15 @@ namespace Autofac.Test.Scenarios.Parameterization; public class Parameterized { - public string A { get; private set; } + public string A + { + get; private set; + } - public int B { get; private set; } + public int B + { + get; private set; + } public Parameterized(string a, int b) { diff --git a/test/Autofac.Test/Scenarios/RegistrationSources/ObjectRegistrationSource.cs b/test/Autofac.Test/Scenarios/RegistrationSources/ObjectRegistrationSource.cs index dd6f1d5a9..c9b13ca4b 100644 --- a/test/Autofac.Test/Scenarios/RegistrationSources/ObjectRegistrationSource.cs +++ b/test/Autofac.Test/Scenarios/RegistrationSources/ObjectRegistrationSource.cs @@ -30,6 +30,9 @@ public IEnumerable RegistrationsFor(Service service, Fun public bool IsAdapterForIndividualComponents { - get { return false; } + get + { + return false; + } } } diff --git a/test/Autofac.Test/Scenarios/WithProperty/WithProps.cs b/test/Autofac.Test/Scenarios/WithProperty/WithProps.cs index 51d66bf41..416f485d3 100644 --- a/test/Autofac.Test/Scenarios/WithProperty/WithProps.cs +++ b/test/Autofac.Test/Scenarios/WithProperty/WithProps.cs @@ -5,9 +5,15 @@ namespace Autofac.Test.Scenarios.WithProperty; public class WithProps { - public string A { get; set; } + public string A + { + get; set; + } - public bool B { get; set; } + public bool B + { + get; set; + } [SuppressMessage("SA1401", "SA1401", Justification = "Public field handles a specific test case.")] [SuppressMessage("CA1051", "CA1051", Justification = "Public field handles a specific test case.")] diff --git a/test/Autofac.Test/SourceRegistrationExtensionsTests.cs b/test/Autofac.Test/SourceRegistrationExtensionsTests.cs index 182796583..2fb1e93e2 100644 --- a/test/Autofac.Test/SourceRegistrationExtensionsTests.cs +++ b/test/Autofac.Test/SourceRegistrationExtensionsTests.cs @@ -39,7 +39,10 @@ public void RegisterObjectSource() private sealed class EmptyRegistrationSource : IRegistrationSource { - public bool RegistrationsForCalled { get; private set; } + public bool RegistrationsForCalled + { + get; private set; + } public bool IsAdapterForIndividualComponents => false; diff --git a/test/Autofac.Test/TagsFixture.cs b/test/Autofac.Test/TagsFixture.cs index 1523deacc..89708c79e 100644 --- a/test/Autofac.Test/TagsFixture.cs +++ b/test/Autofac.Test/TagsFixture.cs @@ -117,17 +117,17 @@ public void InnerRegistrationNotAccessibleToOuter() [Fact] public void MatchesAgainstMultipleScopes() { - const string tag1 = "Tag1"; - const string tag2 = "Tag2"; + const string Tag1 = "Tag1"; + const string Tag2 = "Tag2"; var builder = new ContainerBuilder(); - builder.Register(c => new object()).InstancePerMatchingLifetimeScope(tag1, tag2); + builder.Register(c => new object()).InstancePerMatchingLifetimeScope(Tag1, Tag2); var container = builder.Build(); - var lifetimeScope = container.BeginLifetimeScope(tag1); + var lifetimeScope = container.BeginLifetimeScope(Tag1); Assert.NotNull(lifetimeScope.Resolve()); - lifetimeScope = container.BeginLifetimeScope(tag2); + lifetimeScope = container.BeginLifetimeScope(Tag2); Assert.NotNull(lifetimeScope.Resolve()); } diff --git a/test/Autofac.Test/TypeExtensionsTests.cs b/test/Autofac.Test/TypeExtensionsTests.cs index 2ecd89e78..18c97a6c4 100644 --- a/test/Autofac.Test/TypeExtensionsTests.cs +++ b/test/Autofac.Test/TypeExtensionsTests.cs @@ -133,14 +133,14 @@ private class DeclaredConstructorType { // Values here to ensure constructors get used and not // optimized out by the compiler. - private static readonly Guid StaticValue; + private static readonly Guid _staticValue; private readonly Guid _instanceValue; [SuppressMessage("CA1810", "CA1810", Justification = "Static constructor for test purposes.")] static DeclaredConstructorType() { - StaticValue = Guid.NewGuid(); + _staticValue = Guid.NewGuid(); } public DeclaredConstructorType() @@ -192,16 +192,34 @@ private static void PrivateStaticMethod() private class DeclaredPropertyType { - public string PublicInstanceProperty { get; set; } + public string PublicInstanceProperty + { + get; set; + } - protected string ProtectedInstanceProperty { get; set; } + protected string ProtectedInstanceProperty + { + get; set; + } - private string PrivateInstanceProperty { get; set; } + private string PrivateInstanceProperty + { + get; set; + } - public static string PublicStaticProperty { get; set; } + public static string PublicStaticProperty + { + get; set; + } - protected static string ProtectedStaticProperty { get; set; } + protected static string ProtectedStaticProperty + { + get; set; + } - private static string PrivateStaticProperty { get; set; } + private static string PrivateStaticProperty + { + get; set; + } } } diff --git a/test/Autofac.Test/TypedParameterTests.cs b/test/Autofac.Test/TypedParameterTests.cs index ef32276a8..80235555c 100644 --- a/test/Autofac.Test/TypedParameterTests.cs +++ b/test/Autofac.Test/TypedParameterTests.cs @@ -31,7 +31,7 @@ public void MatchesIdenticallyTypedParameter() using var container = Factory.CreateEmptyContainer(); - Assert.True(typedParam.CanSupplyValue(param, container, out Func vp)); + Assert.True(typedParam.CanSupplyValue(param, container, out var vp)); } private static ParameterInfo AParamOfCConstructor() @@ -53,7 +53,7 @@ public void DoesNotMatchPolymorphicallyTypedParameter() var typedParam = new TypedParameter(typeof(B), new B()); using var container = Factory.CreateEmptyContainer(); - Assert.False(typedParam.CanSupplyValue(param, container, out Func vp)); + Assert.False(typedParam.CanSupplyValue(param, container, out var vp)); } [Fact] @@ -64,7 +64,7 @@ public void DoesNotMatchUnrelatedParameter() var typedParam = new TypedParameter(typeof(string), "Yo!"); using var container = Factory.CreateEmptyContainer(); - Assert.False(typedParam.CanSupplyValue(param, container, out Func vp)); + Assert.False(typedParam.CanSupplyValue(param, container, out var vp)); } [Fact] diff --git a/test/Autofac.Test/Util/AsyncDisposeTracker.cs b/test/Autofac.Test/Util/AsyncDisposeTracker.cs index 8defe1562..230d32686 100644 --- a/test/Autofac.Test/Util/AsyncDisposeTracker.cs +++ b/test/Autofac.Test/Util/AsyncDisposeTracker.cs @@ -9,9 +9,15 @@ public sealed class AsyncDisposeTracker : IDisposable, IAsyncDisposable public event EventHandler Disposing; - public bool IsSyncDisposed { get; set; } + public bool IsSyncDisposed + { + get; set; + } - public bool IsAsyncDisposed { get; set; } + public bool IsAsyncDisposed + { + get; set; + } public AsyncDisposeTracker() : this(null) diff --git a/test/Autofac.Test/Util/AsyncOnlyDisposeTracker.cs b/test/Autofac.Test/Util/AsyncOnlyDisposeTracker.cs index 26308184b..74f36813f 100644 --- a/test/Autofac.Test/Util/AsyncOnlyDisposeTracker.cs +++ b/test/Autofac.Test/Util/AsyncOnlyDisposeTracker.cs @@ -7,7 +7,10 @@ public class AsyncOnlyDisposeTracker : IAsyncDisposable { public event EventHandler Disposing; - public bool IsAsyncDisposed { get; set; } + public bool IsAsyncDisposed + { + get; set; + } public async ValueTask DisposeAsync() { diff --git a/test/Autofac.Test/Util/Cache/ReflectionCacheParameterDictionaryTests.cs b/test/Autofac.Test/Util/Cache/ReflectionCacheParameterDictionaryTests.cs index 50bd4ed13..0776d2914 100644 --- a/test/Autofac.Test/Util/Cache/ReflectionCacheParameterDictionaryTests.cs +++ b/test/Autofac.Test/Util/Cache/ReflectionCacheParameterDictionaryTests.cs @@ -9,7 +9,7 @@ namespace Autofac.Test.Util.Cache; public class ReflectionCacheParameterDictionaryTests { - private static readonly ParameterInfo SampleParameter = typeof(ParameterOwner) + private static readonly ParameterInfo _sampleParameter = typeof(ParameterOwner) .GetMethod(nameof(ParameterOwner.Method), BindingFlags.Public | BindingFlags.Static)! .GetParameters() .Single(); @@ -46,12 +46,12 @@ public void Clear_PredicateDoesNotMatch() { var cache = new ReflectionCacheParameterDictionary { - [SampleParameter] = true, + [_sampleParameter] = true, }; cache.Clear((_, _) => false); - Assert.True(cache.ContainsKey(SampleParameter)); + Assert.True(cache.ContainsKey(_sampleParameter)); } [Fact] @@ -59,12 +59,12 @@ public void Clear_PredicateMatchesMember() { var cache = new ReflectionCacheParameterDictionary { - [SampleParameter] = true, + [_sampleParameter] = true, }; - cache.Clear((member, _) => member == SampleParameter.Member); + cache.Clear((member, _) => member == _sampleParameter.Member); - Assert.False(cache.ContainsKey(SampleParameter)); + Assert.False(cache.ContainsKey(_sampleParameter)); } private static class ParameterOwner diff --git a/test/Autofac.Test/Util/Cache/TypeAssemblyReferenceProviderTests.cs b/test/Autofac.Test/Util/Cache/TypeAssemblyReferenceProviderTests.cs index 1c6bf6432..c9a0d7dc2 100644 --- a/test/Autofac.Test/Util/Cache/TypeAssemblyReferenceProviderTests.cs +++ b/test/Autofac.Test/Util/Cache/TypeAssemblyReferenceProviderTests.cs @@ -80,6 +80,9 @@ public GenericDerivedClass(Service defaultService, SimpleActivatorData activator private class PropertyOwner { - public string Property { get; set; } + public string Property + { + get; set; + } } } diff --git a/test/Autofac.Test/Util/DisposeTracker.cs b/test/Autofac.Test/Util/DisposeTracker.cs index f7ac4864f..2b35cbd28 100644 --- a/test/Autofac.Test/Util/DisposeTracker.cs +++ b/test/Autofac.Test/Util/DisposeTracker.cs @@ -7,7 +7,10 @@ public class DisposeTracker : IDisposable { public event EventHandler Disposing; - public bool IsDisposed { get; set; } + public bool IsDisposed + { + get; set; + } protected virtual void Dispose(bool disposing) {