I'm using Prism 7.1 for WPF application. I tried to use built-in IOC(Unity) but I don't know how I can resolve new instance at run time maybe from method or from containerProvider. But it seems IContainerProvider is not available to be injected in my view model. Do I have any option?
I want to do this to reload my database context. I was told that creating new context is the easiest among others.
public class ProjectViewModel : BindableBase
{
private UnitOfWork unitOfWork;
private IContainerProvider containerProvider;
private IEventAggregator eventAggregator;
#region Constructor
public ProjectViewModel(UnitOfWork unitOfWork, IContainerProvider cp, IEventAggregator ea)
{
this.unitOfWork = unitOfWork;
containerProvider = cp;
eventAggregator = ea;
eventAggregator.GetEvent<SendReloadDataEvents>().Subscribe(Reload);
Reload();
}
#endregion
private void Reload()
{
this.unitOfWork = containerProvider.Resolve<UnitOfWork>();
Projects = new ObservableCollection<Projects>(unitOfWork.ProjectRepo.GetAll());
Customers = new ObservableCollection<Customers>(unitOfWork.CustomerRepo.Find(x => x.Projects.Count > 0));
SelectedProjectType = null;
}
//Other logic continues
}