You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
it is just introduced as an "easy" solution
it is introduced for solving some problem similar to: <Page.DataContext> cannot be set to a class that does not have a parameterless constructor
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
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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
Beta Was this translation helpful? Give feedback.
All reactions