I am building a MDI application using Entity Framework but I am wondering how to use the object context accross all the windows.
I planned to use a single context (singleton) accross the application but in my requirements, I must handle undo changes for each window (if the user does not want to save changes). Moreover, everything must be bound, so a change in a window must update the corresponding object in another window.
Since we can have multiple windows, it is difficult to see in the context which entity was modified by which window and undo changes if necessary.
I thought that we could create a local context for each window but then it would be difficult to maintain (and then maybe synchronize this local context with the global one).
Do you have any thought on how to handle the context in such case?
Thank you.
Your requirements simply say that your windows cannot be bound directly to context. You must have intermediary layer doing your application logic like window data synchronization and undo and this layer will communicate with context just to load or persist data. In your case the layer can be called presenter => MVP pattern with single presenter handling multiple windows + probably command pattern for handling undo if you have many types of operations.