Skip to content

Commit a204403

Browse files
authoredMar 18, 2025
feat: better async backported (#951)
1 parent d362399 commit a204403

24 files changed

+93
-127
lines changed
 

‎src/Directory.Build.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
<PackageProjectUrl>https://www.finbuckle.com/MultiTenant</PackageProjectUrl>
99
<RepositoryUrl>https://github.com/Finbuckle/Finbuckle.MultiTenant</RepositoryUrl>
1010
<PublishRepositoryUrl>true</PublishRepositoryUrl>
11-
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1211
<IncludeSymbols>true</IncludeSymbols>
1312
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
14-
<PackageTags>finbuckle;multitenant;multitenancy;aspnet;aspnetcore;entityframework;entityframework-core;efcore</PackageTags>
13+
<PackageTags>finbuckle;multitenant;multitenancy;aspnet;aspnetcore;entityframeworkcore;efcore</PackageTags>
1514
<PackageIcon>finbuckle-128x128.png</PackageIcon>
1615
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1716
<NoWarn>CS1591</NoWarn>

‎src/Finbuckle.MultiTenant.AspNetCore/Extensions/MultiTenantBuilderExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static MultiTenantBuilder<TTenantInfo> WithPerTenantAuthenticationConvent
9191
if (!string.Equals(currentTenant, authTenant, StringComparison.OrdinalIgnoreCase))
9292
context.RejectPrincipal();
9393

94-
await origOnValidatePrincipal(context);
94+
await origOnValidatePrincipal(context).ConfigureAwait(false);
9595
};
9696
});
9797

@@ -347,7 +347,7 @@ private static void BypassSessionPrincipalValidation<TTenantInfo>(
347347
$"{Constants.TenantToken}__bypass_validate_principal__"))
348348
return;
349349

350-
await origOnValidatePrincipal(context);
350+
await origOnValidatePrincipal(context).ConfigureAwait(false);
351351
};
352352
});
353353
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>

‎src/Finbuckle.MultiTenant.AspNetCore/Internal/MultiTenantAuthenticationSchemeProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public MultiTenantAuthenticationSchemeProvider(IAuthenticationSchemeProvider inn
133133

134134
if (_inner != null)
135135
{
136-
scheme = await _inner.GetSchemeAsync(name);
136+
scheme = await _inner.GetSchemeAsync(name).ConfigureAwait(false);
137137
}
138138

139139
if (scheme == null)

‎src/Finbuckle.MultiTenant.AspNetCore/Internal/MultiTenantAuthenticationService.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ public async Task ChallengeAsync(HttpContext context, string? scheme, Authentica
4949
}
5050

5151
AddTenantIdentifierToProperties(context, ref properties);
52-
await _inner.ChallengeAsync(context, scheme, properties);
52+
await _inner.ChallengeAsync(context, scheme, properties).ConfigureAwait(false);
5353
}
5454

5555
public async Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
5656
{
5757
AddTenantIdentifierToProperties(context, ref properties);
58-
await _inner.ForbidAsync(context, scheme, properties);
58+
await _inner.ForbidAsync(context, scheme, properties).ConfigureAwait(false);
5959
}
6060

6161
public async Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties)
6262
{
6363
AddTenantIdentifierToProperties(context, ref properties);
64-
await _inner.SignInAsync(context, scheme, principal, properties);
64+
await _inner.SignInAsync(context, scheme, principal, properties).ConfigureAwait(false);
6565
}
6666

6767
public async Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
6868
{
6969
AddTenantIdentifierToProperties(context, ref properties);
70-
await _inner.SignOutAsync(context, scheme, properties);
70+
await _inner.SignOutAsync(context, scheme, properties).ConfigureAwait(false);
7171
}
7272
}

‎src/Finbuckle.MultiTenant.AspNetCore/Internal/MultiTenantMiddleware.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public async Task Invoke(HttpContext context)
2727

2828
var resolver = context.RequestServices.GetRequiredService<ITenantResolver>();
2929

30-
var multiTenantContext = await resolver.ResolveAsync(context);
30+
var multiTenantContext = await resolver.ResolveAsync(context).ConfigureAwait(false);
3131
mtcSetter.MultiTenantContext = multiTenantContext;
3232
context.Items[typeof(IMultiTenantContext)] = multiTenantContext;
3333

34-
await next(context);
34+
await next(context).ConfigureAwait(false);
3535
}
3636
}

