Skip to content

Update templates to use file scoped namespace declarations #34220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dotnet_diagnostic.CA1018.severity = warning
dotnet_diagnostic.CA1047.severity = warning

# CA1305: Specify IFormatProvider
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA1305.severity = suggestion

# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = warning
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "6.0.100-preview.7.21360.1"
"version": "6.0.100-preview.7.21364.4"
},
"tools": {
"dotnet": "6.0.100-preview.7.21360.1",
"dotnet": "6.0.100-preview.7.21364.4",
"runtimes": {
"dotnet/x64": [
"2.1.27",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace MyApp.Namespace
{
namespace MyApp.Namespace;

#if NameIsPage
public class IndexModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
public class IndexModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
#else
public class IndexModel : PageModel
public class IndexModel : PageModel
#endif
{
public void OnGet()
{
public void OnGet()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,65 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;

namespace BlazorServerWeb_CSharp.Areas.Identity
namespace BlazorServerWeb_CSharp.Areas.Identity;

public class RevalidatingIdentityAuthenticationStateProvider<TUser>
: RevalidatingServerAuthenticationStateProvider where TUser : class
{
public class RevalidatingIdentityAuthenticationStateProvider<TUser>
: RevalidatingServerAuthenticationStateProvider where TUser : class
private readonly IServiceScopeFactory _scopeFactory;
private readonly IdentityOptions _options;

public RevalidatingIdentityAuthenticationStateProvider(
ILoggerFactory loggerFactory,
IServiceScopeFactory scopeFactory,
IOptions<IdentityOptions> optionsAccessor)
: base(loggerFactory)
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly IdentityOptions _options;
_scopeFactory = scopeFactory;
_options = optionsAccessor.Value;
}

public RevalidatingIdentityAuthenticationStateProvider(
ILoggerFactory loggerFactory,
IServiceScopeFactory scopeFactory,
IOptions<IdentityOptions> optionsAccessor)
: base(loggerFactory)
protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30);

protected override async Task<bool> ValidateAuthenticationStateAsync(
AuthenticationState authenticationState, CancellationToken cancellationToken)
{
// Get the user manager from a new scope to ensure it fetches fresh data
var scope = _scopeFactory.CreateScope();
try
{
_scopeFactory = scopeFactory;
_options = optionsAccessor.Value;
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<TUser>>();
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
}

protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30);

protected override async Task<bool> ValidateAuthenticationStateAsync(
AuthenticationState authenticationState, CancellationToken cancellationToken)
finally
{
// Get the user manager from a new scope to ensure it fetches fresh data
var scope = _scopeFactory.CreateScope();
try
if (scope is IAsyncDisposable asyncDisposable)
{
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<TUser>>();
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
await asyncDisposable.DisposeAsync();
}
finally
else
{
if (scope is IAsyncDisposable asyncDisposable)
{
await asyncDisposable.DisposeAsync();
}
else
{
scope.Dispose();
}
scope.Dispose();
}
}
}

private async Task<bool> ValidateSecurityStampAsync(UserManager<TUser> userManager, ClaimsPrincipal principal)
private async Task<bool> ValidateSecurityStampAsync(UserManager<TUser> userManager, ClaimsPrincipal principal)
{
var user = await userManager.GetUserAsync(principal);
if (user == null)
{
var user = await userManager.GetUserAsync(principal);
if (user == null)
{
return false;
}
else if (!userManager.SupportsUserSecurityStamp)
{
return true;
}
else
{
var principalStamp = principal.FindFirstValue(_options.ClaimsIdentity.SecurityStampClaimType);
var userStamp = await userManager.GetSecurityStampAsync(user);
return principalStamp == userStamp;
}
return false;
}
else if (!userManager.SupportsUserSecurityStamp)
{
return true;
}
else
{
var principalStamp = principal.FindFirstValue(_options.ClaimsIdentity.SecurityStampClaimType);
var userStamp = await userManager.GetSecurityStampAsync(user);
return principalStamp == userStamp;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace BlazorServerWeb_CSharp.Data
namespace BlazorServerWeb_CSharp.Data;

public class ApplicationDbContext : IdentityDbContext
{
public class ApplicationDbContext : IdentityDbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace BlazorServerWeb_CSharp.Data
namespace BlazorServerWeb_CSharp.Data;

public class WeatherForecast
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public DateTime Date { get; set; }

public int TemperatureC { get; set; }
public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
public string? Summary { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace BlazorServerWeb_CSharp.Data
namespace BlazorServerWeb_CSharp.Data;

public class WeatherForecastService
{
public class WeatherForecastService
private static readonly string[] Summaries = new[]
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace BlazorServerWeb_CSharp.Pages
namespace BlazorServerWeb_CSharp.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using Microsoft.AspNetCore.ApiAuthorization.IdentityServer;
using Microsoft.AspNetCore.Mvc;

namespace ComponentsWebAssembly_CSharp.Server.Controllers
namespace ComponentsWebAssembly_CSharp.Server.Controllers;

public class OidcConfigurationController : Controller
{
public class OidcConfigurationController : Controller
{
private readonly ILogger<OidcConfigurationController> _logger;
private readonly ILogger<OidcConfigurationController> _logger;

public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider, ILogger<OidcConfigurationController> logger)
{
ClientRequestParametersProvider = clientRequestParametersProvider;
_logger = logger;
}
public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider, ILogger<OidcConfigurationController> logger)
{
ClientRequestParametersProvider = clientRequestParametersProvider;
_logger = logger;
}

public IClientRequestParametersProvider ClientRequestParametersProvider { get; }
public IClientRequestParametersProvider ClientRequestParametersProvider { get; }

[HttpGet("_configuration/{clientId}")]
public IActionResult GetClientRequestParameters([FromRoute]string clientId)
{
var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId);
return Ok(parameters);
}
[HttpGet("_configuration/{clientId}")]
public IActionResult GetClientRequestParameters([FromRoute]string clientId)
{
var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId);
return Ok(parameters);
}
}
Loading