Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#955)
Browse files Browse the repository at this point in the history
Instead of Task.FromResult(0)
  • Loading branch information
pakrym authored Sep 7, 2016
1 parent 2a03500 commit e131eba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
{
Expand Down Expand Up @@ -263,7 +264,7 @@ private async Task SaveChanges(CancellationToken cancellationToken)
throw new ArgumentNullException(nameof(role));
}
role.Name = roleName;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -354,7 +355,7 @@ public virtual string ConvertIdToString(TKey id)
throw new ArgumentNullException(nameof(role));
}
role.NormalizedName = normalizedName;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down
29 changes: 15 additions & 14 deletions src/Microsoft.AspNetCore.Identity.EntityFrameworkCore/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
{
Expand Down Expand Up @@ -291,7 +292,7 @@ public UserStore(TContext context, IdentityErrorDescriber describer = null)
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
protected Task SaveChanges(CancellationToken cancellationToken)
{
return AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : Task.FromResult(0);
return AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -344,7 +345,7 @@ protected Task SaveChanges(CancellationToken cancellationToken)
throw new ArgumentNullException(nameof(user));
}
user.UserName = userName;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -380,7 +381,7 @@ protected Task SaveChanges(CancellationToken cancellationToken)
throw new ArgumentNullException(nameof(user));
}
user.NormalizedUserName = normalizedName;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -541,7 +542,7 @@ public virtual IQueryable<TUser> Users
throw new ArgumentNullException(nameof(user));
}
user.PasswordHash = passwordHash;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -933,7 +934,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.EmailConfirmed = confirmed;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand All @@ -952,7 +953,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.Email = email;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1007,7 +1008,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.NormalizedEmail = normalizedEmail;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.LockoutEnd = lockoutEnd;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1099,7 +1100,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.AccessFailedCount = 0;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1154,7 +1155,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.LockoutEnabled = enabled;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand All @@ -1173,7 +1174,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.PhoneNumber = phoneNumber;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1229,7 +1230,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.PhoneNumberConfirmed = confirmed;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand All @@ -1248,7 +1249,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.SecurityStamp = stamp;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -1285,7 +1286,7 @@ public async virtual Task<TUser> FindByLoginAsync(string loginProvider, string p
throw new ArgumentNullException(nameof(user));
}
user.TwoFactorEnabled = enabled;
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
},
"dependencies": {
"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": {
"net451": {},
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNetCore.Identity/SignInManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -662,7 +663,7 @@ private Task ResetLockout(TUser user)
{
return UserManager.ResetAccessFailedCountAsync(user);
}
return Task.FromResult(0);
return TaskCache.CompletedTask;
}

internal class TwoFactorAuthenticationInfo
Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.AspNetCore.Identity/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"dependencies": {
"Microsoft.AspNetCore.Authentication.Cookies": "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": {
"net451": {},
Expand Down

0 comments on commit e131eba

Please sign in to comment.