Skip to content

Commit b95efe9

Browse files
iammukeshmjarvis
andauthored
feat(identity): add ICurrentUserService and IRequestContextService interfaces (#1193)
- Create ICurrentUserService interface combining ICurrentUser and ICurrentUserInitializer - Create IRequestContextService interface extending IRequestContext - Update CurrentUserService to implement ICurrentUserService (internal sealed) - Update RequestContextService to implement IRequestContextService (internal sealed) - Update DI registration to register services with their new interfaces - Maintain backward compatibility with existing ICurrentUser and IRequestContext consumers Closes #1180 Co-authored-by: jarvis <jarvis@codewithmukesh.com>
1 parent 447481a commit b95efe9

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Security.Claims;
2+
using FSH.Framework.Core.Context;
3+
4+
namespace FSH.Modules.Identity.Contracts.Services;
5+
6+
/// <summary>
7+
/// Service interface for managing the current user context.
8+
/// Combines user identity access with initialization capabilities.
9+
/// </summary>
10+
public interface ICurrentUserService : ICurrentUser, ICurrentUserInitializer
11+
{
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using FSH.Framework.Core.Context;
2+
3+
namespace FSH.Modules.Identity.Contracts.Services;
4+
5+
/// <summary>
6+
/// Service interface for accessing HTTP request context information.
7+
/// Provides request metadata for auditing, logging, and other cross-cutting concerns.
8+
/// </summary>
9+
public interface IRequestContextService : IRequestContext
10+
{
11+
}

src/Modules/Identity/Modules.Identity/IdentityModule.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ public void ConfigureServices(IHostApplicationBuilder builder)
7373
ArgumentNullException.ThrowIfNull(builder);
7474
var services = builder.Services;
7575
services.AddSingleton<IAuthorizationMiddlewareResultHandler, PathAwareAuthorizationHandler>();
76-
services.AddScoped<ICurrentUser, CurrentUserService>();
77-
services.AddScoped<IRequestContext, RequestContextService>();
76+
services.AddScoped<ICurrentUserService, CurrentUserService>();
77+
services.AddScoped<ICurrentUser>(sp => sp.GetRequiredService<ICurrentUserService>());
78+
services.AddScoped<ICurrentUserInitializer>(sp => sp.GetRequiredService<ICurrentUserService>());
79+
services.AddScoped<IRequestContextService, RequestContextService>();
80+
services.AddScoped<IRequestContext>(sp => sp.GetRequiredService<IRequestContextService>());
7881
services.AddScoped<ITokenService, TokenService>();
79-
services.AddScoped(sp => (ICurrentUserInitializer)sp.GetRequiredService<ICurrentUser>());
8082

8183
// User services - focused single-responsibility services
8284
services.AddTransient<IUserRegistrationService, UserRegistrationService>();

src/Modules/Identity/Modules.Identity/Services/CurrentUserService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using FSH.Framework.Core.Context;
22
using FSH.Framework.Core.Exceptions;
33
using FSH.Framework.Shared.Identity.Claims;
4+
using FSH.Modules.Identity.Contracts.Services;
45
using System.Security.Claims;
56

67
namespace FSH.Modules.Identity.Services;
78

8-
public class CurrentUserService : ICurrentUser, ICurrentUserInitializer
9+
internal sealed class CurrentUserService : ICurrentUserService
910
{
1011
private ClaimsPrincipal? _user;
1112

src/Modules/Identity/Modules.Identity/Services/RequestContextService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FSH.Framework.Core.Context;
22
using FSH.Framework.Web.Origin;
3+
using FSH.Modules.Identity.Contracts.Services;
34
using Microsoft.AspNetCore.Http;
45
using Microsoft.Extensions.Options;
56

@@ -9,7 +10,7 @@ namespace FSH.Modules.Identity.Services;
910
/// Provides HTTP request context information through an abstraction.
1011
/// This allows handlers to access request metadata without direct ASP.NET Core dependencies.
1112
/// </summary>
12-
public sealed class RequestContextService : IRequestContext
13+
internal sealed class RequestContextService : IRequestContextService
1314
{
1415
private readonly IHttpContextAccessor _httpContextAccessor;
1516
private readonly Uri? _originUrl;

0 commit comments

Comments
 (0)