In the past, when I've used MVC, my model objects were just dumb data containers. Everywhere I read says that in MVVM, models should contain business logic as well as being a data container. Now that my model objects also contain business logic, how do I use them as data containers? For instance: my models as an accessor (an injected dependency). In the past, my accessors would construct a model and pass that as their result:
class foo_accessor {
foo_model Get(int id);
...
}
This creates a cyclical dependency though, as my accessor has to create an model object with another accessor. I'm considering creating a structure with my properties and instead passing that around:
class foo_model {
struct container {
int x;
}
private container _cont;
private foo_accessor _accessor;
public X { get => return _cont.x; set => _cont.x = value; }
public GetModel(int id) {
_cont = _accessor.Get(id);
}
}
class foo_accessor {
ref container Get(int id);
...
}
But this seems like duplication and more importantly, violates that out models is actually doing the modeling. It's really just becoming a controller.