‎src/Finbuckle.MultiTenant.AspNetCore/Strategies/ClaimStrategy.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public ClaimStrategy(string template, string? authenticationScheme)
4343
var schemeProvider = httpContext.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
4444
if (_authenticationScheme is null)
4545
{
46-
authScheme = await schemeProvider.GetDefaultAuthenticateSchemeAsync();
46+
authScheme = await schemeProvider.GetDefaultAuthenticateSchemeAsync().ConfigureAwait(false);
4747
}
4848
else
4949
{
5050
authScheme =
51-
(await schemeProvider.GetAllSchemesAsync()).FirstOrDefault(x => x.Name == _authenticationScheme);
51+
(await schemeProvider.GetAllSchemesAsync().ConfigureAwait(false)).FirstOrDefault(x => x.Name == _authenticationScheme);
5252
}
5353

5454
if (authScheme is null)
@@ -59,9 +59,9 @@ public ClaimStrategy(string template, string? authenticationScheme)
5959
var handler =
6060
(IAuthenticationHandler)ActivatorUtilities.CreateInstance(httpContext.RequestServices,
6161
authScheme.HandlerType);
62-
await handler.InitializeAsync(authScheme, httpContext);
62+
await handler.InitializeAsync(authScheme, httpContext).ConfigureAwait(false);
6363
httpContext.Items[$"{Constants.TenantToken}__bypass_validate_principal__"] = "true"; // Value doesn't matter.
64-
var handlerResult = await handler.AuthenticateAsync();
64+
var handlerResult = await handler.AuthenticateAsync().ConfigureAwait(false);
6565
httpContext.Items.Remove($"{Constants.TenantToken}__bypass_validate_principal__");
6666

6767
var identifier = handlerResult.Principal?.FindFirst(_tenantKey)?.Value;

‎src/Finbuckle.MultiTenant.AspNetCore/Strategies/RemoteAuthenticationCallbackStrategy.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public RemoteAuthenticationCallbackStrategy(ILogger<RemoteAuthenticationCallback
3636

3737
var schemes = httpContext.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
3838

39-
foreach (var scheme in (await schemes.GetRequestHandlerSchemesAsync()).Where(s =>
39+
foreach (var scheme in (await schemes.GetRequestHandlerSchemesAsync().ConfigureAwait(false)).Where(s =>
4040
typeof(IAuthenticationRequestHandler).IsAssignableFrom(s.HandlerType)))
4141
{
4242
// TODO verify this comment (still true as of net8.0)
@@ -83,7 +83,7 @@ public RemoteAuthenticationCallbackStrategy(ILogger<RemoteAuthenticationCallback
8383
{
8484
var formOptions = new FormOptions { BufferBody = true, MemoryBufferThreshold = 1048576 };
8585

86-
var form = await httpContext.Request.ReadFormAsync(formOptions);
86+
var form = await httpContext.Request.ReadFormAsync(formOptions).ConfigureAwait(false);
8787
state = form.Single(i => string.Equals(i.Key, "state", StringComparison.OrdinalIgnoreCase))
8888
.Value;
8989
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>

‎src/Finbuckle.MultiTenant.EntityFrameworkCore/MultiTenantDbContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
6969
CancellationToken cancellationToken = default(CancellationToken))
7070
{
7171
this.EnforceMultiTenant();
72-
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
72+
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken).ConfigureAwait(false);
7373
}
7474
}

‎src/Finbuckle.MultiTenant.EntityFrameworkCore/MultiTenantIdentityDbContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,6 @@ public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
203203
CancellationToken cancellationToken = default(CancellationToken))
204204
{
205205
this.EnforceMultiTenant();
206-
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
206+
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken).ConfigureAwait(false);
207207
}
208208
}

‎src/Finbuckle.MultiTenant.EntityFrameworkCore/Stores/EFCoreStore/EFCoreStore.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ public EFCoreStore(TEFCoreStoreDbContext dbContext)
2525
{
2626
return await dbContext.TenantInfo.AsNoTracking()
2727
.Where(ti => ti.Id == id)
28-
.SingleOrDefaultAsync();
28+
.SingleOrDefaultAsync().ConfigureAwait(false);
2929
}
3030

3131
public virtual async Task<IEnumerable<TTenantInfo>> GetAllAsync()
3232
{
33-
return await dbContext.TenantInfo.AsNoTracking().ToListAsync();
33+
return await dbContext.TenantInfo.AsNoTracking().ToListAsync().ConfigureAwait(false);
3434
}
3535

3636
public virtual async Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier)
3737
{
3838
return await dbContext.TenantInfo.AsNoTracking()
3939
.Where(ti => ti.Identifier == identifier)
40-
.SingleOrDefaultAsync();
40+
.SingleOrDefaultAsync().ConfigureAwait(false);
4141
}
4242

