diff --git a/AppCoreNet.Extensions.sln b/AppCoreNet.Extensions.sln
index 1ad7ff6..0b9d93d 100644
--- a/AppCoreNet.Extensions.sln
+++ b/AppCoreNet.Extensions.sln
@@ -109,6 +109,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
stylecop.json = stylecop.json
Directory.Packages.props = Directory.Packages.props
NuGet.config = NuGet.config
+ renovate.json = renovate.json
EndProjectSection
EndProject
Global
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ActivatorExtensions.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ActivatorExtensions.cs
index 9810b12..c3f56c2 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ActivatorExtensions.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ActivatorExtensions.cs
@@ -2,6 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
namespace AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -19,7 +20,9 @@ public static class ActivatorExtensions
/// Constructor arguments not provided by the .
/// An activated object of type .
/// Argument is null.
- public static T? CreateInstance(this IActivator activator, params object[] parameters)
+ public static T? CreateInstance<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(
+ this IActivator activator,
+ params object[] parameters)
{
Ensure.Arg.NotNull(activator);
return (T?)activator.CreateInstance(typeof(T), parameters);
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/DefaultActivator.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/DefaultActivator.cs
index 8920cbb..a456605 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/DefaultActivator.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/DefaultActivator.cs
@@ -2,6 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
namespace AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -17,7 +18,9 @@ public sealed class DefaultActivator : IActivator
public static DefaultActivator Instance { get; } = new();
///
- public object? CreateInstance(Type instanceType, params object[] parameters)
+ public object? CreateInstance(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type instanceType,
+ params object[] parameters)
{
Ensure.Arg.NotNull(instanceType);
Ensure.Arg.NotNull(parameters);
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/IActivator.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/IActivator.cs
index 9b6963f..bb7f7f4 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/IActivator.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/IActivator.cs
@@ -2,6 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
namespace AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -17,5 +18,7 @@ public interface IActivator
/// Constructor arguments not provided by the .
/// An activated object of type .
/// Argument or is null.
- object? CreateInstance(Type instanceType, params object[] parameters);
+ object? CreateInstance(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type instanceType,
+ params object[] parameters);
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ServiceProviderActivator.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ServiceProviderActivator.cs
index 6ec0369..6adf569 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ServiceProviderActivator.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Activator/ServiceProviderActivator.cs
@@ -2,6 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
@@ -26,7 +27,9 @@ public ServiceProviderActivator(IServiceProvider serviceProvider)
}
///
- public object? CreateInstance(Type instanceType, params object[] parameters)
+ public object? CreateInstance(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type instanceType,
+ params object[] parameters)
{
return ActivatorUtilities.CreateInstance(_serviceProvider, instanceType, parameters);
}
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/AppCoreNet.Extensions.DependencyInjection.Abstractions.csproj b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/AppCoreNet.Extensions.DependencyInjection.Abstractions.csproj
index 071ba02..99ae7b7 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/AppCoreNet.Extensions.DependencyInjection.Abstractions.csproj
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/AppCoreNet.Extensions.DependencyInjection.Abstractions.csproj
@@ -4,6 +4,7 @@
net8.0;netstandard2.0;net462
AppCoreNet.Extensions.DependencyInjection
Provides extensions to the Microsoft.Extensions.DependencyInjection framework.
+ true
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder.cs
index 89ff314..e98604a 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder.cs
@@ -2,7 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
-using System.Linq;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
using Microsoft.Extensions.DependencyInjection;
@@ -12,7 +12,7 @@ namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
///
/// Provides a builder for facilities.
///
-public class FacilityBuilder
+public sealed class FacilityBuilder
{
///
/// Gets the .
@@ -36,35 +36,23 @@ internal FacilityBuilder(IServiceCollection services, IActivator activator, Type
FacilityType = facilityType;
}
- private IFacilityExtension CreateExtension(Type extensionType)
- {
- Type contractType = extensionType.GetInterfaces()
- .First(i => i.GetGenericTypeDefinition() == typeof(IFacilityExtension<>))
- .GenericTypeArguments[0];
-
- Type extensionWrapperType = typeof(FacilityExtensionWrapper<>).MakeGenericType(contractType);
- object extension = Activator.CreateInstance(extensionType)!;
-
- return (IFacilityExtension)System.Activator.CreateInstance(extensionWrapperType, extension)!;
- }
-
///
/// Adds an extension to the facility.
///
///
- /// The type must implement with the
- /// type of the facility.
+ /// The type must implement .
///
/// The type of the extension.
/// The to allow chaining.
/// Argument is null.
- /// Argument does not implement with the type of the facility.
- public FacilityBuilder AddExtension(Type extensionType)
+ /// Argument does not implement with the type of the facility.
+ public FacilityBuilder AddExtension(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type extensionType)
{
Ensure.Arg.NotNull(extensionType);
- Ensure.Arg.OfType(extensionType, typeof(IFacilityExtension<>).MakeGenericType(FacilityType));
+ Ensure.Arg.OfType(extensionType);
- IFacilityExtension extension = CreateExtension(extensionType);
+ var extension = (IFacilityExtension)Activator.CreateInstance(extensionType)!;
extension.ConfigureServices(Services);
return this;
}
@@ -82,7 +70,7 @@ public FacilityBuilder AddExtensionsFrom(Action extension in reflectionBuilder.Resolve(FacilityType))
+ foreach (IFacilityExtension extension in reflectionBuilder.Resolve(FacilityType))
{
extension.ConfigureServices(Services);
}
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder{T}.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder{T}.cs
index 15f0017..eaccf86 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder{T}.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityBuilder{T}.cs
@@ -2,7 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
-using System.Linq;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
using Microsoft.Extensions.DependencyInjection;
@@ -13,12 +13,23 @@ namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
/// Provides a builder for facilities.
///
/// The type of the facility.
-public sealed class FacilityBuilder : FacilityBuilder
+public sealed class FacilityBuilder
where T : IFacility
{
+ ///
+ /// Gets the .
+ ///
+ public IServiceCollection Services { get; }
+
+ ///
+ /// Gets the .
+ ///
+ public IActivator Activator { get; }
+
internal FacilityBuilder(IServiceCollection services, IActivator activator)
- : base(services, activator, typeof(T))
{
+ Services = services;
+ Activator = activator;
}
///
@@ -32,9 +43,13 @@ internal FacilityBuilder(IServiceCollection services, IActivator activator)
/// The to allow chaining.
/// Argument is null.
/// Argument does not implement with the type of the facility.
- public new FacilityBuilder AddExtension(Type extensionType)
+ public FacilityBuilder AddExtension(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type extensionType)
{
- base.AddExtension(extensionType);
+ Ensure.Arg.OfType>(extensionType);
+
+ var extension = (IFacilityExtension)Activator.CreateInstance(extensionType)!;
+ extension.ConfigureServices(Services);
return this;
}
@@ -43,7 +58,8 @@ internal FacilityBuilder(IServiceCollection services, IActivator activator)
///
/// The type of the extension.
/// The to allow chaining.
- public FacilityBuilder AddExtension()
+ public FacilityBuilder AddExtension<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TExtension>()
where TExtension : class, IFacilityExtension
{
IFacilityExtension extension = Activator.CreateInstance()!;
@@ -65,14 +81,24 @@ public FacilityBuilder AddExtension(IFacilityExtension extension)
}
///
- /// Adds facility extensions using a to the .
+ /// Adds facility extensions using a to the
+ /// .
///
/// The delegate used to configure the facility extension resolvers.
/// The .
/// Argument is null.
- public new FacilityBuilder AddExtensionsFrom(Action configure)
+ public FacilityBuilder AddExtensionsFrom(Action configure)
{
- base.AddExtensionsFrom(configure);
+ Ensure.Arg.NotNull(configure);
+
+ var reflectionBuilder = new FacilityExtensionReflectionBuilder(Activator);
+ configure(reflectionBuilder);
+
+ foreach (IFacilityExtension extension in reflectionBuilder.Resolve(typeof(T)))
+ {
+ extension.ConfigureServices(Services);
+ }
+
return this;
}
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionReflectionBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionReflectionBuilder.cs
index 07d2f43..32fa414 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionReflectionBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionReflectionBuilder.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -26,7 +27,8 @@ public IFacilityExtensionReflectionBuilder AddResolver(IFacilityExtensionResolve
return this;
}
- public IFacilityExtensionReflectionBuilder AddResolver(Action? configure = null)
+ public IFacilityExtensionReflectionBuilder AddResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(Action? configure = null)
where T : IFacilityExtensionResolver
{
var resolver = _activator.CreateInstance()!;
@@ -34,13 +36,9 @@ public IFacilityExtensionReflectionBuilder AddResolver(Action? configure =
return AddResolver(resolver);
}
- public IReadOnlyCollection> Resolve(Type facilityType)
+ public IReadOnlyCollection Resolve(Type facilityType)
{
- Type[] facilityTypes = facilityType.GetTypesAssignableFrom()
- .Where(t => t.GetInterfaces().Contains(typeof(IFacility)))
- .ToArray();
-
- return _resolvers.SelectMany(s => facilityTypes.SelectMany(s.Resolve))
+ return _resolvers.SelectMany(s => s.Resolve(facilityType))
.ToList()
.AsReadOnly();
}
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionWrapper.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionWrapper.cs
deleted file mode 100644
index 57df949..0000000
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtensionWrapper.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Licensed under the MIT license.
-// Copyright (c) The AppCore .NET project.
-
-using Microsoft.Extensions.DependencyInjection;
-
-namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
-
-internal sealed class FacilityExtensionWrapper : IFacilityExtension
- where TContract : IFacility
-{
- private readonly IFacilityExtension _extension;
-
- public FacilityExtensionWrapper(IFacilityExtension extension)
- {
- _extension = extension;
- }
-
- public void ConfigureServices(IServiceCollection services)
- {
- _extension.ConfigureServices(services);
- }
-}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityReflectionBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityReflectionBuilder.cs
index 9e4072c..6b5441f 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityReflectionBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/FacilityReflectionBuilder.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
@@ -28,7 +29,8 @@ public IFacilityReflectionBuilder AddResolver(IFacilityResolver resolver)
return this;
}
- public IFacilityReflectionBuilder AddResolver(Action? configure = null)
+ public IFacilityReflectionBuilder AddResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(Action? configure = null)
where T : IFacilityResolver
{
var resolver = _activator.CreateInstance()!;
@@ -43,7 +45,7 @@ public IFacilityReflectionBuilder AddExtensionsFrom(Action>
+ public IReadOnlyCollection<(IFacility Facility, IReadOnlyCollection
FacilityExtensions)> Resolve()
{
List facilities =
@@ -58,15 +60,15 @@ public IFacilityReflectionBuilder AddExtensionsFrom(Action> emptyFacilityExtensions =
- new List>().AsReadOnly();
+ ReadOnlyCollection emptyFacilityExtensions =
+ new List().AsReadOnly();
- List<(IFacility Facility, IReadOnlyCollection> FacilityExtensions)> result =
+ List<(IFacility Facility, IReadOnlyCollection FacilityExtensions)> result =
new();
foreach (IFacility facility in facilities)
{
- IReadOnlyCollection> facilityExtensions =
+ IReadOnlyCollection facilityExtensions =
extensionReflectionBuilder?.Resolve(facility.GetType())
?? emptyFacilityExtensions;
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtension.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtension.cs
index 71d16b7..c021b1f 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtension.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtension.cs
@@ -8,13 +8,20 @@ namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
///
/// Represents an extension for a facility.
///
-/// The type of the facility.
-public interface IFacilityExtension
- where T : IFacility
+public interface IFacilityExtension
{
///
/// Must be implemented to register services with the .
///
/// The .
void ConfigureServices(IServiceCollection services);
+}
+
+///
+/// Represents an extension for a facility.
+///
+/// The type of the facility.
+public interface IFacilityExtension : IFacilityExtension
+ where T : IFacility
+{
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionReflectionBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionReflectionBuilder.cs
index 3d87408..c08c4cd 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionReflectionBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionReflectionBuilder.cs
@@ -3,6 +3,7 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
@@ -27,6 +28,7 @@ public interface IFacilityExtensionReflectionBuilder
/// The configuration delegate.
/// The to allow chaining.
[EditorBrowsable(EditorBrowsableState.Advanced)]
- public IFacilityExtensionReflectionBuilder AddResolver(Action? configure = null)
+ public IFacilityExtensionReflectionBuilder AddResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(Action? configure = null)
where T : IFacilityExtensionResolver;
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionResolver.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionResolver.cs
index b6141fd..cfd688f 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionResolver.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityExtensionResolver.cs
@@ -17,5 +17,5 @@ public interface IFacilityExtensionResolver
/// The type of the facility.
/// The of facility extensions.
/// Argument is null.
- IEnumerable> Resolve(Type facilityType);
+ IEnumerable Resolve(Type facilityType);
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityReflectionBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityReflectionBuilder.cs
index 8dad4a4..9c0d738 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityReflectionBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityReflectionBuilder.cs
@@ -3,6 +3,7 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
namespace AppCoreNet.Extensions.DependencyInjection.Facilities;
@@ -27,7 +28,8 @@ public interface IFacilityReflectionBuilder
/// The configuration delegate.
/// The to allow chaining.
[EditorBrowsable(EditorBrowsableState.Advanced)]
- public IFacilityReflectionBuilder AddResolver(Action? configure = null)
+ public IFacilityReflectionBuilder AddResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(Action? configure = null)
where T : IFacilityResolver;
///
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/FacilityServiceCollectionExtensions.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/FacilityServiceCollectionExtensions.cs
index 3850e2a..e71d1aa 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/FacilityServiceCollectionExtensions.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/FacilityServiceCollectionExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
using AppCoreNet.Extensions.DependencyInjection.Facilities;
@@ -24,7 +25,10 @@ public static class FacilityServiceCollectionExtensions
/// The delegate to configure the facility.
/// The to allow chaining.
/// Argument is null.
- public static IServiceCollection AddFacility(this IServiceCollection services, Action>? configure = null)
+ public static IServiceCollection AddFacility<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(
+ this IServiceCollection services,
+ Action>? configure = null)
where T : IFacility
{
Ensure.Arg.NotNull(services);
@@ -56,12 +60,12 @@ public static IServiceCollection AddFacility(this IServiceCollection services
/// Argument is not of type .
public static IServiceCollection AddFacility(
this IServiceCollection services,
- Type facilityType,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type facilityType,
Action? configure = null)
{
Ensure.Arg.NotNull(services);
Ensure.Arg.NotNull(facilityType);
- Ensure.Arg.OfType(facilityType, typeof(IFacility));
+ Ensure.Arg.OfType(facilityType);
services.TryAddTransient();
@@ -100,12 +104,14 @@ public static IServiceCollection AddFacilitiesFrom(
configure(builder);
- foreach ((IFacility Facility, IReadOnlyCollection> FacilityExtensions) item in builder
- .Resolve())
+ IReadOnlyCollection<(IFacility Facility, IReadOnlyCollection FacilityExtensions)>
+ facilities = builder.Resolve();
+
+ foreach ((IFacility Facility, IReadOnlyCollection FacilityExtensions) item in facilities)
{
item.Facility.ConfigureServices(services);
- foreach (IFacilityExtension facilityExtension in item.FacilityExtensions)
+ foreach (IFacilityExtension facilityExtension in item.FacilityExtensions)
{
facilityExtension.ConfigureServices(services);
}
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/IServiceDescriptorReflectionBuilder.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/IServiceDescriptorReflectionBuilder.cs
index 8da922a..e09a342 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/IServiceDescriptorReflectionBuilder.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/IServiceDescriptorReflectionBuilder.cs
@@ -3,6 +3,7 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
namespace AppCoreNet.Extensions.DependencyInjection;
@@ -35,6 +36,7 @@ public interface IServiceDescriptorReflectionBuilder
/// The configuration delegate.
/// The to allow chaining.
[EditorBrowsable(EditorBrowsableState.Advanced)]
- public IServiceDescriptorReflectionBuilder AddResolver(Action? configure = null)
+ public IServiceDescriptorReflectionBuilder AddResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(Action? configure = null)
where T : IServiceDescriptorResolver;
}
\ No newline at end of file
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ReflectionServiceCollectionExtensions.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ReflectionServiceCollectionExtensions.cs
index d53f551..787c95c 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ReflectionServiceCollectionExtensions.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ReflectionServiceCollectionExtensions.cs
@@ -2,6 +2,7 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.DependencyInjection.Activator;
using Microsoft.Extensions.DependencyInjection;
diff --git a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.cs b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.cs
index 747e303..6a5c232 100644
--- a/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.cs
+++ b/DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.cs
@@ -2,9 +2,10 @@
// Copyright (c) The AppCore .NET project.
using System;
-using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
+using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
namespace AppCoreNet.Extensions.DependencyInjection;
@@ -12,11 +13,18 @@ namespace AppCoreNet.Extensions.DependencyInjection;
///
/// Internal service provider which resolves services from an .
///
-internal sealed partial class ServiceCollectionServiceProvider : IServiceProvider, IServiceProviderIsService
+internal sealed class ServiceCollectionServiceProvider : IServiceProvider, IServiceProviderIsService
{
private readonly IServiceCollection _services;
private readonly Dictionary _additionalServices = new();
+ internal static bool VerifyAotCompatibility =>
+#if NETFRAMEWORK || NETSTANDARD2_0
+ false;
+#else
+ !RuntimeFeature.IsDynamicCodeSupported;
+#endif
+
public ServiceCollectionServiceProvider(IServiceCollection services)
{
_services = services;
@@ -27,6 +35,19 @@ public void AddService(Type serviceType, object instance)
_additionalServices.Add(serviceType, instance);
}
+ private static bool IsEnumerable(Type serviceType)
+ {
+ return serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof(IEnumerable<>);
+ }
+
+ private static bool IsServiceType(Type serviceType, Type requestedServiceType)
+ {
+ return serviceType == requestedServiceType
+ || (requestedServiceType.IsGenericType
+ && serviceType.IsGenericTypeDefinition
+ && serviceType == requestedServiceType.GetGenericTypeDefinition());
+ }
+
public bool IsService(Type serviceType)
{
if (serviceType == typeof(IServiceProvider) || serviceType == typeof(IServiceProviderIsService))
@@ -35,42 +56,53 @@ public bool IsService(Type serviceType)
if (_additionalServices.TryGetValue(serviceType, out object? _))
return true;
- if (serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
+ if (IsEnumerable(serviceType))
return true;
- return _services.Any(
- sd => sd.ServiceType == serviceType
- || (serviceType.IsGenericType
- && sd.ServiceType == serviceType.GetGenericTypeDefinition()));
+ return _services.Any(sd => IsServiceType(sd.ServiceType, serviceType));
}
- private IEnumerable
/// The type of the .
-public abstract class OAuthUserHandler : IAuthenticationSchemeHandler
+public abstract class OAuthUserHandler : IAuthenticationSchemeHandler
where TParameters : OAuthUserParameters
{
private readonly IHttpContextAccessor _httpContextAccessor;
@@ -42,7 +42,14 @@ protected OAuthUserHandler(IHttpContextAccessor httpContextAccessor, IOAuthUserT
/// The .
protected abstract void EnsureCompatibleScheme(AuthenticationScheme scheme);
- ///
+ ///
+ /// Authenticates a with the specified OAuth user scheme and parameters.
+ ///
+ /// The .
+ /// The .
+ /// The .
+ /// A .
+ /// The asynchronous operation.
public async Task AuthenticateAsync(
AuthenticationScheme scheme,
HttpRequestMessage request,
@@ -64,4 +71,18 @@ await _authTokenService.GetAccessTokenAsync(scheme, user, parameters, cancellati
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.AccessToken);
}
+
+ async Task IAuthenticationSchemeHandler.AuthenticateAsync(
+ AuthenticationScheme scheme,
+ HttpRequestMessage request,
+ AuthenticationParameters? parameters,
+ CancellationToken cancellationToken)
+ {
+ await AuthenticateAsync(
+ scheme,
+ request,
+ (TParameters?)parameters,
+ cancellationToken)
+ .ConfigureAwait(false);
+ }
}
\ No newline at end of file
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/OAuthUserTokenService.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/OAuthUserTokenService.cs
index 5faab99..a19b831 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/OAuthUserTokenService.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/OAuthUserTokenService.cs
@@ -20,7 +20,9 @@ namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
/// Provides the base class for see .
///
/// The type of the .
-public abstract class OAuthUserTokenService : IOAuthUserTokenService
+public abstract class OAuthUserTokenService<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions>
+ : IOAuthUserTokenService
where TOptions : OAuthUserOptions
{
private static readonly ConcurrentDictionary>> _sync = new();
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect.csproj b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect.csproj
index bf082ac..989b5d8 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect.csproj
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect/AppCoreNet.Extensions.Http.Authentication.OAuth.OpenIdConnect.csproj
@@ -7,6 +7,7 @@
from ASP.NET Core OpenID connect authentication schemes.
$(PackageTags);Security;Authentication;OAuth;OAuth2;OAuth 2.0;IdentityModel;ASP.NET Core;OpenID Connect
+ true
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/AppCoreNet.Extensions.Http.Authentication.OAuth.csproj b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/AppCoreNet.Extensions.Http.Authentication.OAuth.csproj
index f7883c1..fa8520d 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/AppCoreNet.Extensions.Http.Authentication.OAuth.csproj
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/AppCoreNet.Extensions.Http.Authentication.OAuth.csproj
@@ -6,6 +6,7 @@
Adds support to AppCoreNet.Extensions.Http.Authenticaton for authenticating a HttpClient using OAuth2 bearer tokens.
$(PackageTags);Security;Authentication;OAuth;OAuth2;OAuth 2.0;IdentityModel
+ true
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthClientHandler.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthClientHandler.cs
index e6ded6f..4e3650d 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthClientHandler.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthClientHandler.cs
@@ -12,7 +12,7 @@ namespace AppCoreNet.Extensions.Http.Authentication.OAuth;
///
/// Provides a OAuth client authentication handler.
///
-public class OAuthClientHandler : IAuthenticationSchemeHandler
+public class OAuthClientHandler : IAuthenticationSchemeHandler
{
private readonly IOAuthTokenService _authTokenService;
@@ -26,7 +26,14 @@ public OAuthClientHandler(IOAuthTokenService authTokenService)
_authTokenService = authTokenService;
}
- ///
+ ///
+ /// Authenticates a with the specified OAuth client scheme and parameters.
+ ///
+ /// The .
+ /// The .
+ /// The .
+ /// A .
+ /// The asynchronous operation.
public async Task AuthenticateAsync(
AuthenticationScheme scheme,
HttpRequestMessage request,
@@ -39,4 +46,18 @@ await _authTokenService.GetClientAccessTokenAsync(scheme, parameters, cancellati
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.AccessToken);
}
+
+ async Task IAuthenticationSchemeHandler.AuthenticateAsync(
+ AuthenticationScheme scheme,
+ HttpRequestMessage request,
+ AuthenticationParameters? parameters,
+ CancellationToken cancellationToken)
+ {
+ await AuthenticateAsync(
+ scheme,
+ request,
+ (OAuthParameters?)parameters,
+ cancellationToken)
+ .ConfigureAwait(false);
+ }
}
\ No newline at end of file
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthOptionsResolver.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthOptionsResolver.cs
index 75a46d5..5b397ef 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthOptionsResolver.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthOptionsResolver.cs
@@ -2,12 +2,15 @@
// Copyright (c) The AppCore .NET project.
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
namespace AppCoreNet.Extensions.Http.Authentication.OAuth;
-internal sealed class OAuthOptionsResolver : IOAuthOptionsResolver
+internal sealed class OAuthOptionsResolver<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions>
+ : IOAuthOptionsResolver
where TOptions : OAuthOptions
{
private readonly IOptionsMonitor _options;
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthPasswordHandler.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthPasswordHandler.cs
index ebfbe34..9c3a641 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthPasswordHandler.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth/OAuthPasswordHandler.cs
@@ -1,4 +1,7 @@
-using System.Net.Http;
+// Licensed under the MIT license.
+// Copyright (c) The AppCore .NET project.
+
+using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
@@ -9,7 +12,7 @@ namespace AppCoreNet.Extensions.Http.Authentication.OAuth;
///
/// Provides a OAuth password authentication handler.
///
-public class OAuthPasswordHandler : IAuthenticationSchemeHandler
+public class OAuthPasswordHandler : IAuthenticationSchemeHandler
{
private readonly IOAuthTokenService _authTokenService;
@@ -23,7 +26,14 @@ public OAuthPasswordHandler(IOAuthTokenService authTokenService)
_authTokenService = authTokenService;
}
- ///
+ ///
+ /// Authenticates a with the specified OAuth password scheme and parameters.
+ ///
+ /// The .
+ /// The .
+ /// The .
+ /// A .
+ /// The asynchronous operation.
public async Task AuthenticateAsync(
AuthenticationScheme scheme,
HttpRequestMessage request,
@@ -36,4 +46,18 @@ await _authTokenService.GetPasswordAccessTokenAsync(scheme, parameters, cancella
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.AccessToken);
}
+
+ async Task IAuthenticationSchemeHandler.AuthenticateAsync(
+ AuthenticationScheme scheme,
+ HttpRequestMessage request,
+ AuthenticationParameters? parameters,
+ CancellationToken cancellationToken)
+ {
+ await AuthenticateAsync(
+ scheme,
+ request,
+ (OAuthParameters?)parameters,
+ cancellationToken)
+ .ConfigureAwait(false);
+ }
}
\ No newline at end of file
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/AppCoreNet.Extensions.Http.Authentication.csproj b/Http/src/AppCoreNet.Extensions.Http.Authentication/AppCoreNet.Extensions.Http.Authentication.csproj
index ebc9eab..79a3e18 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/AppCoreNet.Extensions.Http.Authentication.csproj
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/AppCoreNet.Extensions.Http.Authentication.csproj
@@ -7,6 +7,7 @@
using different authentication standards.
$(PackageTags);Security;Authentication
+ true
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationHandler.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationHandler.cs
index 3420d25..02f8e08 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationHandler.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationHandler.cs
@@ -16,14 +16,14 @@ namespace AppCoreNet.Extensions.Http.Authentication;
/// authentication to the request.
///
/// The type of the .
-/// The type of the .
+/// The type of the .
public class AuthenticationHandler : DelegatingHandler
where TParameters : AuthenticationParameters, new()
- where THandler : IAuthenticationSchemeHandler
+ where THandler : IAuthenticationSchemeHandler
{
private readonly string _scheme;
private readonly IAuthenticationSchemeProvider _schemes;
- private readonly IAuthenticationSchemeHandler _schemeHandler;
+ private readonly IAuthenticationSchemeHandler _schemeHandler;
private readonly TParameters? _parameters;
private readonly ILogger _logger;
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationParameters.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationParameters.cs
index abce860..fc3444e 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationParameters.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationParameters.cs
@@ -12,7 +12,7 @@ namespace AppCoreNet.Extensions.Http.Authentication;
///
public class AuthenticationParameters
{
- private IDictionary _parameters;
+ private readonly IDictionary _parameters;
///
/// Gets or sets a value indicating whether to force renewing the authentication.
@@ -49,10 +49,11 @@ protected AuthenticationParameters(IDictionary parameters)
public T Clone()
where T : AuthenticationParameters, new()
{
- var clone = new T
+ var clone = new T();
+ foreach (KeyValuePair parameter in _parameters)
{
- _parameters = new Dictionary(_parameters, StringComparer.Ordinal),
- };
+ clone._parameters[parameter.Key] = parameter.Value;
+ }
return clone;
}
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationScheme.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationScheme.cs
index 2e6636a..f2dcd01 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationScheme.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationScheme.cs
@@ -17,7 +17,7 @@ public sealed class AuthenticationScheme
public string Name { get; }
///
- /// Gets the type of the which handles the scheme.
+ /// Gets the type of the which handles the scheme.
///
public Type HandlerType { get; }
@@ -26,22 +26,31 @@ public sealed class AuthenticationScheme
///
public Type OptionsType { get; }
+ ///
+ /// Gets the type of the .
+ ///
+ public Type ParametersType { get; }
+
///
/// Initializes a new instance of the class.
///
/// The name of the authentication scheme.
- /// The type of the which handles the scheme.
+ /// The type of the which handles the scheme.
/// The type of the .
- public AuthenticationScheme(string name, Type handlerType, Type optionsType)
+ /// The type of the .
+ public AuthenticationScheme(string name, Type handlerType, Type optionsType, Type parametersType)
{
Ensure.Arg.NotNull(name);
Ensure.Arg.NotNull(handlerType);
- Ensure.Arg.OfType(handlerType, typeof(IAuthenticationSchemeHandler<>));
+ Ensure.Arg.OfType(handlerType);
Ensure.Arg.NotNull(optionsType);
- Ensure.Arg.OfType(optionsType, typeof(AuthenticationSchemeOptions));
+ Ensure.Arg.OfType(optionsType);
+ Ensure.Arg.NotNull(parametersType);
+ Ensure.Arg.OfType(parametersType);
Name = name;
HandlerType = handlerType;
OptionsType = optionsType;
+ ParametersType = parametersType;
}
}
\ No newline at end of file
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationSchemeHandler.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationSchemeHandler.cs
index 013e93c..1c0a5bc 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationSchemeHandler.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/AuthenticationSchemeHandler.cs
@@ -1,6 +1,7 @@
// Licensed under the MIT license.
// Copyright (c) The AppCore .NET project.
+using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@@ -10,11 +11,13 @@
namespace AppCoreNet.Extensions.Http.Authentication;
///
-/// Provides a base class for .
+/// Provides a base class for .
///
/// The type of the .
/// The type of the .
-public abstract class AuthenticationSchemeHandler : IAuthenticationSchemeHandler
+public abstract class AuthenticationSchemeHandler<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions, TParameters>
+ : IAuthenticationSchemeHandler
where TOptions : AuthenticationSchemeOptions
where TParameters : AuthenticationParameters, new()
{
@@ -46,13 +49,18 @@ protected abstract Task AuthenticateAsync(
HttpRequestMessage request,
CancellationToken cancellationToken);
- async Task IAuthenticationSchemeHandler.AuthenticateAsync(
+ async Task IAuthenticationSchemeHandler.AuthenticateAsync(
AuthenticationScheme scheme,
HttpRequestMessage request,
- TParameters? parameters,
+ AuthenticationParameters? parameters,
CancellationToken cancellationToken)
{
- await AuthenticateAsync(scheme, _optionsMonitor.Get(scheme.Name), parameters, request, cancellationToken)
+ await AuthenticateAsync(
+ scheme,
+ _optionsMonitor.Get(scheme.Name),
+ (TParameters?)parameters,
+ request,
+ cancellationToken)
.ConfigureAwait(false);
}
}
\ No newline at end of file
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/AuthenticationHttpClientBuilderExtensions.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/AuthenticationHttpClientBuilderExtensions.cs
index 1c28a31..245d3b2 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/AuthenticationHttpClientBuilderExtensions.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/AuthenticationHttpClientBuilderExtensions.cs
@@ -26,14 +26,14 @@ private static string GetLoggerName(IHttpClientBuilder builder)
/// The authentication scheme.
/// Additional authentication parameters.
/// The type of the .
- /// The type of the .
+ /// The type of the .
/// The passed .
public static IHttpClientBuilder AddAuthentication(
this IHttpClientBuilder builder,
string scheme,
TParameters? parameters)
where TParameters : AuthenticationParameters, new()
- where THandler : IAuthenticationSchemeHandler
+ where THandler : IAuthenticationSchemeHandler
{
Ensure.Arg.NotNull(builder);
Ensure.Arg.NotNull(scheme);
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/HttpClientAuthenticationBuilderExtensions.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/HttpClientAuthenticationBuilderExtensions.cs
index 378e7b0..4d95749 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/HttpClientAuthenticationBuilderExtensions.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/DependencyInjection/HttpClientAuthenticationBuilderExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using AppCoreNet.Diagnostics;
using AppCoreNet.Extensions.Http.Authentication;
using Microsoft.Extensions.DependencyInjection;
@@ -25,16 +26,16 @@ public static class HttpClientAuthenticationBuilderExtensions
/// The option configuration delegate.
/// The type of the .
/// The type of the .
- /// The type of the .
+ /// The type of the .
/// The to allow chaining the calls.
[EditorBrowsable(EditorBrowsableState.Never)]
- public static IHttpClientAuthenticationBuilder AddScheme(
+ public static IHttpClientAuthenticationBuilder AddScheme(
this IHttpClientAuthenticationBuilder builder,
string name,
Action? configure = null)
where TOptions : AuthenticationSchemeOptions
where TParameters : AuthenticationParameters
- where THandler : class, IAuthenticationSchemeHandler
+ where THandler : class, IAuthenticationSchemeHandler
{
Ensure.Arg.NotNull(builder);
Ensure.Arg.NotNull(name);
@@ -42,12 +43,12 @@ public static IHttpClientAuthenticationBuilder AddScheme();
- services.TryAddTransient>(
+ services.TryAddTransient(
sp => sp.GetRequiredService());
services.Configure(
o => o
- .AddScheme(name, typeof(THandler), typeof(TOptions)));
+ .AddScheme(name, typeof(THandler), typeof(TOptions), typeof(TParameters)));
if (configure != null)
{
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/HttpClientAuthenticationOptions.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/HttpClientAuthenticationOptions.cs
index 6e6de57..d89faf8 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/HttpClientAuthenticationOptions.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/HttpClientAuthenticationOptions.cs
@@ -21,10 +21,11 @@ public sealed class HttpClientAuthenticationOptions
/// Adds a authentication scheme.
///
/// The name of the authentication scheme.
- /// The type of the .
+ /// The type of the .
/// The type of the .
- public void AddScheme(string name, Type handlerType, Type optionsType)
- => SchemeMap.Add(name, new AuthenticationScheme(name, handlerType, optionsType));
+ /// The type of the .
+ public void AddScheme(string name, Type handlerType, Type optionsType, Type parametersType)
+ => SchemeMap.Add(name, new AuthenticationScheme(name, handlerType, optionsType, parametersType));
///
/// Adds a authentication scheme.
diff --git a/Http/src/AppCoreNet.Extensions.Http.Authentication/IAuthenticationSchemeHandler.cs b/Http/src/AppCoreNet.Extensions.Http.Authentication/IAuthenticationSchemeHandler.cs
index 5e5a1d0..c68f552 100644
--- a/Http/src/AppCoreNet.Extensions.Http.Authentication/IAuthenticationSchemeHandler.cs
+++ b/Http/src/AppCoreNet.Extensions.Http.Authentication/IAuthenticationSchemeHandler.cs
@@ -10,9 +10,7 @@ namespace AppCoreNet.Extensions.Http.Authentication;
///
/// Represents a HTTP client authentication scheme handler.
///
-/// The type of the .
-public interface IAuthenticationSchemeHandler
- where TParameters : AuthenticationParameters
+public interface IAuthenticationSchemeHandler
{
///
/// Authenticates a with the specified scheme and parameters.
@@ -25,6 +23,6 @@ public interface IAuthenticationSchemeHandler
Task AuthenticateAsync(
AuthenticationScheme scheme,
HttpRequestMessage request,
- TParameters? parameters = null,
+ AuthenticationParameters? parameters = null,
CancellationToken cancellationToken = default);
}
\ No newline at end of file
diff --git a/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AppCoreNet.Extensions.Http.Authentication.Tests.csproj b/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AppCoreNet.Extensions.Http.Authentication.Tests.csproj
index c245989..4c44fed 100644
--- a/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AppCoreNet.Extensions.Http.Authentication.Tests.csproj
+++ b/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AppCoreNet.Extensions.Http.Authentication.Tests.csproj
@@ -1,7 +1,7 @@
- net8.0
+ net9.0;net8.0
$(TargetFrameworks);net472
AppCoreNet.Extensions.Http.Authentication
diff --git a/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AuthenticationSchemeProviderTests.cs b/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AuthenticationSchemeProviderTests.cs
index f521d20..d833e88 100644
--- a/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AuthenticationSchemeProviderTests.cs
+++ b/Http/test/AppCoreNet.Extensions.Http.Authentication.Tests/AuthenticationSchemeProviderTests.cs
@@ -28,13 +28,15 @@ public async Task AddsSchemesFromOptions()
{
var scheme1 = new AuthenticationScheme(
"scheme1",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
var scheme2 = new AuthenticationScheme(
"scheme2",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
var options = new HttpClientAuthenticationOptions();
options.AddScheme(scheme1);
@@ -54,8 +56,9 @@ public void AddSchemeThrowsOnDuplicateScheme()
var scheme = new AuthenticationScheme(
"scheme",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
provider.AddScheme(scheme);
@@ -72,13 +75,15 @@ public async Task GetAllSchemesReturnsSchemes()
var scheme1 = new AuthenticationScheme(
"scheme1",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
var scheme2 = new AuthenticationScheme(
"scheme2",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
provider.AddScheme(scheme1);
provider.AddScheme(scheme2);
@@ -95,13 +100,15 @@ public async Task FindSchemeReturnsScheme()
var scheme1 = new AuthenticationScheme(
"scheme1",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
var scheme2 = new AuthenticationScheme(
"scheme2",
- typeof(IAuthenticationSchemeHandler<>),
- typeof(AuthenticationSchemeOptions));
+ typeof(IAuthenticationSchemeHandler),
+ typeof(AuthenticationSchemeOptions),
+ typeof(AuthenticationParameters));
provider.AddScheme(scheme1);
provider.AddScheme(scheme2);
diff --git a/Http/test/Directory.Build.props b/Http/test/Directory.Build.props
index 6e1c272..e359518 100644
--- a/Http/test/Directory.Build.props
+++ b/Http/test/Directory.Build.props
@@ -4,6 +4,7 @@
false
$(NoWarn);VSTHRD200
+ true