Different ways to pass services via ImportingConstructor

Nov 6, 2010 at 8:54 AM

Hello Marlon,

today I have an architectural question about the usage of 

[ImportingConstructor] and where to pass services

this is my MainViewModel: // SHOULD I inject my IPlannerRepository HERE at the First/Top ViewModel, when I need it ONLY to pass to the PlannerDaily-/WeeklyViewModel ?? OR should I create my IPlannerRepository instance within the MainViewModel 

LIKE _dailyVM = new PlannerDailyViewModel(_messenger, new Messenger()); and remove the IPlannerRepositry plannerRepo, from the below MainViewModel Ctor ?

How would you do it?

 

[ImportingConstructor]        public MainViewModel(IMainRepository mainRepo, IPlannerRepository plannerRepo, IMessenger messenger) 
{  
          _messenger = messenger; 
           _mainRepo = mainRepo;   
         _plannerRepo = plannerRepo;                   

 

 

}  

private void InitDailyView()   {  VM = _dailyVM ?? (_dailyVM = new PlannerDailyViewModel(_messenger,_plannerRepo));   }

 

 

private void InitWeeklyView()  {  VM = _weeklyVM ?? (_weeklyVM = new PlannerWeeklyViewModel(_messenger,_plannerRepo));  }

 

 

     [ImportingConstructor]
        public PlannerDailyViewModel(IMessenger messenger, IPlannerRepository plannerRepo)
        {
            _messenger = messenger;
            _plannerRepo = plannerRepo;

        }

Coordinator
Nov 7, 2010 at 10:04 AM

I don't think it does much difference... is there anything concerning you ?