Reputation: 326
I would like to extend User class in Orchard Core (Orchard 2), add some additional properties like FirstName, LastName for example. I understand I can store such information in a separate entity like UserProfile, but sometimes it would be convenient just to use my own implementation of IUser. It looks like OrchardCore implementation of "Membership system" is coupled to Orchard.Users.Models.User type. I see there is a service
IUserService.CreateUserAsync(User user,...
Probably it would be better to use IUser interface instead of Orchard.Users.Models.User type? I tried to inherit from Orchard.Users.Models.User class like
class MyUser : Orchard.Users.Models.User
{
..
}
But when I tried to invoke IUserService.CreateUserAsync(myUser) I got a Error
`Unable to cast object of type 'YesSql.Indexes.DescribeContext`1[MyTestModule.Abstractions.Models.MyUser]' to type 'YesSql.Indexes.DescribeContext`1[Orchard.Users.Models.User]'.`
Since Orchard Core use Document storage DB, Why I can not just create my own implementation of IUser and use it? Will it be fixed in the future? may be some workarounds for now?
Upvotes: 1
Views: 2063
Reputation: 326
Answering to my question, probably it will be useful to somebody. User extensibility was implemented in "users" branch now merged to master.
There are multiple solutions
Now Orchard.User implements IEntity, you may add custom properties using Drivers, exactly the same way as it was implemented for Site settings.
You may try directly inherit from Orchard.Users.User, but I'm not sure it will work because of Yes Sql, as I remember, Yes Sql didn't allow retrieve and save derived models, probably it was fixed, need to check
If above solutions do not suitable to your needs e.g you may want to use another ORM like EF. I afraid you have to implement IUser interface, in such case you need to override ASP.NET Identity Stores an Services (IUserStore, IUserService..) + probably you will need to override Admin tool's "Users" and "Roles" UI since they rely on standard Orchard's User implementation. You do not need to override Orchard.OpenId since it relies on IUser interface, BUT! in case if you need issue your own custom "Authorization Claims" you may need to override OpenId's Controller
Upvotes: 4