I have a huge WPF project. It uses:
- MVVM Light
- Microsoft.Unity container as a ViewModelLocator
The MainView content depends from other UserControls:
<ContentControl Visibility="Visible"
Content="{Binding ContentViewModel}" />
Each ViewModel for content creates by ConcreateViewModelFactory:
ContentViewModel =(SimpleViewModelBase) _extendedSearchVMFactory.CreateInstance();
All ViewModels factories has interfaces that registered in ViewModelLocator. Factory example:
public class MainViewModelFactory : IMainViewModelFactory
{
private IUnityContainer _container;
public MainViewModelFactory(IUnityContainer container)
{
_container = container;
}
public MainViewModel CreateInstance(df_role[] currentRoles)
{
var vm = _container.Resolve<MainViewModel>(
new ParameterOverride("currentRoles", currentRoles));
return vm;
}
}
MainViewModel costructor has about 40 parameters to keep all Interfaces for ViewModel constructors:
public MainViewModel(IDataService dataService,
IDialogService dialogService,
ISearchByIdViewModelFactory searchViewModelFactory,
ISearchByPhonesViewModelFactory searchByPhonesViewModelFactory,
IDoubleSearcherViewModelFactory doubleSearcherViewModelFactory,
IAnalysisOfDoubleSearchAlgorythmViewModelFactory analysisOfDoubleSearchAlgorythmViewModelFactory,...
My question: How can I refactor this? If you have helpful information about DI+MVVM I will be grateful.
P.S. Sorry for my english.
MainViewModel
. – Sriram Sakthivel