在哪里可以找到有关领域驱动设计上下文中的身份验证和授权的信息?
我正在尝试以 DDD(领域驱动设计)方式做事。 我真的很挣扎。 在我读过的所有书中,身份验证都没有被关注,也没有被提及!
我编写了自己的身份验证和会员服务,负责注册和登录用户、创建加盐密码等。我不使用.NET 的会员提供程序,但依赖于表单身份验证。
我已经实现了一个用户模型,其中包含用户名、电子邮件、密码哈希、ApprovalStatus 等。
现在我想域模型的其余部分不应该关心用户。 我有一个 Person 类,用于对 Person 及其关联数据进行建模。 因此,它可用于对来自用户和非用户的个人数据进行建模。 Company 类型的对象与人一起使用,而不是与用户一起使用。 活动被分配给一个人,而不是一个用户。
问题是,如何将 Person 模型与 User 模型关联起来? 我真的不想在这两个模型中互相引用。 我是否应该创建一些名为 PersonUser 的关系模型,并创建一个附加服务来检索当前经过身份验证的用户的人员对象?
I'm trying to do things the DDD (domain driven design) way. And boy do I struggle. In all books I read, Authentication is of no concern and not mentioned!
I've written my own Authentication and Membership Service which are responsible for registering and logging in users, creating salted passwords etc. I do not use .NET's Membership Provider but do rely on Forms Authentication.
I've implemented a User model that holds the Username, E-Mail, PasswordHash, ApprovalStatus etc.
Now I guess the rest of the domain model shouldn't concern itself with the Users. I have a class Person that is used to model Persons and their associated data. As such it can be used to model personal data from users and from non-users. An object of type Company works with Persons, not Users. And an Activity is assigned to a Person, not a User.
The question, how do I relate the Person model to the User model? I don't really want a reference to each other in either of the two models. Should I create some Relationship model called PersonUser and create an additional service that retrieves the person object for the currently authenticated user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您所呈现的内容来看,您有几个已知的事实:
既然如此,我将扩展人员模型以包含可为空的 UserId 字段,以便您可以将用户与同时也是用户的人员相关联。
现在我还要假设您在人员模型中有几个“Fetch”方法..通过ID,姓名,部门等检索人员...
我会重载(或创建不同的)fetch 方法也从 User 检索 person 对象(这可以是 id,也可以是下面的用户对象)。
当然,由于您知道每个用户也是一个人,所以我个人认为扩展用户对象以包含人员属性没有什么坏处……
然后,您可以像往常一样返回用户对象……并且也许对用户中的人员字段进行一些时髦的延迟加载...或者在获取用户对象时填充两者。
我不确定是否创建用户<->的“映射”表 除了我上面概述的内容之外,Person 还将为您带来很多东西(尽管您会从铁杆 DBA 那里获得对数据非规范化的称赞).. 对我来说,这只是一个额外的表,需要加入才能获得相同的效果。
Judging from what you've presented, you've got a couple of known facts:
That being the case, I would expand the person model to include a nullable UserId field so that you can relate the User to the Person for those Persons that are also users.
Now I'm also going to assume that you have several "Fetch" methods in the person model.. to retrieve a person by ID, Name, Department, etc...
I would overload (or create a different) fetch method to also retrieve the person object from a User as well (this can be either an id, or the foll user object).
Of course, since you have the known fact that every user is also a person, I personally see no harm nor foul in expanding the user object to include a person property...
Then, you can return the user object as always.. and perhaps do some funky lazy loading of the person field in the user... or populate both when you fetch the user object.
I'm not sure if creating a "mapping" table of User <-> Person is going to garner you much of anything beyond what I've outlined above (although you will get kudo's from the hardcore DBA's for denormalizing your data).. to me it's just an extra table to join to to get the same effect.