Тёмный

Avalonia UI - 06 - Dependency Injection 

Mamma Mia Dev
Подписаться 957
Просмотров 3,1 тыс.
50% 1

Hello everyone and welcome to this new episode of the Avalonia UI series. In this video we'll dive into Dependency Injection and how to use it inside an Avalonia project.
► DI definitions:
Wikipedia: en.wikipedia.org/wiki/Depende...
Microsoft learn: learn.microsoft.com/en-us/dot...
► 3rd party DI containers:
DI in Avalonia using Lamar by Khalid Abuhakmeh: khalidabuhakmeh.com/dependenc...)
DI using Reactive Splat: www.reactiveui.net/docs/handb...
► DI using Microsoft packages
StackOverflow question: stackoverflow.com/questions/7...
Add MsExtensionsHostingSample sample project PR: github.com/AvaloniaUI/Avaloni...
Sample code to set up view locator using Microsoft DI from kekekeks: github.com/AvaloniaUI/Avaloni...
Reddit question: / microsoftextensionsdep...
► CommunityToolkit Experimental package
Experimental package PR: github.com/CommunityToolkit/L...
How to fetch packages from the community toolkit preview Nuget Feed: github.com/CommunityToolkit/W...
Example project to showcase the use of the CommunityToolkit Experimental package: github.com/stevemonaco/Avalon...
► GitHub repo: github.com/MammaMiaDev/avalon...
0:00 Intro
0:52 Dependency Injection
2:08 DI in Avalonia
2:56 3rd party DI containers
3:40 Microsoft DI packages
4:31 Community Toolkit Labs DI package
5:31 Sample project
6:36 Conclusions

Наука

Опубликовано:

 

