diff --git a/.gitignore b/.gitignore index 9de2df6..d82f9ce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # Project specific files artifacts/ +BenchmarkDotNet.Artifacts/ # User-specific files *.suo @@ -108,7 +109,6 @@ publish/ *.pubxml # NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line packages/ # Windows Azure Build Output @@ -133,6 +133,7 @@ node_modules/ bower_components/ wwwroot/ project.lock.json +*.Designer.cs # RIA/Silverlight projects Generated_Code/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8066618..2f72bc6 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: "e72a3ca1632f0b11a07d171449fe447a7ff6795e" # frozen: v0.48.0 + rev: "5b5dddc4fb0f83c3ea1fc5616fa63e115dce83e0" # frozen: v0.49.1 hooks: - id: markdownlint args: - --fix - repo: https://github.com/tillig/json-sort-cli - rev: "2b7e147e0933bd30b58133b6f287e5c695ff4f0e" # frozen: v3.0.1 + rev: "f628ee730c3de493fe79688696555a31364f0a10" # frozen: v3.0.3 hooks: - id: json-sort args: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index b5177ea..7d7c161 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,7 @@ "recommendations": [ "davidanson.vscode-markdownlint", "editorconfig.editorconfig", - "ms-dotnettools.csharp" + "ms-dotnettools.csdevkit", + "travisillig.vscode-json-stable-stringify" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index f7754b1..ce15253 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,30 @@ "autofac", "xunit" ], - "omnisharp.enableEditorConfigSupport": true + "coverage-gutters.coverageBaseDir": "artifacts/logs", + "coverage-gutters.coverageFileNames": [ + "**/coverage.cobertura.xml" + ], + "dotnet.defaultSolution": "Autofac.Extras.AttributeMetadata.sln", + "dotnet.unitTestDebuggingOptions": { + "enableStepFiltering": false, + "justMyCode": false, + "requireExactSource": false, + "sourceLinkOptions": { + "*": { + "enabled": true + } + }, + "suppressJITOptimizations": true, + "symbolOptions": { + "searchNuGetOrgSymbolServer": true + } + }, + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "*.resx": "$(capture).*.resx, $(capture).designer.cs, $(capture).designer.vb" + }, + "files.watcherExclude": { + "**/target": true + } } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 94d81fc..7c2253f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,9 +1,37 @@ { + "linux": { + "options": { + "shell": { + "args": [ + "-NoProfile", + "-Command" + ], + "executable": "pwsh" + } + } + }, + "osx": { + "options": { + "shell": { + "args": [ + "-NoProfile", + "-Command" + ], + "executable": "/usr/local/bin/pwsh" + } + } + }, "tasks": [ + { + "command": "If (Test-Path ${workspaceFolder}/artifacts/logs) { Remove-Item ${workspaceFolder}/artifacts/logs -Recurse -Force }; New-Item -Path ${workspaceFolder}/artifacts/logs -ItemType Directory -Force | Out-Null", + "label": "create log directory", + "type": "shell" + }, { "args": [ "build", - "Autofac.Extras.AttributeMetadata.sln", + "${workspaceFolder}/Autofac.Extras.AttributeMetadata.sln", + "--tl:off", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -13,12 +41,48 @@ "kind": "build" }, "label": "build", - "presentation": { - "reveal": "silent" - }, "problemMatcher": "$msCompile", "type": "shell" + }, + { + "args": [ + "test", + "${workspaceFolder}/Autofac.Extras.AttributeMetadata.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + "--results-directory", + "artifacts/logs", + "--logger:trx", + "--collect:XPlat Code Coverage", + "--settings:build/Coverage.runsettings", + "--filter", + "FullyQualifiedName!~Bench" + ], + "command": "dotnet", + "dependsOn": [ + "create log directory" + ], + "group": { + "isDefault": true, + "kind": "test" + }, + "label": "test", + "problemMatcher": "$msCompile", + "type": "process" } ], - "version": "2.0.0" + "version": "2.0.0", + "windows": { + "options": { + "shell": { + "args": [ + "-NoProfile", + "-ExecutionPolicy", + "Bypass", + "-Command" + ], + "executable": "pwsh.exe" + } + } + } } diff --git a/LICENSE b/LICENSE index 5f727f7..e89fb63 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Autofac Project +Copyright © 2014 Autofac Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ddb2e33..a272c35 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,62 @@ Attribute metadata support for Autofac IoC -[![Build status](https://github.com/autofac/Autofac.Extras.AttributeMetadata/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/autofac/Autofac.Extras.AttributeMetadata/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/Autofac/Autofac.Extras.AttributeMetadata/branch/develop/graph/badge.svg)](https://codecov.io/gh/Autofac/Autofac.Extras.AttributeMetadata) [![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/autofac/Autofac.Extras.AttributeMetadata) +[![Build status](https://github.com/autofac/Autofac.Extras.AttributeMetadata/actions/workflows/main.yml/badge.svg)](https://github.com/autofac/Autofac.Extras.AttributeMetadata/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Autofac/Autofac.Extras.AttributeMetadata/branch/develop/graph/badge.svg)](https://codecov.io/gh/Autofac/Autofac.Extras.AttributeMetadata) [![NuGet](https://img.shields.io/nuget/v/Autofac.Extras.AttributeMetadata.svg)](https://nuget.org/packages/Autofac.Extras.AttributeMetadata) Please file issues and pull requests for this package in this repository rather than in the Autofac core repo. - [Documentation](https://autofac.readthedocs.io/en/latest/advanced/metadata.html) - [NuGet](https://www.nuget.org/packages/Autofac.Extras.AttributeMetadata) - [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html) +- [Open in Visual Studio Code](https://open.vscode.dev/autofac/Autofac.Extras.AttributeMetadata) + +## Quick Start + +First, create a metadata attribute - any `System.Attribute` that has MEF's `[MetadataAttribute]` applied. Every publicly readable property becomes one metadata name/value pair, so the attribute below provides `Age` metadata: + +```csharp +[MetadataAttribute] +public class AgeMetadataAttribute : Attribute +{ + public int Age { get; private set; } + + public AgeMetadataAttribute(int age) + { + Age = age; + } +} +``` + +Apply it to the component implementation rather than to the service interface: + +```csharp +public interface IArtwork +{ + void Display(); +} + +[AgeMetadata(100)] +public class CenturyArtwork : IArtwork +{ + public void Display() { ... } +} +``` + +Then register the `AttributedMetadataModule` so the container reads those attributes, and consume the metadata as you would any other: + +```csharp +var builder = new ContainerBuilder(); +builder.RegisterModule(); +builder.RegisterType().As(); +var container = builder.Build(); + +var artwork = container.Resolve>>() + .First(a => a.Metadata["Age"].Equals(100)); +artwork.Value.Display(); +``` + +[You can read more details in the documentation.](https://autofac.readthedocs.io/en/latest/advanced/metadata.html) + +## Get Help + +**Need help with Autofac?** We have [a documentation site](https://autofac.readthedocs.io/) as well as [API documentation](https://autofac.org/apidoc/). We're ready to answer your questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/autofac) or check out the [discussion forum](https://groups.google.com/forum/#forum/autofac). diff --git a/codecov.yml b/codecov.yml index e77200d..4bca0d7 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,6 +1,6 @@ codecov: branch: develop - require_ci_to_pass: yes + require_ci_to_pass: true coverage: status: project: diff --git a/global.json b/global.json index 513d0b4..be5c6cf 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestFeature", - "version": "10.0.203" + "version": "10.0.302" } } diff --git a/src/Autofac.Extras.AttributeMetadata/Autofac.Extras.AttributeMetadata.csproj b/src/Autofac.Extras.AttributeMetadata/Autofac.Extras.AttributeMetadata.csproj index b1ff173..15fce81 100644 --- a/src/Autofac.Extras.AttributeMetadata/Autofac.Extras.AttributeMetadata.csproj +++ b/src/Autofac.Extras.AttributeMetadata/Autofac.Extras.AttributeMetadata.csproj @@ -1,61 +1,81 @@  - + + Autofac.Extras.AttributeMetadata + Autofac.Extras.AttributeMetadata Autofac allows you to register metadata along with dependencies for additional resolution flexibility. This extension enables that metadata to be registered through attributes. + Copyright © 2015 Autofac Contributors + Autofac Contributors + Autofac + Autofac + ../../Autofac.snk + true + en-US + net10.0;net8.0;netstandard2.1;netstandard2.0 latest - $(NoWarn);IDE0008 + enable true - Autofac.Extras.AttributeMetadata - ../../Autofac.snk - true + ../../build/Source.ruleset + true + AllEnabledByDefault + enable + Autofac.Extras.AttributeMetadata autofac;di;ioc;dependencyinjection;aspnet;aspnetcore Release notes are at https://github.com/autofac/Autofac.Extras.AttributeMetadata/releases icon.png https://autofac.org MIT + README.md git https://github.com/autofac/Autofac.Extras.AttributeMetadata - Autofac.Extras.AttributeMetadata - en-US - Copyright © 2015 Autofac Contributors - ../../build/Source.ruleset - AllEnabledByDefault - true + true true true - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - $(Features);IOperation - Autofac Contributors - Autofac - Autofac - enable + true + snupkg + + PrepareResources;$(CompileDependsOn) - + + + + - - - - - All - - + + + all - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + all + + + + + + MSBuild:Compile + CSharp + $(IntermediateOutputPath)%(Filename).Designer.cs + %(Filename) + + + + + Autofac.Extras.AttributeMetadata + - <_Parameter1>$(AssemblyName).Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001008728425885ef385e049261b18878327dfaaf0d666dea3bd2b0e4f18b33929ad4e5fbc9087e7eda3c1291d2de579206d9b4292456abffbe8be6c7060b36da0c33b883e3878eaf7c89fddf29e6e27d24588e81e86f3a22dd7b1a296b5f06fbfb500bbd7410faa7213ef4e2ce7622aefc03169b0324bcd30ccfe9ac8204e4960be6 diff --git a/src/Autofac.Extras.AttributeMetadata/IMetadataProvider.cs b/src/Autofac.Extras.AttributeMetadata/IMetadataProvider.cs index 4606a59..c5daa78 100644 --- a/src/Autofac.Extras.AttributeMetadata/IMetadataProvider.cs +++ b/src/Autofac.Extras.AttributeMetadata/IMetadataProvider.cs @@ -49,5 +49,5 @@ public interface IMetadataProvider /// /// Target for which metadata should be retrieved. /// Metadata dictionary to merge with existing metadata. - IDictionary GetMetadata(Type targetType); + IDictionary GetMetadata(Type targetType); } diff --git a/src/Autofac.Extras.AttributeMetadata/IMetadataRegistrar{TInterface,TMetadata}.cs b/src/Autofac.Extras.AttributeMetadata/IMetadataRegistrar{TInterface,TMetadata}.cs index b681205..565914a 100644 --- a/src/Autofac.Extras.AttributeMetadata/IMetadataRegistrar{TInterface,TMetadata}.cs +++ b/src/Autofac.Extras.AttributeMetadata/IMetadataRegistrar{TInterface,TMetadata}.cs @@ -15,7 +15,7 @@ public interface IMetadataRegistrar /// /// Gets the builder used to build an from component registrations. /// - ContainerBuilder ContainerBuilder + ContainerBuilder? ContainerBuilder { get; } diff --git a/src/Autofac.Extras.AttributeMetadata/MetadataHelper.cs b/src/Autofac.Extras.AttributeMetadata/MetadataHelper.cs index 101303f..e18f257 100644 --- a/src/Autofac.Extras.AttributeMetadata/MetadataHelper.cs +++ b/src/Autofac.Extras.AttributeMetadata/MetadataHelper.cs @@ -23,7 +23,7 @@ public static class MetadataHelper /// /// Thrown if or is . /// - public static IEnumerable> GetProperties(object target, Type instanceType) + public static IEnumerable> GetProperties(object target, Type instanceType) { if (target == null) { @@ -47,7 +47,7 @@ public static IEnumerable> GetProperties(object tar propertyInfo.DeclaringType != null && propertyInfo.DeclaringType.Name != typeof(Attribute).Name) .Select(propertyInfo => - new KeyValuePair(propertyInfo.Name, propertyInfo.GetValue(target, null))); + new KeyValuePair(propertyInfo.Name, propertyInfo.GetValue(target, null))); } /// @@ -58,14 +58,14 @@ public static IEnumerable> GetProperties(object tar /// /// Thrown if is . /// - public static IEnumerable> GetMetadata(Type targetType) + public static IEnumerable> GetMetadata(Type targetType) { if (targetType == null) { throw new ArgumentNullException(nameof(targetType)); } - var propertyList = new List>(); + var propertyList = new List>(); foreach (var attribute in targetType.GetCustomAttributes(true) .Where(p => p.GetType().GetCustomAttributes(typeof(MetadataAttributeAttribute), true).Length > 0)) @@ -87,7 +87,7 @@ public static IEnumerable> GetMetadata(Type targetT /// /// Thrown if is . /// - public static IEnumerable> GetMetadata(Type targetType) + public static IEnumerable> GetMetadata(Type targetType) { if (targetType == null) { @@ -96,6 +96,6 @@ public static IEnumerable> GetMetadata>(); + return attribute != null ? GetProperties(attribute, targetType) : new List>(); } } diff --git a/src/Autofac.Extras.AttributeMetadata/MetadataModuleResources.resx b/src/Autofac.Extras.AttributeMetadata/MetadataModuleResources.resx new file mode 100644 index 0000000..acc82e0 --- /dev/null +++ b/src/Autofac.Extras.AttributeMetadata/MetadataModuleResources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ContainerBuilder is not initialized. Ensure that the Load method has been called. + + diff --git a/src/Autofac.Extras.AttributeMetadata/MetadataModule{TInterface,TMetadata}.cs b/src/Autofac.Extras.AttributeMetadata/MetadataModule{TInterface,TMetadata}.cs index e6834dd..0011daf 100644 --- a/src/Autofac.Extras.AttributeMetadata/MetadataModule{TInterface,TMetadata}.cs +++ b/src/Autofac.Extras.AttributeMetadata/MetadataModule{TInterface,TMetadata}.cs @@ -12,13 +12,18 @@ namespace Autofac.Extras.AttributeMetadata; /// Interface used on concrete types of metadata decorated instances. /// Strongly typed metadata definition. public abstract class MetadataModule : Module, IMetadataRegistrar + where TInterface : notnull { /// /// Gets the builder used to build an from component registrations. /// - public ContainerBuilder ContainerBuilder + /// + /// The builder used during that can be used to register types and metadata. + /// + public ContainerBuilder? ContainerBuilder { - get; private set; + get; + private set; } /// @@ -35,11 +40,22 @@ public ContainerBuilder ContainerBuilder /// /// The registration for continued configuration. /// - public IRegistrationBuilder - RegisterType(TMetadata metadata) + public IRegistrationBuilder RegisterType(TMetadata metadata) where TInstance : TInterface - => ContainerBuilder.RegisterType().As().WithMetadata( + { + if (metadata is null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + if (ContainerBuilder is null) + { + throw new InvalidOperationException(MetadataModuleResources.ContainerBuilderNotInitialized); + } + + return ContainerBuilder.RegisterType().As().WithMetadata( MetadataHelper.GetProperties(metadata, typeof(TInstance))); + } /// /// registers provided metadata on the declared type. @@ -49,10 +65,26 @@ public IRegistrationBuilder /// The registration for continued configuration. /// - public IRegistrationBuilder RegisterType( - Type instanceType, TMetadata metadata) - => ContainerBuilder.RegisterType(instanceType).As().WithMetadata( + public IRegistrationBuilder RegisterType(Type instanceType, TMetadata metadata) + { + if (instanceType is null) + { + throw new ArgumentNullException(nameof(instanceType)); + } + + if (metadata is null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + if (ContainerBuilder is null) + { + throw new InvalidOperationException(MetadataModuleResources.ContainerBuilderNotInitialized); + } + + return ContainerBuilder.RegisterType(instanceType).As().WithMetadata( MetadataHelper.GetProperties(metadata, instanceType)); + } /// /// Registers the provided concrete instance and scans it for generic metadata attribute data. @@ -61,11 +93,17 @@ public IRegistrationBuilder /// The registration for continued configuration. /// - public IRegistrationBuilder - RegisterAttributedType() + public IRegistrationBuilder RegisterAttributedType() where TInstance : TInterface - => ContainerBuilder.RegisterType().As().WithMetadata( + { + if (ContainerBuilder is null) + { + throw new InvalidOperationException(MetadataModuleResources.ContainerBuilderNotInitialized); + } + + return ContainerBuilder.RegisterType().As().WithMetadata( MetadataHelper.GetMetadata(typeof(TInstance))); + } /// /// Registers the provided concrete instance type and scans it for generate metadata data. @@ -74,10 +112,16 @@ public IRegistrationBuilder /// The registration for continued configuration. /// - public IRegistrationBuilder - RegisterAttributedType(Type instanceType) - => ContainerBuilder.RegisterType(instanceType).As().WithMetadata( + public IRegistrationBuilder RegisterAttributedType(Type instanceType) + { + if (ContainerBuilder is null) + { + throw new InvalidOperationException(MetadataModuleResources.ContainerBuilderNotInitialized); + } + + return ContainerBuilder.RegisterType(instanceType).As().WithMetadata( MetadataHelper.GetMetadata(instanceType)); + } /// /// Standard module method being overridden and sealed to provide wrapped metadata registration. diff --git a/src/Autofac.Extras.AttributeMetadata/ParameterFilterAttribute.cs b/src/Autofac.Extras.AttributeMetadata/ParameterFilterAttribute.cs index 3749239..db401b1 100644 --- a/src/Autofac.Extras.AttributeMetadata/ParameterFilterAttribute.cs +++ b/src/Autofac.Extras.AttributeMetadata/ParameterFilterAttribute.cs @@ -48,5 +48,5 @@ protected ParameterFilterAttribute() /// The specific parameter being resolved that is marked with this attribute. /// The component context under which the parameter is being resolved. /// The instance of the object that should be used for the parameter value. - public abstract object ResolveParameter(ParameterInfo parameter, IComponentContext context); + public abstract object? ResolveParameter(ParameterInfo parameter, IComponentContext context); } diff --git a/src/Autofac.Extras.AttributeMetadata/WithKeyAttribute.cs b/src/Autofac.Extras.AttributeMetadata/WithKeyAttribute.cs index 79392b8..95b65ee 100644 --- a/src/Autofac.Extras.AttributeMetadata/WithKeyAttribute.cs +++ b/src/Autofac.Extras.AttributeMetadata/WithKeyAttribute.cs @@ -109,7 +109,7 @@ public object Key /// /// Thrown if or is . /// - public override object ResolveParameter(ParameterInfo parameter, IComponentContext context) + public override object? ResolveParameter(ParameterInfo parameter, IComponentContext context) { if (parameter == null) { diff --git a/src/Autofac.Extras.AttributeMetadata/WithMetadataAttribute.cs b/src/Autofac.Extras.AttributeMetadata/WithMetadataAttribute.cs index 37ce894..ea5a10c 100644 --- a/src/Autofac.Extras.AttributeMetadata/WithMetadataAttribute.cs +++ b/src/Autofac.Extras.AttributeMetadata/WithMetadataAttribute.cs @@ -1,7 +1,6 @@ // Copyright (c) Autofac Project. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using System.Diagnostics.CodeAnalysis; using System.Reflection; using Autofac.Features.Metadata; @@ -82,13 +81,13 @@ public sealed class WithMetadataAttribute : ParameterFilterAttribute /// Reference to the /// method used in creating a closed generic reference during registration. /// - private static readonly MethodInfo _filterOneInfo = typeof(WithMetadataAttribute).GetMethod("FilterOne", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod); + private static readonly MethodInfo _filterOneInfo = typeof(WithMetadataAttribute).GetMethod("FilterOne", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod)!; /// /// Reference to the /// method used in creating a closed generic reference during registration. /// - private static readonly MethodInfo _filterAllInfo = typeof(WithMetadataAttribute).GetMethod("FilterAll", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod); + private static readonly MethodInfo _filterAllInfo = typeof(WithMetadataAttribute).GetMethod("FilterAll", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod)!; /// /// Initializes a new instance of the class, @@ -145,7 +144,7 @@ public object Value /// /// Thrown if or is . /// - public override object ResolveParameter(ParameterInfo parameter, IComponentContext context) + public override object? ResolveParameter(ParameterInfo parameter, IComponentContext context) { if (parameter == null) { @@ -176,7 +175,7 @@ private static Type GetElementType(Type type) // Using Lazy to ensure components that aren't actually used won't get activated. [SuppressMessage("IDE0051", "IDE0051", Justification = "Method is consumed via reflection in static member variable in this class.")] - private static T FilterOne(IComponentContext context, string metadataKey, object metadataValue) + private static T? FilterOne(IComponentContext context, string metadataKey, object metadataValue) => context.Resolve>>>() .Where(m => m.Metadata.ContainsKey(metadataKey) && metadataValue.Equals(m.Metadata[metadataKey])) .Select(m => m.Value.Value) diff --git a/test/Autofac.Extras.AttributeMetadata.Test/AttributeMetadataModuleTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/AttributeMetadataModuleTestFixture.cs index df67eeb..28df932 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/AttributeMetadataModuleTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/AttributeMetadataModuleTestFixture.cs @@ -3,7 +3,6 @@ using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.NestedLifetimeScopeRegistrationScenario; using Autofac.Features.Metadata; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; @@ -17,7 +16,7 @@ public void Does_not_throw_in_nested_lifetimeScope_builders() builder.RegisterType().As(); var container = builder.Build(); - using (var lifetimeScope = container.BeginLifetimeScope(x => builder.RegisterType())) + using (var lifetimeScope = container.BeginLifetimeScope(x => x.RegisterType())) { var ex = Record.Exception(() => lifetimeScope.Resolve>()); Assert.Null(ex); diff --git a/test/Autofac.Extras.AttributeMetadata.Test/Autofac.Extras.AttributeMetadata.Test.csproj b/test/Autofac.Extras.AttributeMetadata.Test/Autofac.Extras.AttributeMetadata.Test.csproj index df82117..11e2584 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/Autofac.Extras.AttributeMetadata.Test.csproj +++ b/test/Autofac.Extras.AttributeMetadata.Test/Autofac.Extras.AttributeMetadata.Test.csproj @@ -1,49 +1,49 @@  - - net10.0 - $(NoWarn);CS1591;SA1600; + net10.0;net8.0 + $(NoWarn);CS1591 true ../../Autofac.snk true + true ../../build/Test.ruleset AllEnabledByDefault true false latest enable + enable - + + + + + + - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - diff --git a/test/Autofac.Extras.AttributeMetadata.Test/CombinationalWeakTypedAttributeScenarioTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/CombinationalWeakTypedAttributeScenarioTestFixture.cs index a3ed050..8474740 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/CombinationalWeakTypedAttributeScenarioTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/CombinationalWeakTypedAttributeScenarioTestFixture.cs @@ -4,7 +4,6 @@ using System.Reflection; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.CombinationalWeakTypedAttributeScenario; using Autofac.Integration.Mef; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/MetadataHelperTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/MetadataHelperTestFixture.cs index 28af72c..d988cf2 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/MetadataHelperTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/MetadataHelperTestFixture.cs @@ -5,7 +5,6 @@ using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.MetadataModuleScenarioDiscoveryTargets; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.StrongTypedMetadataAttributeScenario; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.WeakTypedMetadataAttributeScenario; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/MetadataModuleTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/MetadataModuleTestFixture.cs index a146982..1e375a3 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/MetadataModuleTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/MetadataModuleTestFixture.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.MetadataModuleScenarioDiscoveryTargets; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/MetadataProviderTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/MetadataProviderTestFixture.cs index 0c0828a..67a69df 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/MetadataProviderTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/MetadataProviderTestFixture.cs @@ -3,7 +3,6 @@ using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.MetadataProviderScenarioTypes; using Autofac.Features.Metadata; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadata.cs b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadata.cs index 2ee70bc..ef20092 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadata.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadata.cs @@ -5,12 +5,12 @@ namespace Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.MetadataProviderSc public class ProvidedMetadata { - public string Key1 + public string? Key1 { get; set; } - public string Key2 + public string? Key2 { get; set; } diff --git a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadataAttribute.cs b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadataAttribute.cs index 6536bfb..957c73c 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadataAttribute.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/MetadataProviderScenario/ProvidedMetadataAttribute.cs @@ -9,9 +9,9 @@ namespace Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.MetadataProviderSc [AttributeUsage(AttributeTargets.Class)] public sealed class ProvidedMetadataAttribute : Attribute, IMetadataProvider { - public IDictionary GetMetadata(Type targetType) + public IDictionary GetMetadata(Type targetType) { - return new Dictionary() + return new Dictionary() { { "Key1", "Value1" }, { "Key2", "Value2" }, diff --git a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/NestedLifetimeScopeRegistrationScenario/NestedLifetimeScopeRegistrationMetadataAttribute.cs b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/NestedLifetimeScopeRegistrationScenario/NestedLifetimeScopeRegistrationMetadataAttribute.cs index e8679da..ef605cd 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/NestedLifetimeScopeRegistrationScenario/NestedLifetimeScopeRegistrationMetadataAttribute.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/ScenarioTypes/NestedLifetimeScopeRegistrationScenario/NestedLifetimeScopeRegistrationMetadataAttribute.cs @@ -9,7 +9,7 @@ namespace Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.NestedLifetimeScop [AttributeUsage(AttributeTargets.Class)] public sealed class NestedLifetimeScopeRegistrationMetadataAttribute : Attribute { - public string Value + public string? Value { get; set; } diff --git a/test/Autofac.Extras.AttributeMetadata.Test/StrongTypedAttributeScenarioTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/StrongTypedAttributeScenarioTestFixture.cs index eee1f68..d4c9a9f 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/StrongTypedAttributeScenarioTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/StrongTypedAttributeScenarioTestFixture.cs @@ -4,7 +4,6 @@ using System.Reflection; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.StrongTypedMetadataAttributeScenario; using Autofac.Integration.Mef; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypeAttributedMetadataModuleTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypeAttributedMetadataModuleTestFixture.cs index 6f8983d..afd1027 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypeAttributedMetadataModuleTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypeAttributedMetadataModuleTestFixture.cs @@ -3,7 +3,6 @@ using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.CombinationalWeakTypedAttributeScenario; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.WeakTypedMetadataAttributeScenario; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedAttributeScenarioTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedAttributeScenarioTestFixture.cs index f83ab01..bcce674 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedAttributeScenarioTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedAttributeScenarioTestFixture.cs @@ -4,7 +4,6 @@ using System.Reflection; using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.WeakTypedMetadataAttributeScenario; using Autofac.Integration.Mef; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedScenarioMetadataModuleTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedScenarioMetadataModuleTestFixture.cs index 2928c92..457955e 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedScenarioMetadataModuleTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/WeakTypedScenarioMetadataModuleTestFixture.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.WeakTypedMetadataAttributeScenario; -using Xunit; namespace Autofac.Extras.AttributeMetadata.Test; diff --git a/test/Autofac.Extras.AttributeMetadata.Test/WithAttributeFilterTestFixture.cs b/test/Autofac.Extras.AttributeMetadata.Test/WithAttributeFilterTestFixture.cs index 8c5e939..e3964e7 100644 --- a/test/Autofac.Extras.AttributeMetadata.Test/WithAttributeFilterTestFixture.cs +++ b/test/Autofac.Extras.AttributeMetadata.Test/WithAttributeFilterTestFixture.cs @@ -5,7 +5,6 @@ using System.ComponentModel.Composition; using Autofac.Features.Metadata; using Autofac.Features.OwnedInstances; -using Xunit; #pragma warning disable CS0618 @@ -263,7 +262,7 @@ public class ToolWindowAdapter : IAdapter public class IdentifiableObject { - public string Id + public string? Id { get; set; } @@ -463,7 +462,7 @@ public string Target get; internal set; } - public IDictionary Metadata + public IDictionary? Metadata { get; }