4343
public virtual async Task<bool> TryAddAsync(TTenantInfo tenantInfo)
4444
{
45-
await dbContext.TenantInfo.AddAsync(tenantInfo);
46-
var result = await dbContext.SaveChangesAsync() > 0;
45+
await dbContext.TenantInfo.AddAsync(tenantInfo).ConfigureAwait(false);
46+
var result = await dbContext.SaveChangesAsync().ConfigureAwait(false) > 0;
4747
dbContext.Entry(tenantInfo).State = EntityState.Detached;
4848

4949
return result;
@@ -53,21 +53,21 @@ public virtual async Task<bool> TryRemoveAsync(string identifier)
5353
{
5454
var existing = await dbContext.TenantInfo
5555
.Where(ti => ti.Identifier == identifier)
56-
.SingleOrDefaultAsync();
56+
.SingleOrDefaultAsync().ConfigureAwait(false);
5757

5858
if (existing is null)
5959
{
6060
return false;
6161
}
6262

6363
dbContext.TenantInfo.Remove(existing);
64-
return await dbContext.SaveChangesAsync() > 0;
64+
return await dbContext.SaveChangesAsync().ConfigureAwait(false) > 0;
6565
}
6666

6767
public virtual async Task<bool> TryUpdateAsync(TTenantInfo tenantInfo)
6868
{
6969
dbContext.TenantInfo.Update(tenantInfo);
70-
var result = await dbContext.SaveChangesAsync() > 0;
70+
var result = await dbContext.SaveChangesAsync().ConfigureAwait(false) > 0;
7171
dbContext.Entry(tenantInfo).State = EntityState.Detached;
7272
return result;
7373
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>

‎src/Finbuckle.MultiTenant/Stores/ConfigurationStore/ConfigurationStore.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ public Task<bool> TryAddAsync(TTenantInfo tenantInfo)
9393
throw new ArgumentNullException(nameof(id));
9494
}
9595

96-
return await Task.FromResult(tenantMap?.Where(kv => kv.Value.Id == id).SingleOrDefault().Value);
96+
return await Task.FromResult(tenantMap?.Where(kv => kv.Value.Id == id).SingleOrDefault().Value).ConfigureAwait(false);
9797
}
9898

9999
/// <inheritdoc />
100100
public async Task<IEnumerable<TTenantInfo>> GetAllAsync()
101101
{
102-
return await Task.FromResult(tenantMap?.Select(x => x.Value).ToList() ?? new List<TTenantInfo>());
102+
return await Task.FromResult(tenantMap?.Select(x => x.Value).ToList() ?? new List<TTenantInfo>()).ConfigureAwait(false);
103103
}
104104

105105
/// <inheritdoc />
@@ -115,7 +115,7 @@ public async Task<IEnumerable<TTenantInfo>> GetAllAsync()
115115
return null;
116116
}
117117

118-
return await Task.FromResult(tenantMap.TryGetValue(identifier, out var result) ? result : null);
118+
return await Task.FromResult(tenantMap.TryGetValue(identifier, out var result) ? result : null).ConfigureAwait(false);
119119
}
120120

121121
/// <summary>

‎src/Finbuckle.MultiTenant/Stores/EchoStore/EchoStore.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ namespace Finbuckle.MultiTenant.Stores.EchoStore;
1818
/// <inheritdoc />
1919
public async Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier)
2020
{
21-
return await Task.FromResult(new TTenantInfo { Id = identifier, Identifier = identifier });
21+
return await Task.FromResult(new TTenantInfo { Id = identifier, Identifier = identifier }).ConfigureAwait(false);
2222
}
2323

2424
/// <inheritdoc />
2525
public async Task<TTenantInfo?> TryGetAsync(string id)
2626
{
27-
return await Task.FromResult(new TTenantInfo { Id = id, Identifier = id });
27+
return await Task.FromResult(new TTenantInfo { Id = id, Identifier = id }).ConfigureAwait(false);
2828
}
2929

3030
/// <summary>

‎src/Finbuckle.MultiTenant/Stores/HttpRemoteStore/HttpRemoteStore.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public Task<bool> TryAddAsync(TTenantInfo tenantInfo)
7272
/// <exception cref="NotImplementedException">When a not-found (404) status code is encountered</exception>
7373
public async Task<IEnumerable<TTenantInfo>> GetAllAsync()
7474
{
75-
return await _client.GetAllAsync(endpointTemplate);
75+
return await _client.GetAllAsync(endpointTemplate).ConfigureAwait(false);
7676
}
7777

7878
/// <inheritdoc />
7979
public async Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier)
8080
{
81-
var result = await _client.TryGetByIdentifierAsync(endpointTemplate, identifier);
81+
var result = await _client.TryGetByIdentifierAsync(endpointTemplate, identifier).ConfigureAwait(false);
8282
return result;
8383
}
8484

