Skip to content

Commit

Permalink
Merge pull request #1271 from DuendeSoftware/joe/dcr-startup
Browse files Browse the repository at this point in the history
Improve DCR startup
  • Loading branch information
brockallen committed May 9, 2023
2 parents f3f90a1 + 5b3bd43 commit 437c84a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer.Services;
using Microsoft.AspNetCore.Http;

namespace Duende.IdentityServer.Configuration.EntityFramework;

/// <summary>
/// Provides cancellation tokens based on the incoming http request
/// </summary>
class DefaultCancellationTokenProvider : ICancellationTokenProvider
{
private readonly IHttpContextAccessor _httpContextAccessor;

/// <summary>
/// Constructor
/// </summary>
/// <param name="httpContextAccessor"></param>
public DefaultCancellationTokenProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

/// <summary>
/// Provides access to the cancellation token from the http context
/// </summary>
public CancellationToken CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Configuration\Duende.IdentityServer.Configuration.csproj" />
<ProjectReference Include="..\Storage\Duende.IdentityServer.Storage.csproj" />
<ProjectReference Include="..\Configuration\Duende.IdentityServer.Configuration.csproj" />
<ProjectReference Include="..\Storage\Duende.IdentityServer.Storage.csproj" />
<ProjectReference Include="..\EntityFramework.Storage\Duende.IdentityServer.EntityFramework.Storage.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Duende.IdentityServer.Configuration.EntityFramework;

Expand All @@ -18,6 +21,8 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddClientConfigurationStore(this IdentityServerConfigurationBuilder builder)
{
builder.Services.TryAddTransient<ICancellationTokenProvider, DefaultCancellationTokenProvider>();
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
return builder.Services.AddTransient<IClientConfigurationStore, ClientConfigurationStore>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static IIdentityServerBuilder AddCoreServices(this IIdentityServerBuilder
/// <returns></returns>
public static IIdentityServerBuilder AddPluggableServices(this IIdentityServerBuilder builder)
{
builder.Services.TryAddTransient<ICancellationTokenProvider, DefaultHttpContextCancellationTokenICancellationTokenProvider>();
builder.Services.TryAddTransient<ICancellationTokenProvider, DefaultCancellationTokenProvider>();
builder.Services.TryAddTransient<IPersistedGrantService, DefaultPersistedGrantService>();
builder.Services.TryAddTransient<IKeyMaterialService, DefaultKeyMaterialService>();
builder.Services.TryAddTransient<ITokenService, DefaultTokenService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Http;
using System.Threading;

namespace Duende.IdentityServer.Services.Default;

/// <summary>
/// Provides cancellation tokens based on the incoming http request
/// </summary>
class DefaultCancellationTokenProvider : ICancellationTokenProvider
{
private readonly IHttpContextAccessor _httpContextAccessor;

/// <summary>
/// Constructor
/// </summary>
/// <param name="httpContextAccessor"></param>
public DefaultCancellationTokenProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

/// <summary>
/// Provides access to the cancellation token from the http context
/// </summary>
public CancellationToken CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None;
}

This file was deleted.

0 comments on commit 437c84a

Please sign in to comment.