From fc6d5594938138b524f48af3227043f6440c8d0e Mon Sep 17 00:00:00 2001 From: "David G. Moore, Jr." Date: Fri, 19 Jan 2024 05:49:05 -0500 Subject: [PATCH] Enhance host builder auto-configuration Refactored `AutoConfigureIApplicationHostBuilderExtensions` to introduce a generic parameter that facilitates configuration loading based on the assembly location of a given program type. Enabled discovery of both host and app builder configurator types using `AutoConfiguratorConfiguration` rather than reflection, streamlining the configuration process. Consolidated and optimized `KeyPerJsonFileConfigurationExtensions`, including the addition of regex patterns for environment-specific configurations, improving file discovery and environment matching for JSON configurations. Updated project solution GUIDs in `.sln` files for consistency. Streamlined `TempMediaType` by removing unused URI properties and improved readability across several service configuration classes by formatting long lambdas and aligning nested properties. Removed redundant `UseHttpServicesExtensions` class to clean up the HTTP pipeline setup. Refactoring led to the removal of obsolete extension methods for service configuration, in favor of more focused, encapsulated, and testable configuration classes. These changes are pivotal to enhancing the maintainability and extensibility of the application's configuration management, enabling more intuitive mapping of configuration sections to strongly typed settings and providing a foundation for future extensibility. --- .../AutoConfiguratorConfiguration.cs | 29 +++++++ ...figureIApplicationHostBuilderExtensions.cs | 71 ++++++++++++--- .../KeyPerJsonFileConfigurationExtensions.cs | 21 +++-- .../Dgmjr.Hosting.Extensions.sln | 42 +++++++++ src/Http/Mime/Dgmjr.Mime.sln | 26 +++--- src/Http/Mime/TempMediaType.cs | 7 +- src/Http/Services/CorsOptions.cs | 18 ++-- src/Http/Services/ExceptionHandlerOptions.cs | 6 ++ ...HttpServicesExtensions.AddHttpServices.cs} | 2 +- ...HttpServicesExtensions.UseHttpServices.cs} | 5 ++ src/Http/Services/HttpServicesOptions.cs | 87 +++++++++++++++++-- .../HttpServicesOptionsAutoConfigurator.cs | 5 +- src/MicrosoftGraph/Dgmjr.Graph.csproj | 2 +- src/MicrosoftGraph/Dgmjr.Graph.sln | 26 +++--- src/Mvc/LICENSE.md | 26 +++--- src/Mvc/MvcAutoConfigurator.cs | 4 +- 16 files changed, 300 insertions(+), 77 deletions(-) create mode 100644 src/Configuration/AutoConfiguratorConfiguration.cs create mode 100644 src/Hosting.Extensions/Dgmjr.Hosting.Extensions.sln create mode 100644 src/Http/Services/ExceptionHandlerOptions.cs rename src/Http/Services/{AddHttpServicesExtensions.cs => HttpServicesExtensions.AddHttpServices.cs} (95%) rename src/Http/Services/{UseHttpServicesExtensions.cs => HttpServicesExtensions.UseHttpServices.cs} (93%) mode change 100755 => 100644 src/Mvc/LICENSE.md diff --git a/src/Configuration/AutoConfiguratorConfiguration.cs b/src/Configuration/AutoConfiguratorConfiguration.cs new file mode 100644 index 00000000..ec5e653b --- /dev/null +++ b/src/Configuration/AutoConfiguratorConfiguration.cs @@ -0,0 +1,29 @@ +using System.Collections.ObjectModel; + +namespace Dgmjr.Configuration.Extensions; + +public class AutoConfiguratorConfiguration : Collection +{ + public const string SectionName = "AutoConfigure"; +} + +public class AutoConfiguratorConfigurator(IConfiguration configuration) + : IConfigureOptions +{ + public void Configure(AutoConfiguratorConfiguration options) + { + var section = configuration.GetSection(AutoConfiguratorConfiguration.SectionName); + Console.WriteLine(section.ToJson()); + if (section.Exists()) + { + foreach (var configurator in section.GetChildren()) + { + var type = Type.GetType(configurator.Value); + if (type != null) + { + options.Add(type); + } + } + } + } +} diff --git a/src/Configuration/AutoConfigureIApplicationHostBuilderExtensions.cs b/src/Configuration/AutoConfigureIApplicationHostBuilderExtensions.cs index 4a7791fe..897838e8 100644 --- a/src/Configuration/AutoConfigureIApplicationHostBuilderExtensions.cs +++ b/src/Configuration/AutoConfigureIApplicationHostBuilderExtensions.cs @@ -10,33 +10,76 @@ namespace Microsoft.Extensions.DependencyInjection; public static class AutoConfigureIApplicationHostBuilderExtensions { - public static IHostApplicationBuilder AutoConfigure(this IHostApplicationBuilder builder) + public static IHostApplicationBuilder AutoConfigure( + this IHostApplicationBuilder builder + ) { - var hostBuilderConfiguratorTypes = AssemblyLoadExtensions - .GetTypesAssignableTo(); + builder.Configuration.AddKeyPerJsonFile( + Path.Join(Path.GetDirectoryName(typeof(TProgram).Assembly.Location), "./Configuration/") + ); + + var autoConfigurationConfig = new AutoConfiguratorConfiguration(); + var autoConfiguratorConfigurator = new AutoConfiguratorConfigurator(builder.Configuration); + autoConfiguratorConfigurator.Configure(autoConfigurationConfig); + + var hostBuilderConfiguratorTypes = autoConfigurationConfig.Where( + type => typeof(IConfigureIHostApplicationBuilder).IsAssignableFrom(type) + ); + var appBuilderConfiguratorTypes = autoConfigurationConfig.Where( + type => typeof(IConfigureIApplicationBuilder).IsAssignableFrom(type) + ); + + // var hostBuilderConfiguratorTypes = AssemblyLoadExtensions + // .GetTypesAssignableTo(); - var appBuilderConfiguratorTypes = AssemblyLoadExtensions - .GetTypesAssignableTo(); + // var appBuilderConfiguratorTypes = AssemblyLoadExtensions + // .GetTypesAssignableTo(); var services = new ServiceCollection(); - foreach(var serviceDescriptor in builder.Services) + foreach (var serviceDescriptor in builder.Services) { services.Add(serviceDescriptor); } foreach (var configuratorType in hostBuilderConfiguratorTypes) { - services.TryAddEnumerable(new ServiceDescriptor(typeof(IConfigureIHostApplicationBuilder), configuratorType, ServiceLifetime.Singleton)); - builder.Services.TryAddEnumerable(new ServiceDescriptor(typeof(IConfigureIHostApplicationBuilder), configuratorType, ServiceLifetime.Singleton)); + services.TryAddEnumerable( + new ServiceDescriptor( + typeof(IConfigureIHostApplicationBuilder), + configuratorType, + ServiceLifetime.Singleton + ) + ); + builder.Services.TryAddEnumerable( + new ServiceDescriptor( + typeof(IConfigureIHostApplicationBuilder), + configuratorType, + ServiceLifetime.Singleton + ) + ); } - foreach(var configuratorType in appBuilderConfiguratorTypes) + foreach (var configuratorType in appBuilderConfiguratorTypes) { - services.TryAddEnumerable(new ServiceDescriptor(typeof(IConfigureIApplicationBuilder), configuratorType, ServiceLifetime.Singleton)); - builder.Services.TryAddEnumerable(new ServiceDescriptor(typeof(IConfigureIApplicationBuilder), configuratorType, ServiceLifetime.Singleton)); + services.TryAddEnumerable( + new ServiceDescriptor( + typeof(IConfigureIApplicationBuilder), + configuratorType, + ServiceLifetime.Singleton + ) + ); + builder.Services.TryAddEnumerable( + new ServiceDescriptor( + typeof(IConfigureIApplicationBuilder), + configuratorType, + ServiceLifetime.Singleton + ) + ); } - var configurators = services.BuildServiceProvider().GetServices() + var configurators = services + .BuildServiceProvider() + .GetServices() .OrderBy(configurator => configurator.Order) .ToList(); @@ -46,7 +89,9 @@ public static IHostApplicationBuilder AutoConfigure(this IHostApplicationBuilder foreach (var configurator in configurators) { - Console.WriteLine($"Configuring IHostApplicationBuilder with {configurator.GetType().Name}."); + Console.WriteLine( + $"Configuring IHostApplicationBuilder with {configurator.GetType().Name}." + ); configurator.Configure(builder); } diff --git a/src/Configuration/KeyPerJsonFileConfigurationExtensions.cs b/src/Configuration/KeyPerJsonFileConfigurationExtensions.cs index 60541e58..695b1b04 100644 --- a/src/Configuration/KeyPerJsonFileConfigurationExtensions.cs +++ b/src/Configuration/KeyPerJsonFileConfigurationExtensions.cs @@ -86,7 +86,8 @@ internal static void OnLoadException(FileLoadExceptionContext ctx) internal static readonly string[] EnvironmentNames = Hosting.EnvironmentNames.All; - internal static readonly string EnvironmentizedRegexString = $@"^(?[a-zA-Z0-9:\-]*(?:\.[a-zA-Z0-9:\-])*)(?::(?{Join("|", EnvironmentNames.Select(env => $"(?:{env})"))}))?\.json$"; + internal static readonly string EnvironmentizedRegexString = + $@"^(?[a-zA-Z0-9:\-]*(?:\.[a-zA-Z0-9:\-])*)(?::(?{Join("|", EnvironmentNames.Select(env => $"(?:{env})"))}))?\.json$"; public static Regx EnvironmentizedRegex => new(EnvironmentizedRegexString, Rxo.Compiled | Rxo.IgnoreCase); @@ -96,6 +97,12 @@ internal static void OnLoadException(FileLoadExceptionContext ctx) Rxo.Compiled | Rxo.IgnoreCase ); + public static Regx NonEnvironmentizedRegex => + new( + @"^(?[a-zA-Z0-9\-]*(?:\.[a-zA-Z0-9\-])*)\.json$", + Rxo.Compiled | Rxo.IgnoreCase + ); + internal static IEnumerable GetJsonFiles( this DirectoryInfo directory, bool recursive @@ -125,15 +132,17 @@ internal static string RemoveEnvironmentIfIsForThisEnvironment(this string jsonF internal static int CountLines(this string s) => LineBreakRegex().Matches(s).Count; internal static bool IsForThisEnvironment(this FileInfo jsonFile) => - ThisEnvironmentRegex.IsMatch(jsonFile.Name) || !EnvironmentizedRegex.IsMatch(jsonFile.Name); + NonEnvironmentizedRegex.IsMatch(jsonFile.Name) + || ThisEnvironmentRegex.IsMatch(jsonFile.Name) + || !EnvironmentizedRegex.IsMatch(jsonFile.Name); public static string MakeAppsettingsJsonFile(this DirectoryInfo directory, bool recursive) { var appsettingsJsonFileName = Path.Join(directory.FullName, "../" + AppSettings_Json); - var jsonWriter = new StringBuilder(); + var jsonBuilder = new StringBuilder(); using (var appsettingsJsonFile = File.CreateText(appsettingsJsonFileName)) - using (var jsonStringWriter = new StringWriter(jsonWriter)) - using (var multiWriter = new MultiWriter(appsettingsJsonFile, jsonStringWriter)) + using (var jsonWriter = new StringWriter(jsonBuilder)) + using (var multiWriter = new MultiWriter(appsettingsJsonFile, jsonWriter)) { var jsonFiles = directory.GetJsonFiles(recursive); @@ -154,6 +163,6 @@ public static string MakeAppsettingsJsonFile(this DirectoryInfo directory, bool multiWriter.WriteLine("}"); } - return jsonWriter.ToString(); + return jsonBuilder.ToString(); } } diff --git a/src/Hosting.Extensions/Dgmjr.Hosting.Extensions.sln b/src/Hosting.Extensions/Dgmjr.Hosting.Extensions.sln new file mode 100644 index 00000000..b2658926 --- /dev/null +++ b/src/Hosting.Extensions/Dgmjr.Hosting.Extensions.sln @@ -0,0 +1,42 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}" + ProjectSection(SolutionItems) = preProject + ..\..\Directory.Build.props = ..\..\Directory.Build.props + ..\..\..\..\Directory.Build.targets = ..\..\..\..\Directory.Build.targets + ..\..\..\..\global.json = ..\..\..\..\global.json + ..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\Packages\Versions.Local.props + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Hosting.Extensions", "Dgmjr.Hosting.Extensions.csproj", "{3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Local|Any CPU = Local|Any CPU + Debug|Any CPU = Debug|Any CPU + Testing|Any CPU = Testing|Any CPU + Staging|Any CPU = Staging|Any CPU + Production|Any CPU = Production|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Local|Any CPU.ActiveCfg = Local|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Local|Any CPU.Build.0 = Local|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Testing|Any CPU.Build.0 = Testing|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Staging|Any CPU.Build.0 = Staging|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Production|Any CPU.ActiveCfg = Local|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Production|Any CPU.Build.0 = Local|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3423EF02-8D3E-4EE3-85C9-ADB65A0FB747}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3AB149ED-782B-4DF7-9109-FF92BC0C6627} + EndGlobalSection +EndGlobal diff --git a/src/Http/Mime/Dgmjr.Mime.sln b/src/Http/Mime/Dgmjr.Mime.sln index 7e793ee2..b3925c3d 100644 --- a/src/Http/Mime/Dgmjr.Mime.sln +++ b/src/Http/Mime/Dgmjr.Mime.sln @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Mime", "Dgmjr.Mime.csproj", "{0078C266-1755-4136-8524-343385336AE6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Mime", "Dgmjr.Mime.csproj", "{0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -20,18 +20,18 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0078C266-1755-4136-8524-343385336AE6}.Local|Any CPU.ActiveCfg = Local|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Local|Any CPU.Build.0 = Local|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Testing|Any CPU.ActiveCfg = Testing|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Testing|Any CPU.Build.0 = Testing|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Staging|Any CPU.ActiveCfg = Staging|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Staging|Any CPU.Build.0 = Staging|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Production|Any CPU.ActiveCfg = Local|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Production|Any CPU.Build.0 = Local|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0078C266-1755-4136-8524-343385336AE6}.Release|Any CPU.Build.0 = Release|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Local|Any CPU.ActiveCfg = Local|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Local|Any CPU.Build.0 = Local|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Testing|Any CPU.Build.0 = Testing|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Staging|Any CPU.Build.0 = Staging|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Production|Any CPU.ActiveCfg = Local|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Production|Any CPU.Build.0 = Local|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C5C8570-0B57-4D82-ADE2-A4DDF4FC24F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Http/Mime/TempMediaType.cs b/src/Http/Mime/TempMediaType.cs index fcfc0352..d83c6c16 100644 --- a/src/Http/Mime/TempMediaType.cs +++ b/src/Http/Mime/TempMediaType.cs @@ -18,8 +18,7 @@ namespace Dgmjr.Mime; using Dgmjr.Mime.Enums; -public readonly record struct TempMediaType(string Name) - : IMediaType +public readonly record struct TempMediaType(string Name) : IMediaType { public string DisplayName { get; } = Name; private static readonly MD5 MD5 = MD5.Create(); @@ -38,8 +37,8 @@ public readonly record struct TempMediaType(string Name) public int Order => 0; public string Prompt => ""; - uri IMediaType.Uri => UriString; - uri IHaveAuri.Uri => UriString; + // uri IMediaType.Uri => UriString; + // uri IHaveAuri.Uri => UriString; object IHaveAValue.Value => Value; diff --git a/src/Http/Services/CorsOptions.cs b/src/Http/Services/CorsOptions.cs index 1313fac4..7d7ad74c 100644 --- a/src/Http/Services/CorsOptions.cs +++ b/src/Http/Services/CorsOptions.cs @@ -10,10 +10,15 @@ namespace Dgmjr.AspNetCore.Http.Services; string, Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicy >; -using ICorsPolicyCollection = ICollection>; -using ICorsPolicyEnumerable = IEnumerable>; +using ICorsPolicyCollection = ICollection< + KeyValuePair +>; +using ICorsPolicyEnumerable = IEnumerable< + KeyValuePair +>; using System.Diagnostics.CodeAnalysis; +/// public class CorsOptions : Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions { public CorsOptions() { } @@ -22,12 +27,15 @@ public CorsOptions() { } public CorsOptions(IConfigurationSection section) => section.Bind(this); - public CorsOptions(ICorsPolicyEnumerable collection) => - collection.ToList().ForEach(Add); + public CorsOptions(ICorsPolicyEnumerable collection) => collection.ToList().ForEach(Add); public CorsOptions(int capacity) { } - public CorsPolicy this[string key] { get => Policies[key]; set => Policies[key] = value; } + public CorsPolicy this[string key] + { + get => Policies[key]; + set => Policies[key] = value; + } public ICorsPolicyDictionary Policies { get; } = new CorsPolicyDictionary(); diff --git a/src/Http/Services/ExceptionHandlerOptions.cs b/src/Http/Services/ExceptionHandlerOptions.cs new file mode 100644 index 00000000..99f2524c --- /dev/null +++ b/src/Http/Services/ExceptionHandlerOptions.cs @@ -0,0 +1,6 @@ +namespace Dgmjr.AspNetCore.Http; + +public class ExceptionHandlerOptions : Microsoft.AspNetCore.Builder.ExceptionHandlerOptions +{ + public bool UseDeveloperExceptionPage { get; set; } = false; +} diff --git a/src/Http/Services/AddHttpServicesExtensions.cs b/src/Http/Services/HttpServicesExtensions.AddHttpServices.cs similarity index 95% rename from src/Http/Services/AddHttpServicesExtensions.cs rename to src/Http/Services/HttpServicesExtensions.AddHttpServices.cs index b81432fb..4979fa2b 100644 --- a/src/Http/Services/AddHttpServicesExtensions.cs +++ b/src/Http/Services/HttpServicesExtensions.AddHttpServices.cs @@ -146,7 +146,7 @@ public static IHostApplicationBuilder AddHttpServices( if (options.ExceptionHandling != null) { - builder.Services.Configure( + builder.Services.Configure( options => builder.Configuration.Bind( $"{configurationSectionKey}:{ExceptionHandling}", diff --git a/src/Http/Services/UseHttpServicesExtensions.cs b/src/Http/Services/HttpServicesExtensions.UseHttpServices.cs similarity index 93% rename from src/Http/Services/UseHttpServicesExtensions.cs rename to src/Http/Services/HttpServicesExtensions.UseHttpServices.cs index efa457bd..f913215a 100644 --- a/src/Http/Services/UseHttpServicesExtensions.cs +++ b/src/Http/Services/HttpServicesExtensions.UseHttpServices.cs @@ -106,6 +106,11 @@ public static IApplicationBuilder UseHttpServices(this IApplicationBuilder app) app.UseHttpsRedirection(); } + if(options.ExceptionHandling?.UseDeveloperExceptionPage == true) + { + app.UseDeveloperExceptionPage(); + } + if(options.UseExceptionHandler) { app.UseExceptionHandler(options.ExceptionHandling); diff --git a/src/Http/Services/HttpServicesOptions.cs b/src/Http/Services/HttpServicesOptions.cs index b0853063..0e315c62 100644 --- a/src/Http/Services/HttpServicesOptions.cs +++ b/src/Http/Services/HttpServicesOptions.cs @@ -19,35 +19,94 @@ namespace Dgmjr.AspNetCore.Http; public interface IHttpServicesOptions { + /// TRUE if you want to enable the welcome page, FALSE otherwise bool UseWelcomePage { get; set; } + + /// WelcomePageOptions WelcomePage { get; set; } + + /// TRUE if you want to enable the cookie policy, FALSE otherwise bool UseCookiePolicy { get; set; } + + /// CookiePolicyOptions CookiePolicy { get; set; } + + /// CorsOptions Cors { get; set; } + + /// TRUE if you want to enable CORS, FALSE otherwise bool UseCors { get; set; } + + /// FileServerOptions FileServer { get; set; } + + /// TRUE if you want to enable the files middlewares, FALSE otherwise bool UseFileServer { get; set; } + + /// TRUE if you want to enable the static files middleware, FALSE otherwise bool UseStaticFiles { get; set; } + + /// TRUE if you want to enable the forwarded headers middleware, FALSE otherwise bool UseForwardedHeaders { get; set; } + + /// ForwardedHeadersOptions ForwardedHeaders { get; set; } + + /// HstsOptions Hsts { get; set; } + + /// TRUE if you want to enable the HSTS middleware, FALSE otherwise bool UseHsts { get; set; } + + /// HttpsRedirectionOptions HttpsRedirection { get; set; } + + /// TRUE if you want to enable HTTPS redirection, FALSE otherwise bool UseHttpsRedirection { get; set; } + + /// IISServerOptions IIS { get; set; } + + /// KestrelServerOptions Kestrel { get; set; } + + /// OutputCacheOptions OutputCache { get; set; } + + /// TRUE if you want to enable the output caching middleware, FALSE otherwise bool UseOutputCaching { get; set; } + + /// RequestDecompressionOptions RequestDecompression { get; set; } + + /// TRUE if you want to enable the request decompression middleware, FALSE otherwise bool UseRequestDecompression { get; set; } + + /// ResponseCachingOptions ResponseCaching { get; set; } + + /// TRUE if you want to enable the response caching middleware, FALSE otherwise bool UseResponseCaching { get; set; } + + /// ResponseCompressionOptions ResponseCompression { get; set; } + + /// TRUE if you want to enable the response compression middleware, FALSE otherwise bool UseResponseCompression { get; set; } + + /// SessionOptions Session { get; set; } + + /// TRUE if you want to enable the session middleware, FALSE otherwise bool UseSession { get; set; } + + /// TRUE if you want to add an to the DI container, FALSE otherwise bool AddHttpContextAccessor { get; set; } + + /// TRUE if you want to enable the exception handling middleware, FALSE otherwise bool UseExceptionHandler { get; set; } + + /// ExceptionHandlerOptions ExceptionHandling { get; set; } } @@ -81,11 +140,21 @@ private static FileServerOptions DefaultFilFileServerOptions EnableDirectoryBrowsing = true }; _defaultFileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true; - _defaultFileServerOptions.StaticFileOptions.DefaultContentType = Dgmjr.Mime.Application.OctetStream.DisplayName; + _defaultFileServerOptions.StaticFileOptions.DefaultContentType = Dgmjr + .Mime + .Application + .OctetStream + .DisplayName; // _defaultFileServerOptions.FileProvider = new PhysicalFileProvider(Path.Join(Directory.GetCurrentDirectory(), "wwwroot")); // _defaultFileServerOptions.DefaultFilesOptions.FileProvider =_defaultFileServerOptions.FileProvider; - _defaultFileServerOptions.DefaultFilesOptions.DefaultFileNames = new List { "index.html", "index.htm", "swagger.json" }; - _defaultFileServerOptions.StaticFileOptions.ContentTypeProvider = new Dgmjr.AspNetCore.StaticFiles.MimeKitContentTypeProvider(); + _defaultFileServerOptions.DefaultFilesOptions.DefaultFileNames = new List + { + "index.html", + "index.htm", + "swagger.json" + }; + _defaultFileServerOptions.StaticFileOptions.ContentTypeProvider = + new Dgmjr.AspNetCore.StaticFiles.MimeKitContentTypeProvider(); // _defaultFileServerOptions.DirectoryBrowserOptions.FileProvider = _defaultFileServerOptions.FileProvider; _defaultFileServerOptions.DirectoryBrowserOptions.RequestPath = "/wwwroot"; return _defaultFileServerOptions; @@ -116,14 +185,20 @@ private static FileServerOptions DefaultFilFileServerOptions public ResponseCachingOptions ResponseCaching { get; set; } = new(); public bool UseResponseCaching { get; set; } = true; - public ResponseCompressionOptions ResponseCompression { get; set; } = new() { MimeTypes = ResponseCompressionDefaults.MimeTypes }; + public ResponseCompressionOptions ResponseCompression { get; set; } = + new() { MimeTypes = ResponseCompressionDefaults.MimeTypes }; public bool UseResponseCompression { get; set; } = true; - public SessionOptions Session { get; set; } = new() { Cookie = new() { Name = SessionDefaults.CookieName, Path = SessionDefaults.CookiePath } }; + public SessionOptions Session { get; set; } = + new() + { + Cookie = new() { Name = SessionDefaults.CookieName, Path = SessionDefaults.CookiePath } + }; public bool UseSession { get; set; } = true; public bool AddHttpContextAccessor { get; set; } = true; public bool UseExceptionHandler { get; set; } = true; - public ExceptionHandlerOptions ExceptionHandling { get; set; } = new() { ExceptionHandlingPath = "/error" }; + public ExceptionHandlerOptions ExceptionHandling { get; set; } = + new() { ExceptionHandlingPath = "/error" }; } diff --git a/src/Http/Services/HttpServicesOptionsAutoConfigurator.cs b/src/Http/Services/HttpServicesOptionsAutoConfigurator.cs index d3e7a537..398b4152 100644 --- a/src/Http/Services/HttpServicesOptionsAutoConfigurator.cs +++ b/src/Http/Services/HttpServicesOptionsAutoConfigurator.cs @@ -1,9 +1,12 @@ namespace Microsoft.Extensions.DependencyInjection; + using Dgmjr.Configuration.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -public class HttpServicesOptionsAutoConfigurator : IConfigureIHostApplicationBuilder, IConfigureIApplicationBuilder +public class HttpServicesOptionsAutoConfigurator + : IConfigureIHostApplicationBuilder, + IConfigureIApplicationBuilder { public ConfigurationOrder Order => ConfigurationOrder.AnyTime; diff --git a/src/MicrosoftGraph/Dgmjr.Graph.csproj b/src/MicrosoftGraph/Dgmjr.Graph.csproj index 6ea36ced..e046adce 100644 --- a/src/MicrosoftGraph/Dgmjr.Graph.csproj +++ b/src/MicrosoftGraph/Dgmjr.Graph.csproj @@ -39,7 +39,7 @@ - + diff --git a/src/MicrosoftGraph/Dgmjr.Graph.sln b/src/MicrosoftGraph/Dgmjr.Graph.sln index 7e98e5e5..0c1a1602 100644 --- a/src/MicrosoftGraph/Dgmjr.Graph.sln +++ b/src/MicrosoftGraph/Dgmjr.Graph.sln @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Web.DownstreamApis", "..\DownstreamApis\Dgmjr.Web.DownstreamApis.csproj", "{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Graph", "Dgmjr.Graph.csproj", "{D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Graph", "Dgmjr.Graph.csproj", "{5C8E0E57-5C56-4505-91C3-616D1860A342}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -34,18 +34,18 @@ Global {0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Production|Any CPU.Build.0 = Local|Any CPU {0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Release|Any CPU.ActiveCfg = Release|Any CPU {0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Release|Any CPU.Build.0 = Release|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Local|Any CPU.ActiveCfg = Local|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Local|Any CPU.Build.0 = Local|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Testing|Any CPU.ActiveCfg = Testing|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Testing|Any CPU.Build.0 = Testing|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Staging|Any CPU.ActiveCfg = Staging|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Staging|Any CPU.Build.0 = Staging|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Production|Any CPU.ActiveCfg = Local|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Production|Any CPU.Build.0 = Local|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D6E3A1A7-6CE2-4CB6-AB20-AD3C525E5E23}.Release|Any CPU.Build.0 = Release|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Local|Any CPU.ActiveCfg = Local|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Local|Any CPU.Build.0 = Local|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Testing|Any CPU.Build.0 = Testing|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Staging|Any CPU.Build.0 = Staging|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Production|Any CPU.ActiveCfg = Local|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Production|Any CPU.Build.0 = Local|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C8E0E57-5C56-4505-91C3-616D1860A342}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Mvc/LICENSE.md b/src/Mvc/LICENSE.md old mode 100755 new mode 100644 index c80a6760..4f592f86 --- a/src/Mvc/LICENSE.md +++ b/src/Mvc/LICENSE.md @@ -1,21 +1,21 @@ --- -date: 2023-07-13T05:44:46:00+05:00Z +date: 2023-07-13T05:44:46:00-05:00Z description: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, yadda, yadda, yadda... keywords: - - IP - - copyright - - license - - mit +- IP +- copyright +- license +- mit permissions: - - commercial-use - - modifications - - distribution - - private-use +- commercial-use +- modifications +- distribution +- private-use conditions: - - include-copyright +- include-copyright limitations: - - liability - - warranty +- liability +- warranty lastmod: 2024-01-0T00:39:00.0000+05:00Z license: MIT slug: mit-license @@ -25,7 +25,7 @@ type: license # MIT License -## Copyright © 2022-2023 [David G. Moore, Jr.](mailto:david@dgmjr.io "Send Dr. Moore an email") ([@dgmjr](https://github.com/dgmjr "Contact Dr. Moore on GitHub")), All Rights Reserved +## Copyright © 2022-2024 [David G. Moore, Jr.](mailto:david@dgmjr.io "Send Dr. Moore") ([@dgmjr](https://github.com/dgmjr "Contact Dr. Moore on GitHub")), All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/Mvc/MvcAutoConfigurator.cs b/src/Mvc/MvcAutoConfigurator.cs index fcc7b08f..7613542a 100644 --- a/src/Mvc/MvcAutoConfigurator.cs +++ b/src/Mvc/MvcAutoConfigurator.cs @@ -1,7 +1,9 @@ -namespace Dgmjr.AspNetCore.Mvc; +namespace Microsoft.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Builder; using Dgmjr.Configuration.Extensions; using static Microsoft.Extensions.DependencyInjection.IHostApplicationBuilderMvcExtensions; + public class MvcAutoConfigurator : IConfigureIHostApplicationBuilder, IConfigureIApplicationBuilder { private const string Mvc = nameof(Mvc);