Service locator pattern with ViewModels #4728
Marek Bor (Marek-Bor)
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello!
I am very new to TemplateStudio (looked at it only a few months ago and now I want to partially use TemplateStudio start project implementation for my own WinUI 3 implementation - kind of mix a bit of my sh-tcode in). But I have a question now.
Is using service locator pattern with ViewModels like ViewModel = App.GetService(); a good idea?
Service locator pattern is usually concidered an anti-pattern but TemplateStudio initializes all viewmodels using this pattern. I wondered if:
So I would like someone to comment if using service locator pattern with view (for initializing viewmodels) is a common practice? If so - what problem does it solve? The same questions go for ViewModels.
Why I ask:
As an example while developing for WinUI 3 without using TemplateStudio: I have a page in my application that end-user can generate xlsx specifications from Tekla BIM models, so it uses two services - ITS2022Integration and IXlsxExchange. This means I can call them directly within defined commands in my ViewModel as I have injected them into ViewModel's constructor. My NavigationService implementation looks quite different because of this (opposed to TemplateStudio) as well as all my Views are commonly injected with according viewmodels. Am I overengineering here? Or it is a good practice?
Kindest regards and thanks to anyone who could spare some time to comment,
Marek
All reactions