Skip to content

Add nullable annotations to Identity.Extensions #40007

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 2 commits into from
Feb 10, 2022
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
6 changes: 3 additions & 3 deletions src/Identity/EntityFrameworkCore/src/IdentityDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ protected IdentityDbContext() { }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User roles.
/// </summary>
public virtual DbSet<TUserRole> UserRoles { get; set; }
public virtual DbSet<TUserRole> UserRoles { get; set; } = default!;

/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of roles.
/// </summary>
public virtual DbSet<TRole> Roles { get; set; }
public virtual DbSet<TRole> Roles { get; set; } = default!;

/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of role claims.
/// </summary>
public virtual DbSet<TRoleClaim> RoleClaims { get; set; }
public virtual DbSet<TRoleClaim> RoleClaims { get; set; } = default!;

/// <summary>
/// Configures the schema needed for the identity framework.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IdentityBuilder AddEntityFrameworkStores<TContext>(this IdentityBu
return builder;
}

private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType)
private static void AddStores(IServiceCollection services, Type userType, Type? roleType, Type contextType)
{
var identityUserType = FindGenericBaseType(userType, typeof(IdentityUser<>));
if (identityUserType == null)
Expand Down Expand Up @@ -89,12 +89,11 @@ private static void AddStores(IServiceCollection services, Type userType, Type r
}
services.TryAddScoped(typeof(IUserStore<>).MakeGenericType(userType), userStoreType);
}

}

private static Type FindGenericBaseType(Type currentType, Type genericBaseType)
private static Type? FindGenericBaseType(Type currentType, Type genericBaseType)
{
var type = currentType;
Type? type = currentType;
while (type != null)
{
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
Expand Down
12 changes: 6 additions & 6 deletions src/Identity/EntityFrameworkCore/src/IdentityUserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ protected IdentityUserContext() { }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of Users.
/// </summary>
public virtual DbSet<TUser> Users { get; set; }
public virtual DbSet<TUser> Users { get; set; } = default!;

/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User claims.
/// </summary>
public virtual DbSet<TUserClaim> UserClaims { get; set; }
public virtual DbSet<TUserClaim> UserClaims { get; set; } = default!;

/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User logins.
/// </summary>
public virtual DbSet<TUserLogin> UserLogins { get; set; }
public virtual DbSet<TUserLogin> UserLogins { get; set; } = default!;

/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User tokens.
/// </summary>
public virtual DbSet<TUserToken> UserTokens { get; set; }
public virtual DbSet<TUserToken> UserTokens { get; set; } = default!;

private StoreOptions GetStoreOptions() => this.GetService<IDbContextOptions>()
private StoreOptions? GetStoreOptions() => this.GetService<IDbContextOptions>()
.Extensions.OfType<CoreOptionsExtension>()
.FirstOrDefault()?.ApplicationServiceProvider
?.GetService<IOptions<IdentityOptions>>()
Expand All @@ -118,7 +118,7 @@ protected override void OnModelCreating(ModelBuilder builder)
var storeOptions = GetStoreOptions();
var maxKeyLength = storeOptions?.MaxLengthForKeys ?? 0;
var encryptPersonalData = storeOptions?.ProtectPersonalData ?? false;
PersonalDataConverter converter = null;
PersonalDataConverter? converter = null;

builder.Entity<TUser>(b =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;entityframeworkcore;identity;membership</PackageTags>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
252 changes: 251 additions & 1 deletion src/Identity/EntityFrameworkCore/src/PublicAPI.Unshipped.txt

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/Identity/EntityFrameworkCore/src/RoleStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RoleStore<TRole> : RoleStore<TRole, DbContext, string>
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
public RoleStore(DbContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
public RoleStore(DbContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
}

/// <summary>
Expand All @@ -37,7 +37,7 @@ public class RoleStore<TRole, TContext> : RoleStore<TRole, TContext, string>
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
public RoleStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
public RoleStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
}

/// <summary>
Expand All @@ -58,7 +58,7 @@ public class RoleStore<TRole, TContext, TKey> : RoleStore<TRole, TContext, TKey,
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
public RoleStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
public RoleStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
}

/// <summary>
Expand All @@ -83,7 +83,7 @@ public class RoleStore<TRole, TContext, TKey, TUserRole, TRoleClaim> :
/// </summary>
/// <param name="context">The <see cref="DbContext"/>.</param>
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
public RoleStore(TContext context, IdentityErrorDescriber describer = null)
public RoleStore(TContext context, IdentityErrorDescriber? describer = null)
{
if (context == null)
{
Expand Down Expand Up @@ -211,7 +211,7 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
{
throw new ArgumentNullException(nameof(role));
}
return Task.FromResult(ConvertIdToString(role.Id));
return Task.FromResult(ConvertIdToString(role.Id)!);
}

/// <summary>
Expand All @@ -220,7 +220,7 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
/// <param name="role">The role whose name should be returned.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that contains the name of the role.</returns>
public virtual Task<string> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string?> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand All @@ -238,7 +238,7 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
/// <param name="roleName">The name of the role.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
public virtual Task SetRoleNameAsync(TRole role, string roleName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetRoleNameAsync(TRole role, string? roleName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand All @@ -255,21 +255,21 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
/// </summary>
/// <param name="id">The id to convert.</param>
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
public virtual TKey ConvertIdFromString(string id)
public virtual TKey? ConvertIdFromString(string id)
{
if (id == null)
{
return default(TKey);
}
return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
return (TKey?)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
}

/// <summary>
/// Converts the provided <paramref name="id"/> to its string representation.
/// </summary>
/// <param name="id">The id to convert.</param>
/// <returns>An <see cref="string"/> representation of the provided <paramref name="id"/>.</returns>
public virtual string ConvertIdToString(TKey id)
public virtual string? ConvertIdToString(TKey id)
{
if (id.Equals(default(TKey)))
{
Expand All @@ -284,7 +284,7 @@ public virtual string ConvertIdToString(TKey id)
/// <param name="id">The role ID to look for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that result of the look up.</returns>
public virtual Task<TRole> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TRole?> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand All @@ -298,7 +298,7 @@ public virtual string ConvertIdToString(TKey id)
/// <param name="normalizedName">The normalized role name to look for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that result of the look up.</returns>
public virtual Task<TRole> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TRole?> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand All @@ -311,7 +311,7 @@ public virtual string ConvertIdToString(TKey id)
/// <param name="role">The role whose normalized name should be retrieved.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that contains the name of the role.</returns>
public virtual Task<string> GetNormalizedRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string?> GetNormalizedRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand All @@ -329,7 +329,7 @@ public virtual string ConvertIdToString(TKey id)
/// <param name="normalizedName">The normalized name to set</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
public virtual Task SetNormalizedRoleNameAsync(TRole role, string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetNormalizedRoleNameAsync(TRole role, string? normalizedName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
Expand Down Expand Up @@ -371,7 +371,7 @@ protected void ThrowIfDisposed()
throw new ArgumentNullException(nameof(role));
}

return await RoleClaims.Where(rc => rc.RoleId.Equals(role.Id)).Select(c => new Claim(c.ClaimType, c.ClaimValue)).ToListAsync(cancellationToken);
return await RoleClaims.Where(rc => rc.RoleId.Equals(role.Id)).Select(c => new Claim(c.ClaimType!, c.ClaimValue!)).ToListAsync(cancellationToken);
}

/// <summary>
Expand Down
Loading