与实体和服务共享枚举,保留在一层还是两层?
因此,存在一个具有枚举属性的实体和一个将返回或采用该枚举类型的 wcf 服务。枚举应该位于实体程序集中并用属性对其进行标记,还是应该复制两个程序集的枚举,标记服务枚举并保留实体枚举未修饰?我不喜欢复制枚举类型,但我也不想装饰我的实体项目中的任何内容。最好的做法是什么?
So there is an entity that has an enum property and a wcf service that would return or take that enum type. Should the enum be in the entities assembly and mark it up with attributes or should I duplicate the enums for both assemblies, marking the service enums and leaving the entity enums undecorated? I don't like duplicating the enum types but I don't really want to decorate anything in my entities project either. What's the best practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
枚举不需要装饰。只有一个版本,不要装饰它。
Decoration isn't needed for enums. Just have one version, and don't decorate it.
“最佳实践”是对您有意义的任何做法。我们在线上共享所有实体枚举类型(数百个)——除非绝对必要,否则在实体/线类型之间复制和转换是没有意义的。只要一切都是 3.5SP1 或更高版本,DataContract/EnumMember 装饰就是可选的。我仍然这样做是为了保持一致性(我们从 3.0 开始就一直使用这些东西),但没有它也能正常工作。
"Best practice" is whatever makes sense for you. We share all our entity enum types (several hundred of them) on the wire- it just doesn't make sense to duplicate and translate between entity/wire types unless absolutely necessary. As long as everything is 3.5SP1 or better, DataContract/EnumMember decoration is optional. I still do it for consistency (we've been using the stuff since 3.0), but it works fine without.