I need to pass the dispatcher to update the UI:
container.RegisterType<Dispatcher>().AsSelf();
container.Register(c => new MyViewModel(c.Resolve<Dispatcher>(), ...some other arguments)).As<IMyViewModel>();
But since it's static, when I do container.Build();
I get this exception:
Autofac.Core.Activators.Reflection.NoConstructorsFoundException:
'No accessible constructors were found for the type 'System.Windows.Threading.Dispatcher'.'
In my viewmodels I usually use it like _dispatcher?.Invoke('some code');
.
I thought about removing it from the viewmodels contructors and in them just do _dispatcher = Dispatcher.CurrentDispatcher;
, but since I'm working with threads im not sure if it is the best way to use it.