diff --git a/DigitalData.Core.API/DIExtensions.cs b/DigitalData.Core.API/DIExtensions.cs
index 3a6fa68..a1145b1 100644
--- a/DigitalData.Core.API/DIExtensions.cs
+++ b/DigitalData.Core.API/DIExtensions.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder;
+using System.Configuration;
namespace DigitalData.Core.API
{
@@ -47,5 +48,22 @@ namespace DigitalData.Core.API
/// The WebApplication instance.
/// True if the environment is Development or DiP mode is enabled; otherwise, false.
public static bool IsDevOrDiP(this WebApplication app) => app.Environment.IsDevelopment() || app.IsDiP();
- }
+
+ ///
+ /// Configures the services with options from the specified section of the appsettings.json file.
+ ///
+ /// The options class type. Must be a reference type.
+ /// The WebApplicationBuilder instance.
+ /// The WebApplicationBuilder instance for chaining.
+ /// Thrown if the section is not found in the configuration.
+ public static WebApplicationBuilder ConfigureBySection(this WebApplicationBuilder builder) where T : class
+ {
+ var section = builder.Configuration.GetSection(typeof(T).Name);
+ if (!section.Exists())
+ throw new InvalidOperationException($"Section '{typeof(T).Name}' not found in appsettings.");
+
+ builder.Services.Configure(section);
+ return builder;
+ }
+ }
}
\ No newline at end of file