Dependency Injection on ViewModels #15630
-
I have a User control (ReacticeUserControl) that I created a ViewModel for:
I instantiate it in the ReacticeUserControl code behind:
All good so far. If I now want to inject a dependency into the ViewModel like so:
This means when I try to instantiate it requires this parameter and kind of defeats the point of DI. In my App code behind I have set up the configuration needed:
Just feel like I am missing or have missed a step somewhere, trying to keep things lightweight and only use ViewModels where needed |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
check Avalonia.Samples -> ViewInteractionSample |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
I think this is my issue, coming from a asp.net core background I was just expecting after some initial set up against the
Host.CreateDefaultBuilder()
that that would be enough, but looking through the docs and watching AngelSix it looks like the DI service registration is needed within theOnFrameworkInitializationCompleted