‎src/Finbuckle.MultiTenant/Stores/HttpRemoteStore/HttpRemoteStoreClient.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public HttpRemoteStoreClient(IHttpClientFactory clientFactory, JsonSerializerOpt
2323
{
2424
var client = clientFactory.CreateClient(typeof(HttpRemoteStoreClient<TTenantInfo>).FullName!);
2525
var uri = endpointTemplate.Replace(HttpRemoteStore<TTenantInfo>.DefaultEndpointTemplateIdentifierToken, identifier);
26-
var response = await client.GetAsync(uri);
26+
var response = await client.GetAsync(uri).ConfigureAwait(false);
2727

2828
if (!response.IsSuccessStatusCode)
2929
return null;
3030

31-
var json = await response.Content.ReadAsStringAsync();
31+
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
3232
var result = JsonSerializer.Deserialize<TTenantInfo>(json, _defaultSerializerOptions);
3333

3434
return result;
@@ -38,7 +38,7 @@ public async Task<IEnumerable<TTenantInfo>> GetAllAsync(string endpointTemplate)
3838
{
3939
var client = clientFactory.CreateClient(typeof(HttpRemoteStoreClient<TTenantInfo>).FullName!);
4040
var uri = endpointTemplate.Replace(HttpRemoteStore<TTenantInfo>.DefaultEndpointTemplateIdentifierToken, string.Empty);
41-
var response = await client.GetAsync(uri);
41+
var response = await client.GetAsync(uri).ConfigureAwait(false);
4242

4343

4444
if (!response.IsSuccessStatusCode)
@@ -52,7 +52,7 @@ public async Task<IEnumerable<TTenantInfo>> GetAllAsync(string endpointTemplate)
5252
return Enumerable.Empty<TTenantInfo>();
5353
}
5454

55-
var json = await response.Content.ReadAsStringAsync();
55+
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
5656
var result = JsonSerializer.Deserialize<IEnumerable<TTenantInfo>>(json, _defaultSerializerOptions);
5757

5858
return result!;

‎src/Finbuckle.MultiTenant/Stores/InMemoryStore/InMemoryStore.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,50 +49,50 @@ public InMemoryStore(IOptions<InMemoryStoreOptions<TTenantInfo>> options)
4949
public async Task<TTenantInfo?> TryGetAsync(string id)
5050
{
5151
var result = _tenantMap.Values.SingleOrDefault(ti => ti.Id == id);
52-
return await Task.FromResult(result);
52+
return await Task.FromResult(result).ConfigureAwait(false);
5353
}
5454

5555
/// <inheritdoc />
5656
public async Task<TTenantInfo?> TryGetByIdentifierAsync(string identifier)
5757
{
5858
_tenantMap.TryGetValue(identifier, out var result);
5959

60-
return await Task.FromResult(result);
60+
return await Task.FromResult(result).ConfigureAwait(false);
6161
}
6262

6363
/// <inheritdoc />
6464
public async Task<IEnumerable<TTenantInfo>> GetAllAsync()
6565
{
66-
return await Task.FromResult(_tenantMap.Select(x => x.Value).ToList());
66+
return await Task.FromResult(_tenantMap.Select(x => x.Value).ToList()).ConfigureAwait(false);
6767
}
6868

6969
/// <inheritdoc />
7070
public async Task<bool> TryAddAsync(TTenantInfo tenantInfo)
7171
{
7272
var result = tenantInfo.Identifier != null && _tenantMap.TryAdd(tenantInfo.Identifier, tenantInfo);
7373

74-
return await Task.FromResult(result);
74+
return await Task.FromResult(result).ConfigureAwait(false);
7575
}
7676

7777
/// <inheritdoc />
7878
public async Task<bool> TryRemoveAsync(string identifier)
7979
{
8080
var result = _tenantMap.TryRemove(identifier, out var _);
8181

82-
return await Task.FromResult(result);
82+
return await Task.FromResult(result).ConfigureAwait(false);
8383
}
8484

8585
/// <inheritdoc />
8686
public async Task<bool> TryUpdateAsync(TTenantInfo tenantInfo)
8787
{
88-
var existingTenantInfo = tenantInfo.Id != null ? await TryGetAsync(tenantInfo.Id) : null;
88+
var existingTenantInfo = tenantInfo.Id != null ? await TryGetAsync(tenantInfo.Id).ConfigureAwait(false) : null;
8989

9090
if (existingTenantInfo?.Identifier != null)
9191
{
9292
var result = _tenantMap.TryUpdate(existingTenantInfo.Identifier, tenantInfo, existingTenantInfo);
93-
return await Task.FromResult(result);
93+
return await Task.FromResult(result).ConfigureAwait(false);
9494
}
9595

96-
return await Task.FromResult(false);
96+
return await Task.FromResult(false).ConfigureAwait(false);
9797
}
9898
}

0 commit comments

Comments
 (0)
Please sign in to comment.