Wether Używam Automappera lub mapowania ręcznego, które nie odgrywa żadnej roli.Nadal waham się używać ViewModels zamiast modelu do widoku
Wszystkie dane dla ReleaseViewModel muszą znajdować się na pierwszym miejscu w Wydaniu, ponieważ wypełnia się je warstwa dostępu do danych. 90% mojego modelu jest w ten sposób. Dlaczego narzut duplikowania wszystkiego?
Co z zasadą KISS i nadmierną inżynierią?
Oczywiście każde narzędzie do odpowiedniego zadania, ale bardzo często czytam na SO, że nie używanie ViewModels w asp.net mvc jest NO-GO.
Gdzie narysować linię? Czy należy używać ViewModels, gdy różnią się one do 50%, 75% lub 99% od moich modeli?
Mam Model Release:
public class Release
{
public int Id { get; set; }
public string Name { get; set; }
public string Author { get; set; }
public DateTime CreatedAt { get; set; }
public int FailedTestsCount { get; set; }
public int SucceededTestsCount { get; set; }
public int SumTestsCount
{
get
{
return SucceededTestsCount + FailedTestsCount;
}
}
public int SumTestingTime { get; set; }
}
się ReleaseViewModel ViewModel:
public class ReleaseViewModel
{
[HiddenInput(DisplayValue = false)]
public int Id { get; set; }
[Required(ErrorMessage = "Name must not be empty.")]
[StringLength(30, ErrorMessage = "Enter max. 30 chars for a name.")]
[Remote("ReleaseExists", "Release", ErrorMessage = "This name already exists.")]
public string Name { get; set; }
public string Author { get; set; }
public DateTime CreatedAt { get; set; }
public int FailedTestsCount { get; set; }
public int SucceededTestsCount { get; set; }
public int SumTestsCount
{
get
{
return SucceededTestsCount + FailedTestsCount;
}
}
public int SumTestingTime { get; set; }
}
Czy twoja klasa wydania jest DTO, czy jest to obiekt domeny z funkcjonalnością? – Jupaol
jest to obiekt domeny. Nie mam wielu warstw, aby mieć potrzebę dto. – Pascal
Dlaczego nie chcesz, aby Nazwa była wymagana i miała być mniejsza niż 30 znaków w modelu Twojej domeny? Mimo że model Twojej domeny nie może wyświetlić ładnego komunikatu dla użytkownika, może on nadal odmawiać przetworzenia, jeśli parametr ModelState.IsValid ma wartość false. Przynajmniej tak myślę, że powinieneś to zrobić, ale jestem nowicjuszem –