I current got a flow like this:
The Repository gets injected with a Datasource. The ViewModel gets injected with the Repository.
Because there’s a constant flow of Items and Mutations (deletions, changes) that need to translate to the UI I don’t keep a collection of items in the Repository. Therefor I ended up with a repository that only passes along Items between the Datasource and the ViewModels.
I’ve always understood that you shouldn’t directly use the Datasource in the UI layer (ViewModels are in my UI layer). But is this still the case if you use dependency injection? Am I putting the Repository pattern to its use or is it just causing me overhead? (Right now it feels like it does.)
I originally implemented the repository to decouple the UI and Datasource but I’ve found that DI does a great job without a Repository.
You might want to have a look at some of the blog posts by Oren Eini (aka Ayende Rahien)
The evils of the repository abstraction layer
or
Repository is the new singleton
More often than not repositories are just “flow heaters”. They do nothing but forward calls and results and just add overhead.
Btw: if you should or should not use repositories has nothing to do with dependency injection!
Update
Oren just published a new post on this topic.