Skip to content

Commit 1f9966b

Browse files
author
Vadim Belov
committed
Refactor EasyStackOptions and improve API usability
Renamed `AddAuthorization` to `AuthorizationEnabled` and changed its access modifier to `internal`. Added a new `AddAuthorization()` method to enable authorization with method chaining. Enhanced `WithPostgres<TDbContext>()` to include an optional `useLazyLoadingProxies` parameter, allowing configuration of lazy loading proxies. Updated XML documentation for better clarity. Updated `HostApplicationBuilderExtensions` to use the renamed `AuthorizationEnabled` property for consistency. Note: Exception message referencing "Set AddPostgres to true" remains unchanged and may need review.
1 parent dfb12f9 commit 1f9966b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Sources/EasyExtensions.AspNetCore.Stack/Builders/EasyStackOptions.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ public class EasyStackOptions
2020
/// <summary>
2121
/// Gets or sets a value indicating whether authorization should be added to the request.
2222
/// </summary>
23-
public bool AddAuthorization { get; set; }
23+
internal bool AuthorizationEnabled { get; set; }
24+
25+
/// <summary>
26+
/// Enables authorization for the current EasyStackOptions instance.
27+
/// </summary>
28+
/// <returns>The current EasyStackOptions instance with authorization enabled.</returns>
29+
public EasyStackOptions AddAuthorization()
30+
{
31+
AuthorizationEnabled = true;
32+
return this;
33+
}
2434

2535
/// <summary>
2636
/// Gets or sets the delegate used to configure database services and health checks during application startup.
@@ -31,14 +41,22 @@ public class EasyStackOptions
3141
/// and monitoring.</remarks>
3242
public Action<IServiceCollection, IHealthChecksBuilder, IConfiguration>? ConfigureDatabase { get; set; }
3343

34-
35-
public EasyStackOptions WithPostgres<TDbContext>() where TDbContext : AuditedDbContext
44+
/// <summary>
45+
/// Configures the application to use PostgreSQL as the database provider with the specified audited DbContext
46+
/// type.
47+
/// </summary>
48+
/// <remarks>This method registers the specified DbContext for use with PostgreSQL and adds a
49+
/// health check for the database connection. Lazy loading proxies are disabled by default for the registered
50+
/// DbContext.</remarks>
51+
/// <typeparam name="TDbContext">The type of the DbContext to use for PostgreSQL integration. Must inherit from AuditedDbContext.</typeparam>
52+
/// <returns>The current EasyStackOptions instance for method chaining.</returns>
53+
public EasyStackOptions WithPostgres<TDbContext>(bool useLazyLoadingProxies = false) where TDbContext : AuditedDbContext
3654
{
3755
ConfigureDatabase = (services, hc, cfg) =>
3856
{
3957
services.AddPostgresDbContext<TDbContext>(db =>
4058
{
41-
db.UseLazyLoadingProxies = false;
59+
db.UseLazyLoadingProxies = useLazyLoadingProxies;
4260
});
4361

4462
hc.AddCheck<DatabaseHealthCheck<TDbContext>>("Database");

Sources/EasyExtensions.AspNetCore.Stack/Extensions/HostApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static IHostApplicationBuilder AddEasyStack(
143143
logger.LogInformation("Added Postgres DbContext and Database health check");
144144
}
145145

146-
if (options.AddAuthorization)
146+
if (options.AuthorizationEnabled)
147147
{
148148
if (options.ConfigureDatabase == null)
149149
{

0 commit comments

Comments
 (0)