Mean.io - 延长用户模式的最佳实践 [英] Mean.io - Best practice to extend User model

查看:167
本文介绍了Mean.io - 延长用户模式的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mean.io带有一个内置在用户包内的用户模型。是什么,如果我想更多的数据附加到其扩展用户模型的最佳做法是什么?

Mean.io comes with a built in user model within the user package. What is the best practice for extending that user model if I want to attach additional data to it?

我与Django的经验让我创造了向它属于用户对象的外键指向一个配置文件。我喜欢这种方法,因为我不碰用户包的方式。但是,这是一个最好的做法?如果是这样,我怎么能保证一个配置文件文档的创建在创建一个用户文档的?如果没有,是什么?

My experience with Django had me creating a "profile" that had a foreign key pointing towards the user object it belonged to. I like this approach because I don't touch the user package that way. But is this a best practice? If this is, how can I ensure the creation of a profile doc at the creation of a user doc? If not, what is?

推荐答案

我不知道qm69的解决方案是最好的未来的兼容性均值。在mean.io文档 http://learn.mean.io/ 它规定开发商不应该改变任何核心包,包括用户包。

I'm not sure qm69's solution would be the best for future compatibility with mean. In the mean.io documentation http://learn.mean.io/ it states the developer shouldn't alter any core packages, including the user package.

该mean.io模式是实现任何和所有扩展作为自定义程序包。并覆盖使用$ viewPathProvider.override方法默认视图。

The mean.io pattern is to implement any and all extensions as a custom package. And override default views using the $viewPathProvider.override method.

其次,用户包基本上是一个安全/认证功能,而不是,定期接收更新的配置文件实现。此变更将最有可能打破未来的修补程序和风险引入安全漏洞。

Secondly the User package is fundamentally a security/authentication feature and not a profile implementation which regularly receives updates. Altering this will most likely break future fixes and risk introducing security bugs.

我的建议是使用的手段包装系统,以实现一个配置文件并添加一个服务依赖于用户的服务。我在previous项目这样做,效果很好。

My advice would be to implement a profile using means package system and add a service dependency for the User service. I've done this in previous projects and it works well.

要实现一个配置文件包,请按照下面的步骤:

To implement a profile package, follow the below steps:

1)创建平均使用软件包侧称为配置文件的自定义程序包。

1) Create a custom package called profile using mean package profile.

2)实施在自定义程序包的所有配置文件要求模型/视图/控制。 DONT ALTER ANYTHING在用户包。

2) Implement model/view/control for all profile requirements in the custom package. DONT ALTER ANYTHING IN THE USER package.

2)使用依赖注入包括全球服务业务。这会给你访问Global.user数据,所以你最有可能甚至不需要使用用户的服务。

2) Use dependency injection to include the Global service service. This will give you access to Global.user data so you most likely don't even need to use the User services.

3)使用上述DOCO提到的$重写方法重写任何用户的意见。

3) Override any User views using the $override method mentioned in the above doco.

希望这有助于;)

这篇关于Mean.io - 延长用户模式的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