What do you think of putting get-logic in getters ViewModel? Sort of:
public class DummyViewModel { public int Id { get; set; } private DummyObject myObject; public DummyObject MyObject { get { if (MyObject == null) { DummyRepository repo = new DummyRepository(); myObject = repo.Get(Id); } return myObject; } } }
Is this bad practice or completely perfect? I find that my controllers are really bloated by doing all the get-logic, but I'm really torn as to where I should put this ...
My reason for this is that I can pass the ViewModel to different types of views, and only the required DB search will be performed depending on what property is being requested.
, - , "" ( ( ) , , ).
, GetAvailableClients , , . - IOW , ( ), LINQ, , .
GetAvailableClients
, , - , , , . -, , . , , , - , , , -, ... .
, .
:
1) . , ?
2) . - , viewmodel . , viewmodel ?
3) . Id ( - ) setter. ? , , , . , - , SoC.
- - DTO. , , VM .
Source: https://habr.com/ru/post/1742792/More articles:List of images that wrap - androidСоветы по использованию пользовательского контроля с помощью CToolTipCtrl? (МФЦ) - c++SQL join to capture data from one table through a staging table - sqlIs there an easy way to generate Erlang Thrift files for Cassandra on Windows? - erlangРезолюция Циркулярные ссылки для объектов Реализация ISerializable - .netcontinuous music on the site - htmlState chain design - javaSQL Express as the main database - .netHow to do simple mathematical operations and display the result in a text field - mathHow to programmatically record the start and end of MVC FileResult to register incomplete downloads? - model-view-controllerAll Articles