0

I founded some awesome example of using IOC container. example It's looks very cool. Ben Scheirman suggested to wrap each property by INotyfi using IOC. But i do not know how to implement it under Mvvm light IOC container. Because i can not find var bindingFriendlyInstance = IoC.Resolve<Customer>(new NotifyPropertyChangedWrapper()); in MvvmLight. MvvmLight has only SimpleIoc.Default.GetInstance<Customer>(); but it does not take any arguments.

public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime CustomerSince { get; set; }
public string Status { get; set; }
}

UglyCustomer

public class UglyCustomer : INotifyPropertyChanged
{
private string _firstName;
public string FirstName
{
    get { return _firstName; }
    set
    {
        string oldValue = _firstName;
        _firstName = value;
        if(oldValue != value)
            OnPropertyChanged("FirstName");
    }
}

private string _lastName;
public string LastName
{
    get { return _lastName; }
    set
    {
        string oldValue = _lastName;
        _lastName = value;
        if(oldValue != value)
            OnPropertyChanged("LastName");
    }
}

private DateTime _customerSince;
public DateTime CustomerSince
{
    get { return _customerSince; }
    set
    {
        DateTime oldValue = _customerSince;
        _customerSince = value;
        if(oldValue != value)
            OnPropertyChanged("CustomerSince");
    }
}

private string _status;
public string Status
{
    get { return _status; }
    set
    {
        string oldValue = _status;
        _status = value;
        if(oldValue != value)
            OnPropertyChanged("Status");
    }
}

protected virtual void OnPropertyChanged(string property)
{
    var propertyChanged = PropertyChanged;

    if(propertyChanged != null)
        propertyChanged(this, new PropertyChangedEventArgs(property));
}

public event PropertyChangedEventHandler PropertyChanged;
}
Community
  • 1
  • 1
A191919
  • 3,422
  • 7
  • 49
  • 93
  • SimpleIoc is the worst IoC container I have ever used. I would recommend switching to a more feature-rich container like Unity or StructureMap – Glen Thomas Jul 28 '15 at 15:15
  • Just use the MVVM Light snippets ('mvvminpc' is *really* handy) to crank out your get/set boilerplate. It'll leave your code more verbose, but the verbosity conforms to 'standard' use of MVVM Light. Other people will find it much easier to read your code. – goobering Jul 28 '15 at 15:34
  • What you want is something you can't do with an IoC container. What you want requires a code weaving library like [Validar](https://github.com/Fody/Validar). – Steven Jul 28 '15 at 16:11

0 Answers0