We have models:

public class EmployeeFunction{ public int Id {get;set;} public string Name {get;set;} } public class Employee public int Id{get;set;} public string Code {get; set;} public string Name {get;set;} public EmployeeFunction EmployeeFunction{get;set;} } 

For models, we have the implementation of the repositories:

 public interface IRepository<T> { //... } public abstract class RepositoryBase<T> : IRepository<T>{ //... } public class EmployeesRepository<Employee> { //... } public class EmployeeFunctionsRepository<EmployeeFunction> { //... } 

Using MVVM Light Toolkit repositories are injected into ViewModel.

 public class EmployeesViewModel{ //... private IRepository<Employee> _repository; public ObservableColeection<Emolyee> Items { get; private set; } public EmployeesViewModel(IRepository<Employee> repository){ _repository = repository; Items = _repository.GetAll(); } //... } 

How does this approach fill the EmployeeFunction property in the Employee class? I understand that there should be a link to the EmployeeFunction instance, obtained from the corresponding repository. Those. Does the employee repository have to pull the repository of posts to get the necessary link?

  • MVVM has nothing to do with it. You are faced with the typical problem of repository responsibility, namely, "what if you need to pull the repository method of another repository." Should he jerk or himself collect the entire graph of objects. - vitidev
  • @vitidev And how do you think it will be more correct? For example, if a class consists mainly of references to other classes? - Ivan Nazarov
  • one
    There is no perfect solution to this question. blog.byndyu.ru/2011/08/repository.html What you will have to sacrifice. ALL solutions have some disadvantages, alas. If I already have turnips, I’m giving birth to a ChoToTamQuery class, that is, a QueryObject that takes in as many repositories as it needs and collects the desired graph. - vitidev
  • @vitidev Hmm. Thanks for the tip. Somehow on the move did not even occur. - Ivan Nazarov

0