7 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 30   
@CH-pv3te
@CH-pv3te 6 месяцев назад
Really happy to see someone else is struggling with DI in Avalonia - thought I was the only one!
@MammaMiaDev
@MammaMiaDev 6 месяцев назад
ehehe yeah! And from what I understood, I'm just scratching the surface. I've already faced a couple situations where I struggled a bit to make DI behave properly. For instance at DesignTime, where the new CommunityToolkit DI container might not be initialized. Or when you start mixing stuff by putting ViewModels as View constructor arguments 🤯
@CH-pv3te
@CH-pv3te 6 месяцев назад
@@MammaMiaDev Coming from an MVC background you dont realised how spoiled your are with the instantly available features. I'm really enjoying Avalonia - just wish there was more documentation.
@StefanOlson
@StefanOlson 6 месяцев назад
Love the work you put into this!
@nevelate
@nevelate 6 месяцев назад
Thanks, amazing video!
@manueliriarte1535
@manueliriarte1535 4 месяца назад
you have my like on this, I am just starting a project in Avalonia and so far I have some resentments about it haha like the lack of documentation, and real world examples, when trying to implement DI got to the same page you show there and a bit more resentment was added to me haha but I was looking for something like this, thanks man. great video too.
@MammaMiaDev
@MammaMiaDev 3 месяца назад
Thanks! Avalonia's team is putting a lot of effort in improving the documentation. We just gotta be patient 😄
@gadgetkh9408
@gadgetkh9408 6 месяцев назад
❤❤❤
@arif1984may
@arif1984may 6 месяцев назад
You are amazing! :) thank you so much for your effort. Looking forward for DI focused project example. How about an app with login screen, which after successful login navigates to main page? U could use cookies for web app and secure storage for mobile app to avoid the login if the user already authorised. Anyway, thank you so much for these unique tutorials!
@MammaMiaDev
@MammaMiaDev 6 месяцев назад
You are too kind. Thanks😄
@vladmartian
@vladmartian 4 месяца назад
Now you can find some documentation on Avalonia Documentation about Dependency Injection
@MammaMiaDev
@MammaMiaDev 3 месяца назад
Some new documentation you mean? Got any link to it?
@matsydoodles
@matsydoodles 2 месяца назад
The issue I have is that, Avalonia wants to have an empty constructor for DesignTime and I'm inclined not to use what is essentially a service locator to do this as that makes it less obvious from the outset of its dependencies.
@MammaMiaDev
@MammaMiaDev 2 месяца назад
A workaround could be to have 2 constructors maybe: one with injected parameters, and an empty one where you manually create the services (or fakes). The empty one will be used at design time, and the other one at runtime.
@matsydoodles
@matsydoodles 2 месяца назад
@@MammaMiaDev Yeah, I had that initially, but it looked smelly because it was never used, and Visual Studio would complain that it could be deleted, etc. I really don't like the idea of mixing live and debug code together. In the end, I settled on creating "DesignTime" ViewModels, e.g., DesignTimeMainWindowViewModel.cs, which inherits from the MainWindowViewModel. I then used NSubstitute to mock the services and pass them down to the base of the MainWindowViewModel. Not that I plan to, but this then would allow me to easily mock service interactions for the design time and not pollute my code with if(designtime etc.
@CH-pv3te
@CH-pv3te 6 месяцев назад
Did anyone manage to get this working with anything other than views/viewmodes? IE a service?
@parko1965
@parko1965 5 месяцев назад
Yes what you stuck with?
@CH-pv3te
@CH-pv3te 5 месяцев назад
I actually managed to get it working in the end. Just had to stick at it. Thanks.
@MammaMiaDev
@MammaMiaDev 5 месяцев назад
Hey @CH-pv3te, happy to know you got it working!
@CH-pv3te
@CH-pv3te Месяц назад
@@MammaMiaDev I've recently come back to avalonia, is this version of DI a service locator pattern? Isnt that considered bad?
@NEProductionE
@NEProductionE 25 дней назад
@@CH-pv3te Ya afaik service locator pattern is an anti pattern and thats why i dont really understand why its used then just dont use DI cause it makes no sense if you trick your way around xD
@Diegovnia
@Diegovnia Месяц назад
I swear to god... Every time I'm starting even a simple project I end up using this Microsoft Di and I waste about 2-4 hours because I never remember that shit... Then I promise myself to just make a template for myself on git... of course I don't do that...
@MammaMiaDev
@MammaMiaDev Месяц назад
ahahahah story of my life :D
@MultiLeechCZ
@MultiLeechCZ 5 месяцев назад
Why did you remove my posts pointing out that is not working? I also include the source as proof. Instead of remove it should check it see what is wrong.. It was very rude..
@MammaMiaDev
@MammaMiaDev 5 месяцев назад
Hey, I can assure you I didn't remove your comment. I'm not sure of what happened, and I'm so sorry for that. I can still see your comment in the channel notifications, but it's not listed here for some reasons. By the way, from the comment I can see you can't find the experimental DI library anymore? Have you tried enabling "prerelease" packages? Because I can still see it in the Labs namespace. Current version seems to be "0.1.240124-build.1624"
@phykk
@phykk 4 месяца назад
Make sure the URL in the package manager to Community Toolkit is set correctly. I somehow had "-latest" in the url. After removing it I could see the DependencyInjection package.
Далее
Avalonia UI - 07 - Beautiful apps with Fluent UI
14:20
Dependency Injection | Prime Reacts
28:34
Просмотров 304 тыс.
POLI зовет Газана
00:12
Просмотров 572 тыс.
Yeni Özbək Mahnisi Yoxsa Vefali Reqsi? 😍
00:36
Просмотров 2,1 млн
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Просмотров 1,2 млн
WPF Running in the Browser
1:31
Просмотров 1,7 тыс.
Has Generative AI Already Peaked? - Computerphile
12:48
Is There Hope For .NET MAUI?
7:10
Просмотров 25 тыс.
WHY did this C++ code FAIL?
38:10
Просмотров 195 тыс.
Dependency Injection, Generic Host, and WPF
2:44:29
Просмотров 7 тыс.
I DONT USE NEXT JS
54:01
Просмотров 328 тыс.
Avalonia UI - 01 - Project Setup
30:37
Просмотров 10 тыс.
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Просмотров 448 тыс.
Сравнили apple и xiaomi!
0:21
Просмотров 27 тыс.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00