I don't want to reference EntityFramework and hence Identity.EntityFramework with its IdentityUser in my domain. But I'd like to use UserManager of Identity.Core which uses IUserStore<TUser> where TUser : IUser<string>. And hence I need to expose that IUserStore while hiding ApplicationUser as it derives from IdentityUser.
In my data access layer:
public class ApplicationUser : IdentityUser, IApplicationUser { }
// somewhere for IoC container:
var userStore = new UserStore<ApplicationUser>();
// The following breaks with error CS0266:
// Cannot implicitly convert type 'UserStore<ApplicationUser>' to 'IUserStore<IApplicationUser>'
IUserStore<IApplicationUser> userStore = userStore; // does not work
var um = new UserManager<IApplicationUser>(userStore);
In my domain layer:
public interface IApplicationUser : IUser<string> {}
// desired behavior somewhere in domain/web:
var myUserManager = iocContainer.Resolve<UserManager<IApplicationUser>();
This code does not work as TUser in IUserStore<TUser> is not variant (covariance).