Home » Java » Should services be used in a ViewModel

Should services be used in a ViewModel

Posted by: admin August 11, 2018 Leave a comment

Questions:

So I have a service which is injected in my controller via dependency injection. I can either use it in the controller multiple times to convert a value when assigning to a particular property in a ViewModel. Or I could pass an instance of the service to the ViewModel in the constructor and use it in the the setter of the property (C#). Which would be the best way?

I feel like the setter way would be the most maintainable. However, I don’t want to pollute the ViweModel. I’m not sure if I am breaking any best practices here.

Answers: