Skip to content

Commit 51a1f9a

Browse files
committed
Cleaned up accessor usage
1 parent db7058d commit 51a1f9a

2 files changed

Lines changed: 6 additions & 29 deletions

File tree

src/IdentityManager2/Api/Controllers/UsersController.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
using IdentityManager2.Resources;
1010
using Microsoft.AspNetCore.Authorization;
1111
using Microsoft.AspNetCore.Mvc;
12-
using Microsoft.AspNetCore.Mvc.Infrastructure;
13-
using Microsoft.AspNetCore.Mvc.Routing;
1412
using static System.String;
1513

1614
namespace IdentityManager2.Api.Controllers
@@ -21,15 +19,11 @@ namespace IdentityManager2.Api.Controllers
2119
public class UsersController : Controller
2220
{
2321
private readonly IIdentityManagerService service;
24-
private readonly IUrlHelperFactory urlHelperFactory;
25-
private readonly IActionContextAccessor actionContextAccessor;
2622
private IdentityManagerMetadata metadata;
2723

28-
public UsersController(IIdentityManagerService service, IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor)
24+
public UsersController(IIdentityManagerService service)
2925
{
3026
this.service = service ?? throw new ArgumentNullException(nameof(service));
31-
this.urlHelperFactory = urlHelperFactory ?? throw new ArgumentNullException(nameof(urlHelperFactory));
32-
this.actionContextAccessor = actionContextAccessor ?? throw new ArgumentNullException(nameof(actionContextAccessor));
3327
}
3428

3529
public async Task<IdentityManagerMetadata> GetMetadataAsync()
@@ -52,9 +46,7 @@ public async Task<IActionResult> GetUsersAsync(string filter = null, int start =
5246
{
5347
var meta = await GetMetadataAsync();
5448

55-
var resource = new UserQueryResultResource(result.Result,
56-
urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext),
57-
meta.UserMetadata);
49+
var resource = new UserQueryResultResource(result.Result, Url, meta.UserMetadata);
5850
return Ok(resource);
5951
}
6052

@@ -82,13 +74,11 @@ public async Task<IActionResult> CreateUserAsync([FromBody] PropertyValue[] prop
8274
var result = await service.CreateUserAsync(properties);
8375
if (result.IsSuccess)
8476
{
85-
var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
86-
87-
var url = urlHelper.Link(IdentityManagerConstants.RouteNames.GetUser, new { subject = result.Result.Subject });
77+
var url = Url.Link(IdentityManagerConstants.RouteNames.GetUser, new {subject = result.Result.Subject});
8878
var resource = new
8979
{
90-
Data = new { subject = result.Result.Subject },
91-
Links = new { detail = url }
80+
Data = new {subject = result.Result.Subject},
81+
Links = new {detail = url}
9282
};
9383

9484
return Created(url, resource);

src/IdentityManager2/Configuration/DependencyInjection/IdentityManagerServiceCollectionExtensions.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
using IdentityManager2;
44
using IdentityManager2.Configuration;
55
using Microsoft.AspNetCore.Http;
6-
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.AspNetCore.Mvc.Infrastructure;
8-
using Microsoft.AspNetCore.Mvc.Routing;
9-
using Microsoft.Extensions.DependencyInjection.Extensions;
106
using Microsoft.Extensions.Options;
117

128
namespace Microsoft.Extensions.DependencyInjection
@@ -19,18 +15,10 @@ public static IIdentityManagerBuilder AddIdentityManager(this IServiceCollection
1915

2016
var identityManagerOptions = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityManagerOptions>>().Value;
2117
identityManagerOptions.Validate();
22-
18+
2319
services.AddControllersWithViews()
2420
.AddNewtonsoftJson();
2521

26-
services.AddHttpContextAccessor();
27-
services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
28-
services.TryAddSingleton<IUrlHelper>(x =>
29-
{
30-
var actionContext = x.GetService<IActionContextAccessor>().ActionContext;
31-
return new UrlHelper(actionContext);
32-
});
33-
3422
// IdentityManager API authentication scheme
3523
services.AddAuthentication()
3624
.AddCookie(IdentityManagerConstants.LocalApiScheme, options =>
@@ -44,7 +32,6 @@ public static IIdentityManagerBuilder AddIdentityManager(this IServiceCollection
4432
// TODO: API Cookie: SlidingExpiration
4533
// TODO: API Cookie: ExpireTimeSpan
4634

47-
//options.ForwardChallenge = identityManagerOptions.SecurityConfiguration.HostChallengeType;
4835
options.LoginPath = "/api/login";
4936

5037
options.Events.OnRedirectToLogin = context =>

0 commit comments

Comments
 (0)