I am trying to create a "User Service" class where I Expose only the methods that would need to go through this. One of this methods is FindById. Here is my code:
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security.DataProtection;
public interface IUserService : IDisposable
{
Task<CustomUser> FindByIdAsync(string userId);
ICustomUser FindById(string userId);
}
public class UserService : UserManager<CustomUser>, IUserService
{
public UserService(IUserStore<CustomUser> store, IDataProtectionProvider dataProvider)
: base(store)
{
UserValidator = new UserValidator<CustomUser>(this)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
PasswordValidator = new PasswordValidator
{
RequiredLength = 8,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
UserLockoutEnabledByDefault = true;
DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(1);
MaxFailedAccessAttemptsBeforeLockout = 5;
var dataProtectionProvider = dataProvider;
if (dataProtectionProvider != null)
{
UserTokenProvider =
new DataProtectorTokenProvider<CustomUser>(dataProtectionProvider.Create("ASP.NET Identity"));
}
}
public new async Task<ICustomUser> FindByIdAsync(string userId)
{
return await base.FindByIdAsync(userId);
}
public ICustomUser FindById(string userId)
{
return base.FindById(userId);
}
}
The FindByIdAsync method works fine, however the FindById method won't even compile. My autocomplete suggests that the method is there, but when I type it out, it becomes red and says:
Microsoft.AspNet.Identity.UserManager does not contain a definition for FindById
What am I doing wrong?
EDIT:
FindById comes from UserManagerExtensions (see https://msdn.microsoft.com/en-us/library/dn497471(v=vs.108).aspx). Does this mean that I have to extend the extensions class somehow? All I am really trying to do is allow the use of this method via my interface which is IUserService, but adding a reference there it forces me to implement a method, which I tried to do with little success as you can see above