﻿namespace Lauener.Core.XAML
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    using Lauener.Core.Services;

    public abstract class ModelBase : INotifyPropertyChanged
    {
        private IDispatcherService dispatcherService;

        protected ModelBase()
        {
            this.dispatcherService = Starter.Container.Resolve<IDispatcherService>();
        }

        protected void RaisePropertyChanged([CallerMemberName]string property = null)
        {
            this.dispatcherService.ExecuteInUiThread(
                () =>
                    {
                        this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
                    });
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}