aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 868 forks source link

[Design] Add UI user factory #1976

Closed HaoK closed 5 years ago

HaoK commented 6 years ago

Exploring fixes for https://github.com/aspnet/Identity/issues/1722

Not sure if this might be more appropriate for 3.0 as its will be hard to do this in a non breaking change way in 2.2, basically moves away from Activator.CreateInstance infavor of a dedicated DefaultUIUserFactory which will be used to create new user instances.

We provide a default one that works for identity user based classes that have a default constructor, custom users can add their own factory implementation that implements: TUser Create(string userName, string email)

or they can just register it inline like so with a sugar method:

            services.AddDefaultIdentity<PocoUser>()
                .AddUserManager<UserManager<PocoUser>>()
                .AddDefaultUIUserFactory<PocoUser>((userName,email) =>
                    new PocoUser()
                    {
                        UserName = userName,
                        Email = email
                    });

Thoughts @ajcvickers @javiercn @blowdart

HaoK commented 6 years ago

Per triage we will revisit this in for 3.0

gulbanana commented 6 years ago

I’ll look forward to it. At the moment our TUser is really a “user accessor” which has to be contextualised to retrieve the real orm object, which is fine in IUserStore but kind of a pain for app code to do.

natemcmaster commented 5 years ago

This repo is being archived. If this is still something you want to get merged, open a new PR against https://github.com/aspnet/AspNetCore