0

These could be my entity relations:

1 Pupil has 1 Chair

1 Pupil has N Documents

1 Pupil has N Marks

1 Pupil has N IncidentReports

etc...

So with that sample I get 4 IEnumerable from my database put each into an ObservableCollection.

Now I have 4 different Views each bound to one of those 4 collections.

Lets assume I delete a single PupilViewModel in the AdministrationController which is the only View where I can delete a PupilViewModel.

Now I have to inform 3 other Controller and their ObservableCollections about the one deleted PupilViewModel to keep the whole application synchronized... thats stupid somehow.

Do you have any good advice on that scenario?

AND it gets even worse. If I delete a schoolclass I have to sync the pupils everywhere AND the documents or incidentreports or marks...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Elisabeth
  • 20,496
  • 52
  • 200
  • 321

1 Answers1

0

What I would suggest is using the EventAggregator from such frameworks as Prism, Caliburn. The fundermental thing about this is that you register interest in a known subject or object within each ViewModel and when a delete of a pupil comes along all ViewModels interested in knowing about the change can update (or synchronize) the ObservableCollections since the pupil (or id) is passed to all listeners.

Another alternative which might be more work would be to have one model object that all those ViewModels share an instance of. That model is responsible for updating the lists it has and provided it implements INotifyPropertyChanged and has the collections bound to the view then the Views will update.

aqwert
  • 10,559
  • 2
  • 41
  • 61
  • Is EventAggregator not the same as a IMessenger or IMediator service ? I register for a certain Type/Message and when that data is sent the Callback OnXXX-method is executed. I already use that. – Elisabeth Dec 24 '10 at 17:31
  • Regarding this current blog post ( http://codebetter.com/glennblock/2010/10/11/yea-another-simplification-of-prism-s-eventaggregator-syntax/ ) on the new Prism the IEventAggregator is the same as the IMediator means a Messenger service which offers publishing data and subscribing to events. This is exactly what leads to spagetthi code I heard some people say on SO! – Elisabeth Dec 26 '10 at 21:31
  • Where on SO have you heard it leads to spagetti code? It offers a loosely coupled eventing mechanism. I have never had this experience since you publish and subscribe on a particular subject. As for Prism's implementation you don't have to use it. I was merely suggesting a pattern to solve your problem. – aqwert Dec 28 '10 at 06:27