MVVM && IOC && Sub-ViewModels
        Posted  
        
            by Lee Treveil
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Lee Treveil
        
        
        
        Published on 2010-05-21T11:44:14Z
        Indexed on 
            2010/05/22
            2:30 UTC
        
        
        Read the original article
        Hit count: 753
        
I have a ViewModel, it takes two parameters in the constructor that are of the same type:
public class CustomerComparerViewModel
{
    public CustomerComparerViewModel(CustomerViewModel customerViewModel1,
                                     CustomerViewModel customerViewModel2)
    {
    }
}
public class CustomerViewModel
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
If I wasn't using IOC I could just new up the viewmodel and pass the sub-viewmodels in. I could package the two viewmodels into one class and pass that into the constructor but if I had another viewmodel that only needed one CustomerViewModel I would need to pass in something that the viewmodel does not need.
How do I go about dealing with this using IOC? I'm using Ninject btw.
Thanks
© Stack Overflow or respective owner