存储库模式和分层。 我在哪里申请担保?
我正在尽最大努力设计我的网络应用程序,使各层之间有良好的分离。 我正在使用存储库模式,因此有一个 SQLObjectRepository,它由我的 ObjectService 调用,而我的 Web 前端又调用它。
在我的对象模型中,用户与一个或多个区域相关联,这些区域应该过滤他们应该有权访问的对象。 我的问题是,当我查询对象时,是否将代码放入服务中以设置对象的权限,或者该代码应该放在存储库中吗? 如果用户是 2 个区域的成员,我应该将用户作为参数传递给服务,还是应该将用户的区域传递给服务?
I am doing my best to design my web app with good separation between the layers. I am using the repository pattern and as such have a SQLObjectRepository which is called by my ObjectService which is called by my Web front end.
In my object model, the user is associated with one or more regions which should filter the objects they should have access to. My question is, when I am querying for objects, do I put the code in the service to set the permissions on the objects, or should that code be in the repository? If the user is a member of 2 regions, should I pass the user as a parameter to the service, or should I pass the user's regions to the service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会:
以可以应用于任何您喜欢的地方的方式编写安全检查。 这样您就可以随着需求的变化进行重构。
如果安全检查确实总是适用,请将其放置在存储库层(或者更好,如果您的语言支持它,则放置在某个方面),以便多个服务在使用时将共享共同的安全性相同的存储库。 否则将其放置在服务中(或作用于服务的方面)。
将整个用户对象传递给安全检查机制:
I would:
Write the security check in such a way that it can be applied in any place you like. This way you can refactor as requirements change.
If the security check really will always apply, place it in the repository layer (or better, in an aspect if your language supports it) so that multiple services will all share common security if they use the same repository. Otherwise place it in the service (or an aspect acting on the service).
pass the entire user object to the security checking mechanism: