How does breezejs EntityManager work?

I read the breeze.js documentation (by the way, excellent documentation), but I have doubts about the EntityManager.

Suppose I have the following factory method:

var createManager = function () { return new breeze.EntityManager({ serviceName: serviceName, metadataStore: store }); }; 

Then I define two instances of Entitymanager:

 em1 = createManager(); em2 = createManager(); 

If call

 em1.saveChanges(); 

Does em2 changes?

Do em1 and em2 common cache?

If not, do I need to create a Singleton EntityManager? In my project, I access EntityManager in many places, swap objects among them, so I'm not sure which best (or the right) architecture should follow.

+4
source share
1 answer

I believe that the object manager acts as its own data context on the client. When you create em1 and em2, you create 2 different managers, so they are saved independently of each other. If you want to reference the same entitymanager in several places (which is one of its advantages), you can use the javascript module template to refer to the created instance.

My preferred method is to create a module called datacontext. He owns an entity manager and any other custom functions I need to provide a light breeze. All other modules reference this datacontext and simply request data. Datacontext hides the breeze from the rest of the modules. This is not the only way, but I like it because it follows good separation patterns.

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1447477/


All Articles