实体和基础设施服务
我有一个实体工厂,需要访问文件系统来构造对象。我创建了一个 IFileSystem 接口,它被注入到工厂中。
使用基础设施服务的正确方式是吗?如果是这样,建议对实体本身执行相同的操作,因为实体上的重要方法也需要操作文件系统。
I have an entity factory which requires access to the file system for construction of the object. I have created a IFileSystem
interface, which is being injected into the factory.
Is the the correct way to use an infrastructure service? If so is it recommended to do the same for the entity itself, since important methods on the entity will be required to manipulate the file system also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不知道您正在从事哪个领域,则很难回答这个问题。但这看起来并不正确,因为这类似于注入 IDatabase 之类的东西。文件系统和数据库是持久性技术,域逻辑应尽可能与持久性无关。因此,如果您的通用语言不包含“文件系统”的概念,您可能需要重新评估此设计。您可以简单地用更以领域为中心的术语(例如
ICustomerConstructionInfoProvider
)重申您的意图。然后注入此接口实现,类似于注入存储库实现的方式。It is hard to answer this question without knowing what domain you are working on. It does not seem right though because this would be similar to injecting something like IDatabase. File system and database are persistence technologies and domain logic should be as persistent-agnostic as possible. So you might want to reevaluate this design if your Ubiquitous Language does not include the concept of 'file system'. You can simply restate your intent in a more domain centric terms like
ICustomerConstructionInfoProvider
. And then inject this interface implementation similarly to how you would inject repositories implementation.