@@ -18,15 +18,47 @@ public static class DependencyInjectionExtensions
1818 /// The <see cref="IServiceCollection"/> so that additional calls can be chained.
1919 /// </returns>
2020 public static IServiceCollection AddSecurityKey ( this IServiceCollection services , Action < SecurityKeyOptions > ? configure = null )
21+ {
22+ return AddSecurityKey < SecurityKeyValidator , SecurityKeyExtractor > ( services , configure ) ;
23+ }
24+
25+ /// <summary>
26+ /// Adds the security API key services to the specified <see cref="IServiceCollection" />.
27+ /// </summary>
28+ /// <typeparam name="TValidator">The type for validating the security API key.</typeparam>
29+ /// <param name="services">The <see cref="IServiceCollection" /> to add services.</param>
30+ /// <param name="configure">An action delegate to configure the provided <see cref="SecurityKeyOptions" />.</param>
31+ /// <returns>
32+ /// The <see cref="IServiceCollection" /> so that additional calls can be chained.
33+ /// </returns>
34+ public static IServiceCollection AddSecurityKey < TValidator > ( this IServiceCollection services , Action < SecurityKeyOptions > ? configure = null )
35+ where TValidator : class , ISecurityKeyValidator
36+ {
37+ return AddSecurityKey < TValidator , SecurityKeyExtractor > ( services , configure ) ;
38+ }
39+
40+ /// <summary>
41+ /// Adds the security API key services to the specified <see cref="IServiceCollection" />.
42+ /// </summary>
43+ /// <typeparam name="TValidator">The type for validating the security API key.</typeparam>
44+ /// <typeparam name="TExtractor">The type for extracting the security API key.</typeparam>
45+ /// <param name="services">The <see cref="IServiceCollection" /> to add services.</param>
46+ /// <param name="configure">An action delegate to configure the provided <see cref="SecurityKeyOptions" />.</param>
47+ /// <returns>
48+ /// The <see cref="IServiceCollection" /> so that additional calls can be chained.
49+ /// </returns>
50+ public static IServiceCollection AddSecurityKey < TValidator , TExtractor > ( this IServiceCollection services , Action < SecurityKeyOptions > ? configure = null )
51+ where TValidator : class , ISecurityKeyValidator
52+ where TExtractor : class , ISecurityKeyExtractor
2153 {
2254 services . AddHttpContextAccessor ( ) ;
2355
2456 services . AddOptions < SecurityKeyOptions > ( ) ;
2557 if ( configure != null )
2658 services . Configure ( configure ) ;
2759
28- services . TryAddSingleton < ISecurityKeyExtractor , SecurityKeyExtractor > ( ) ;
29- services . TryAddSingleton < ISecurityKeyValidator , SecurityKeyValidator > ( ) ;
60+ services . TryAddSingleton < ISecurityKeyExtractor , TExtractor > ( ) ;
61+ services . TryAddSingleton < ISecurityKeyValidator , TValidator > ( ) ;
3062
3163 // used by SecurityKeyAttribute
3264 services . TryAddSingleton < SecurityKeyAuthorizationFilter > ( ) ;
0 commit comments