jeudi 16 juillet 2015

ViewModel that use BaseViewModel and inherit of Model

I have n-layer app (Entity Layer - Business layer - Web layer). I like to use ViewModels (in Web layer) to have List of dropdown, etc to erich basic business object (Entity layer) to the UI. For that, I use a BaseViewModel (Web Layer) in every ViewModel that has dropdown or default values, it allows me to just call methods to fill datas, very usefull.

Now I want to find a smart way to avoid to re-type all the Entity Layer properties to VM.

For the moment, here is an example of what I do:

Model :

Class CustomObjectModel { 
public int id {get;set;} 
public string name {get;set;} 
public string description {get;set;} 
}

VM :

public Class CustomObjectViewModel : BaseViewModel { 
public int id {get;set;} 
public string name {get;set;} 
public string description {get;set;} 
public List<possibleNames> string  {get;set;} 
}

BaseVM:

public Class BaseViewModel{
public List<string> FillNames(){...}
public List<string> DefaultName(){...}
}

And I don't want to re-type Model properties to VM... How?

I could use inheritance: CustomObjectModel inherits of BaseViewModel and then CustomObjectViewModel inherits of CustomObjectModel but it is really not clean to have reference of WEB from Entites project and it makes me feel uncomfortable with it.

Thanks to help me :-)

Aucun commentaire:

Enregistrer un commentaire