Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#955)

Instead of Task.FromResult(0)
This commit is contained in:
Pavel Krymets 2016-09-07 11:24:45 -07:00 committed by GitHub
parent 2a03500ace
commit e131ebae47
5 changed files with 30 additions and 19 deletions

View File

@ -9,6 +9,7 @@ using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
{ {
@ -263,7 +264,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(role)); throw new ArgumentNullException(nameof(role));
} }
role.Name = roleName; role.Name = roleName;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -354,7 +355,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(role)); throw new ArgumentNullException(nameof(role));
} }
role.NormalizedName = normalizedName; role.NormalizedName = normalizedName;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>

View File

@ -10,6 +10,7 @@ using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
{ {
@ -291,7 +292,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
protected Task SaveChanges(CancellationToken cancellationToken) protected Task SaveChanges(CancellationToken cancellationToken)
{ {
return AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : Task.FromResult(0); return AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -344,7 +345,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.UserName = userName; user.UserName = userName;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -380,7 +381,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.NormalizedUserName = normalizedName; user.NormalizedUserName = normalizedName;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -541,7 +542,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.PasswordHash = passwordHash; user.PasswordHash = passwordHash;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -933,7 +934,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.EmailConfirmed = confirmed; user.EmailConfirmed = confirmed;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -952,7 +953,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.Email = email; user.Email = email;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1007,7 +1008,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.NormalizedEmail = normalizedEmail; user.NormalizedEmail = normalizedEmail;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1062,7 +1063,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.LockoutEnd = lockoutEnd; user.LockoutEnd = lockoutEnd;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1099,7 +1100,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.AccessFailedCount = 0; user.AccessFailedCount = 0;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1154,7 +1155,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.LockoutEnabled = enabled; user.LockoutEnabled = enabled;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1173,7 +1174,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.PhoneNumber = phoneNumber; user.PhoneNumber = phoneNumber;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1229,7 +1230,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.PhoneNumberConfirmed = confirmed; user.PhoneNumberConfirmed = confirmed;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1248,7 +1249,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.SecurityStamp = stamp; user.SecurityStamp = stamp;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -1285,7 +1286,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
user.TwoFactorEnabled = enabled; user.TwoFactorEnabled = enabled;
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
/// <summary> /// <summary>

View File

@ -20,7 +20,11 @@
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Identity": "1.1.0-*", "Microsoft.AspNetCore.Identity": "1.1.0-*",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0-*" "Microsoft.EntityFrameworkCore.Relational": "1.1.0-*",
"Microsoft.Extensions.TaskCache.Sources": {
"version": "1.1.0-*",
"type": "build"
}
}, },
"frameworks": { "frameworks": {
"net451": {}, "net451": {},

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Authentication; using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Http.Features.Authentication; using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -662,7 +663,7 @@ namespace Microsoft.AspNetCore.Identity
{ {
return UserManager.ResetAccessFailedCountAsync(user); return UserManager.ResetAccessFailedCountAsync(user);
} }
return Task.FromResult(0); return TaskCache.CompletedTask;
} }
internal class TwoFactorAuthenticationInfo internal class TwoFactorAuthenticationInfo

View File

@ -20,7 +20,11 @@
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.0-*", "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0-*",
"Microsoft.AspNetCore.Cryptography.KeyDerivation": "1.1.0-*", "Microsoft.AspNetCore.Cryptography.KeyDerivation": "1.1.0-*",
"Microsoft.AspNetCore.Hosting.Abstractions": "1.1.0-*" "Microsoft.AspNetCore.Hosting.Abstractions": "1.1.0-*",
"Microsoft.Extensions.TaskCache.Sources": {
"version": "1.1.0-*",
"type": "build"
}
}, },
"frameworks": { "frameworks": {
"net451": {}, "net451": {},