zynthh
zynthh
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
The constructor is being called before. I verified this by stepping through with the debugger.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
(I don't really know the WPF terminology, this is my first contact with the framework, I'm sorry.)
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
Thanks all for your answers. I think my question was kind of answered, but I guess I will just normally instantiate an instance of my Service in my Page and use DI where nothing "frontend" is involved. Or if anyone knows a way how I can achieve it (maybe by refactoring the Page to a Component idk) please let me know.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
OK that doesn't sound very good tbh. I'm wondering now, if you're even supposed to use DI with WPF that way. Have you used it in that way before? Or maybe someone else? I would love your feedback. 😄 In the end I could always just instantiate my Service normally in SomePage and everything should work, right?
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
That doesn't work either. I don't want to inject SomePage anywhere, so why would I need to register it? I mean I tried it but it still doesnt't work. I want to inject SomeService into SomePage. And SomeService is registered. Maybe it's the way SomePage is being used in my MainWindow?
<Frame x:Name="SomeFrame" Source="Pages/SomePage.xaml" Loaded="SomePage_Loaded" />
<Frame x:Name="SomeFrame" Source="Pages/SomePage.xaml" Loaded="SomePage_Loaded" />
Could that be a reason for my error?
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
Thanks for your feedback. I tried adding it both as a scoped and a transient service but the same error remains.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
Or rather, we can get this to work 😄
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
It's getting late here, I appreciate your help. I will be active here again tomorrow. Hopefully I can get this to work.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
No, I transferred it into my project. He didn't have an example for what I'm trying to achieve. That is, injecting a dependency into another dependency basically. I just found out that, if I remove the injection of SomeService in SomePage, the app builds just fine.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
When I build the app, this exception that you can see in the screenshot is thrown. You can see in the top bar it says DefaultBinder.cs. It's some sort of internal .NET file.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
So, any more suggestions?
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
I setup DI as shown in this video. They used the non-null assertion operator there.
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
48 replies
CC#
Created by zynthh on 4/19/2023 in #help
❔ ✅ Trouble getting Dependency Injection to work in a WPF application
Thats not my code dude. thats where the exception is thrown
48 replies