What is the best way to call dataservices and organise a modular project in WPF ?
I am pretty new in MVVM and WPF and I have a project with at least :
- 1 main "organizer" module
- 10 independant modules (whose are loaded or not)
- A dataservice in each module to do some operation with my data
I want to know if they are a way to call my module dataservice from my main organizer module dynamically without using a super_long_switch_case_of_death_with_redondant_code. What is the best way to achive this ?
For exemple, when I click on one of my item (in a treeview), I call a command which execute this function :
private void AddNewThingsCommand(object myObject)
{
if (myObject== null) return;
var objectType = myObject.GetType().ToString();
switch (objectType)
{
case "FirstObjectType":
ModuleFirst.Services.ModuleFirstDataService moduleFirstDataService = new ModuleFirst.Services.ModuleFirstDataService ();
moduleFirstDataService.DoSomeSuperActionInMyDataService(someObject);
break;
case "SecondObjectType":
ModuleSecond.Services.ModuleSecondDataService ModuleSecondDataService = new ModuleSecond.Services.ModuleSecondDataService ();
ModuleSecondDataService.DoSomeRandomSuperActionInMyDataService(someObject2);
break;
default:
break;
}
}
But it seem to be really repetitive and useless stuff to do, have you any idea how to automatize that ?
I don't need a WPF Trigger based on Object Type I am looking for something I can use in a command to dynamically load my services and get items throught my modules.