views:

241

answers:

1

Hi all,

First and foremost. Sorry about my English, i'm still learning :)

I'm currently wrestling with the MVVM model.

  • At the bottom, i have a database.
  • On top of that sits my DAL which is bascily the ADO.NET entity framework. *Note that the different entities are also my business objects (since i include validation in them).
  • On top of that again, i have repository classes which define the different queries required in the app.
  • And ofcourse on top of that i got things like the interface, other components and unit testing but i dont think that's really relevant.

The situation is as the following (in abstract): On top of the repository pattern, there is a worker performing all kinds of tasks. Next there is an interface which shows the status of these different tasks. (Each task containing tons of subtasks). Both the interface and the worker share the same Repository of the tasks!

Now what i'm trying to achieve is this: The worker might open (or expand if you will) a task, processing all its subtasks. At some time, the user might expand the task in the interface seeing all the subtasks. Ofcourse it would be great to see the subtasks beeing updated once there beeing processed by the scheduler. Yet, by default i dont want to have the subtasks loaded in memory when not beeing processed or shown. Therefore the subtasks should load on demand.

Now my question, when one of the consumers open a repository for the subtasks of a task, Whats the nicest way of sharing it with other consumers (this is required, because the repository raises the events when things change)? (e.g. how to share the repository created by the worker with the interface).

Most notably, you would say that it will become a property of the Task entity, but because the Task entity is used a business object, it should not have the knowledge of either the underlying datasource (in this case the EF model), or the Repository layer on top of it.

Another option would be to create add a LoadChildTasks method to the Tasks repository but that would mean that i have to keep a collection internally and when the load is called, check if there wasn't a SubTaskRepository created before for the Task specified. Also it would mean that when both the interface and the worker dropped their operations on the task list, it needs to be manually released because else it would be held in memory by the internal list.

A: 

Hi we make the repository class as singleton class. so it will be shared in whole application. hope this will help. Jane

Jane
Thanks for your input but this will simply not comply since a requirement is that resources are released once not beeing used any more. Also, i would like to find a great abstract way of doing this, singleton is not a really nice solution in this scenario.
Polity