.NET MAUI supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. On top of that it fully supports constructor injection and full dependency resolution when navigating when using Shell. I break down every little thing you need to know about DI, IoC, and constructor injection with .NET MAUI.
Note: That [ICommand] is now [RelayCommand] from the .NET community toolkit!
Links:
Sample Code: https://github.com/jamesmontemagno/MauiApp-DI?WT.mc_id=friends-0000-jamont
MVVM Source Generators: https://github.com/jamesmontemagno/MVVMSourceGenerators?WT.mc_id=friends-0000-jamont
.NET Podcasts App: https://github.com/microsoft/dotnet-podcasts?WT.mc_id=friends-0000-jamont
.NET MAUI Documentation: https://docs.microsoft.com/dotnet/maui/?WT.mc_id=friends-0000-jamont
Dependency Injection in .NET: https://docs.microsoft.com/dotnet/core/extensions/dependency-injection?WT.mc_id=friends-0000-jamont
Dependency Injection in ASP.NET Core: https://docs.microsoft.com/aspnet/core/fundamentals/dependency-injection?WT.mc_id=friends-0000-jamont
.NET MAUI Workshop: https://github.com/dotnet-presentations/dotnet-maui-workshop?WT.mc_id=friends-0000-jamont
Join this channel to get access to perks:
https://www.youtube.com/channel/UCENTmbKaTphpWV2R2evVz2A/join
👕 Buy some swag! - https://jamesmontemagno.myspreadshop.com/
☕️ Buy me a coffee - https://www.buymeacoffee.com/jamesmontemagno
Chapters:
00:00 - Intro
01:15 - What is dependency injection?
04:55 - Source code walkthrough
07:10 - Registering services
09:30 - Resolving services
12:00 - Constructor injection & resolution of dependencies
14:00 - Automatic dependency resolution with Shell
17:08 - Wrap-up
Follow:
👨💻 GitHub: https://github.com/jamesmontemagno
🦜 Twitter: https://twitter.com/jamesmontemagno
📄 Website: https://www.montemagno.com
📰 Newsletter: https://newsletter.montemagno.com/
Disclaimer: This channel, videos, and streams are created in my spare time and are a product of me... James Montemagno! They are NOT officially affiliated or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.
What is on my hat? It is the CLE clothing logo because I am from Cleveland! Checkout their awesome CLE merch: https://cleclothingco.myshopify.com/
What is that art on my wall? It is an original piece from the French street artist Gregos of La Butte Montmartre: https://www.instagram.com/p/BceZ1oNHiQx/
My Setup:
💡 Nanoleaf Elements Lights - https://amzn.to/3umwJVW
🎙 Blue Spark Microphone - https://amzn.to/3qgtYkq
🎙 Blue Pop Filter - https://amzn.to/3jEWM3r
🤳 Rode Microphone Arm - https://amzn.to/2Z68AlE
🎧 Sony MDR7306 Headphones - https://amzn.to/372jxta
📲 Stream Deck - https://amzn.to/373Uk1n
📹 Elgato Cam Link - https://amzn.to/3a9eGbh
📷 GoPro Hero - https://amzn.to/374lm90
🖱 MX Master 2S Mouse - https://amzn.to/3d7J2gj
⌨️ Tecware Phantom Keyboard - https://amzn.to/3aUP4y9
#dotnetmaui #dependencyinjection #dotnet #ios #android #netmaui #maui