Castle.DynamicProxy based library that provides a way to implement INotifyPropertyChanged automatically using AOP style.
public class ViewModel : INotifyPropertyChangedCaller
{
[Inpc]
public virtual string Property { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
- AopInpcFactory
static void Main(string[] args)
{
var viewModel = AopInpcFactory.Create<ViewModel>();
//var viewModel = AopInpcFactory.Decorate(new ViewModel());
viewModel.PropertyChanged += (sender, eventArgs)
=> Console.WriteLine($"The property \"{eventArgs.PropertyName}\" was updated with value \"{viewModel.Property}\".");
viewModel.Property = "Hello world!";
}
- DI-container
static void Main(string[] args)
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterType<InpcInterceptor>();
containerBuilder.RegisterType<ViewModel>()
.EnableClassInterceptors()
.InterceptedBy(typeof(InpcInterceptor));
var container = containerBuilder.Build();
var viewModel = container.Resolve<ViewModel>();
viewModel.PropertyChanged += (sender, eventArgs)
=> Console.WriteLine($"The property \"{eventArgs.PropertyName}\" was updated with value \"{viewModel.Property}\".");
viewModel.Property = "Hello world!";
}
- Castle.DynamicProxy ProxyGenerator
static void Main(string[] args)
{
var viewModel = new ProxyGenerator().CreateClassProxy<ViewModel>(new InpcInterceptor());
viewModel.PropertyChanged += (sender, eventArgs)
=> Console.WriteLine($"The property \"{eventArgs.PropertyName}\" was updated with value \"{viewModel.Property}\".");
viewModel.Property = "Hello world!";
}
The property "Property" was updated with value "Hello world!".