breezeJS 为什么要为每个工作单元创建一个新的 entityManagerProvider?

breezeJS why create a new entityManagerProvider for each unit of work?

我是 BreezeJS 的新手,但非常感兴趣。我想将它合并到我目前正在进行的 Angular/Node 项目中。

我一直在通读文档并查看示例。我一直在审查的一个示例是可以在此处找到的 TempHire 示例: https://github.com/Breeze/breeze.js.samples/blob/master/node/tempHire

我不明白他们为什么要为每个 UnitOfWork 创建一个新的 entityManagerProvider。这似乎浪费了很多精力。我确信这是有原因的,我只是不明白,因为我不了解 breeze 或工作模式单元。

非常感谢任何帮助。

关键在文档中:"UOWs can be shared between ViewModels if different parts of the UI work with the same data, but each UOW remains a unique sandbox."

在 angularjs 中,工厂服务是单例的,因此当您创建一个 UOW 服务时,您也会为它创建一个 entityManager。

在该 UOW 中,您可以放置​​所有要使用的数据存储库,并将其用于您的业务代码。

每次您想使用这些数据时,只需注入您创建的 "unitofwork" 服务,而不会创建额外的 entityManager。 "UnitOfWork" 服务工厂有一个 "get" 方法。

但是如果您想使用一个新的干净的 UnitOfWork 服务实例和一个空的 entityManager 缓存,那么您只需调用 unitOfWork.create() 即可创建一个新的 enityManager。

此处解释了此类业务场景的示例:http://breeze.github.io/doc-cool-breezes/multiple-entitymanagers.html