How are you populating/validating your ViewModels?

后端 未结 4 366
闹比i
闹比i 2021-01-30 03:40

I\'m curious of all of the various ways people are building their ViewModels and why they choose that method.

I can think of several ways here:

-1. Injected repo

4条回答
  •  -上瘾入骨i
    2021-01-30 03:45

    I just finished a project where we did a variation on #4. We had a service class injected into the controller. The service class held dependencies on the repository and a model builder class (we called it model factory).

    The controller called into the service class, which handled business validation logic, and then fetched view models from the appropriate factory. The models themselves relied on data annotations for input validation.

    It worked really well for our team. There was enough separation of concerns to allow the devs to do their work without affecting one another, but it was manageable enough to understand what was going on.

    It's the first time we tried it and we'll be sticking with it. I'm interested to see how others respond.

提交回复
热议问题