Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 4282f37

Browse files
author
Benjamin Grabkowitz
committed
Renaming GetAsync() method to Value property to more duck type Lazy<T> and reduce the scope of this pull request to just the AsyncLazy class.
No logic changes.
1 parent 104d3e7 commit 4282f37

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/IdentityModel.AspNetCore.OAuth2Introspection/Infrastructure/AsyncLazy.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ public AsyncLazy(Func<Task<T>> taskFactory)
1717
_taskFactory = taskFactory;
1818
_lazyTaskFactory = InitLazy(_taskFactory);
1919
}
20-
21-
public Task<T> GetAsync()
22-
{
23-
//If the lazy value is not yet created, we should just return the lazy value (which will create it)
24-
//If the value has been created and the value (which is a Task<T>) is not faulted, we should just return the value;
25-
if(!(_lazyTaskFactory.IsValueCreated && _lazyTaskFactory.Value.IsFaulted)) return _lazyTaskFactory.Value;
2620

27-
lock (_lazyInitializationGuard)
21+
public Task<T> Value
22+
{
23+
get
2824
{
29-
if (_lazyTaskFactory.IsValueCreated && _lazyTaskFactory.Value.IsFaulted)
25+
//If the lazy value is not yet created, we should just return the lazy value (which will create it)
26+
//If the value has been created and the value (which is a Task<T>) is not faulted, we should just return the value;
27+
if (!(_lazyTaskFactory.IsValueCreated && _lazyTaskFactory.Value.IsFaulted))
28+
return _lazyTaskFactory.Value;
29+
30+
lock (_lazyInitializationGuard)
3031
{
31-
_lazyTaskFactory = InitLazy(_taskFactory);
32-
}
32+
if (_lazyTaskFactory.IsValueCreated && _lazyTaskFactory.Value.IsFaulted)
33+
{
34+
_lazyTaskFactory = InitLazy(_taskFactory);
35+
}
3336

34-
return _lazyTaskFactory.Value;
37+
return _lazyTaskFactory.Value;
38+
}
3539
}
3640
}
3741

src/IdentityModel.AspNetCore.OAuth2Introspection/OAuth2IntrospectionHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
9191

9292
try
9393
{
94-
var response = await lazyIntrospection.GetAsync().ConfigureAwait(false);
94+
var response = await lazyIntrospection.Value.ConfigureAwait(false);
9595

9696
if (response.IsError)
9797
{
@@ -139,7 +139,7 @@ private AsyncLazy<IntrospectionResponse> CreateLazyIntrospection(string token)
139139

140140
private async Task<IntrospectionResponse> LoadClaimsForToken(string token)
141141
{
142-
var introspectionClient = await Options.IntrospectionClient.GetAsync().ConfigureAwait(false);
142+
var introspectionClient = await Options.IntrospectionClient.Value.ConfigureAwait(false);
143143

144144
return await introspectionClient.SendAsync(new IntrospectionRequest
145145
{

0 commit comments

Comments
 (0)