Dependency Injection with Microsoft.Extensions in Xamarin.Forms

  Рет қаралды 9,501

Gerald Versluis

Gerald Versluis

Күн бұрын

Пікірлер: 52
@paulute68
@paulute68 3 жыл бұрын
wow, one of the best video on Dependency Injection, very clear. Thanks for taking time to explain.
@jfversluis
@jfversluis 3 жыл бұрын
That is such a big compliment! Thank you Paul!
@Thaizer
@Thaizer 3 жыл бұрын
Nice video. Like to see a video of DI in MAUI. Keep up the great work.
@jfversluis
@jfversluis 3 жыл бұрын
That will definitely come thanks!
@Luca_040
@Luca_040 Жыл бұрын
Great video, refactoring our xamarin forms app to use dependency injection finally
@pakalex13
@pakalex13 3 жыл бұрын
Awesome explanation about this topic, very simple and easy to understand! great video!
@jfversluis
@jfversluis 3 жыл бұрын
Thank you so much friend!
@SayyadHasan
@SayyadHasan 3 жыл бұрын
Again awesome tutorial, Thanks Gerald!
@jfversluis
@jfversluis 3 жыл бұрын
Thank you!
@lexusprogrammer4515
@lexusprogrammer4515 3 жыл бұрын
What about when you have already wired up and Binded the Context of the ViewModel directly into the View but now with “IMyService” injected into it using the Constructor, I’m trying to avoid Binding the Context from the Code behind.
@jfversluis
@jfversluis 3 жыл бұрын
I'm not entirely sure what you mean :)
@briancarroll9982
@briancarroll9982 3 жыл бұрын
@@jfversluis I think he may be asking the same question I have. In your example, the BindingContext is being set from the code behind, but when trying to set it from within the XAML using , we get an error stating the "Type 'MainPageModel' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter." Do you know how to get around that?
@EngDuraid
@EngDuraid 3 жыл бұрын
Thank you very much for the good explanation
@jfversluis
@jfversluis 3 жыл бұрын
Glad it was helpful! Thanks for letting me know!
@revtane9
@revtane9 3 жыл бұрын
Amazing tutorial as always
@jfversluis
@jfversluis 3 жыл бұрын
Yay thanks!
@rizwansiddiqui5351
@rizwansiddiqui5351 3 жыл бұрын
Great tutorial! I have a question, how about using this to set up a service across multiple platforms (iOS, Android). I have a interface that is implemented in platform specific code and I want to register that interface to the DI container
@jfversluis
@jfversluis 3 жыл бұрын
Good question! You would have to expose you di container in the platform project somehow and register the platform specific implementation that way :)
@amolband8403
@amolband8403 2 жыл бұрын
Great Video! One questions why we have to use Microsoft.Extention when there already having default DI in Xamarin.Forms What is the differances with that Thanks
@jfversluis
@jfversluis 2 жыл бұрын
Thank you! There is no dependency injection built-in to Xamarin.Forms. The DependencyService is there but it lacks features and the performance isn’t great so you shouldn’t be using that.
@Malkaviansters
@Malkaviansters 2 жыл бұрын
Hey Gerald, How can you navigate around pages from ViewModels, when using this approach ?
@jfversluis
@jfversluis 2 жыл бұрын
You'll have to implement something for that yourself. FreshMvvm does it, which is open source so you might be able to borrow some inspiration from there
@mwardell18290
@mwardell18290 2 жыл бұрын
Okay Great Video. This is the DI Container of Choice possibly for my new project... One major question which remains; What about when you need X Platform Injection/Resolution? Into the actual Android/iOs Boundary?
@jfversluis
@jfversluis 2 жыл бұрын
If you're going to use .NET MAUI you won't even need this. Something is already built-in. This is how you could leverage DI for platform-specific code: kzbin.info/www/bejne/boPMZqGAqMajhas
@JonnyBooker
@JonnyBooker 2 жыл бұрын
Have implemented something similar in my project and this reaffirms what I'm doing makes sense! Quick question, do you think anything in terms of disposal of the Service Provider should be done at all? I know it implements I disposable so wasn't sure whether I should be potentially calling dispose on sleep and re-creating it on resume
@jfversluis
@jfversluis 2 жыл бұрын
I don't think you'd have to bother unless you're doing something really advanced. The Service Provider will live for your whole application lifecycle and be gone when the app gets shutdown.
@paulegan3783
@paulegan3783 2 жыл бұрын
Dank je wel!
@jfversluis
@jfversluis 2 жыл бұрын
Alsjeblieft!
@Varinator
@Varinator 3 жыл бұрын
You can make it even more automated by using reflection. You can look for every Type that's name ends with "Service", then for each of the interfaces it implements you add it to the serviceProvider. You can even have a ServiceScope attribute on Interfaces to define which scope you want it to be injected as, which can also be grabbed using reflection. In the end, as long as you stick to naming convention, you can inject everything you create automatically by just writing that one dependencyInjection method and not have to worry about always adding each thing to the services as you create it.
@yuriyholembyovskyy1223
@yuriyholembyovskyy1223 3 жыл бұрын
Amazing content! What I have seen from .NET MAUI samples it will use MS.Ext.DI by default or some modified version of it. Am I right? Hence it's a good idea to use this DI in your current XF apps and it will be easier to migrate to .NET MAUI.
@jfversluis
@jfversluis 3 жыл бұрын
I need to look into the details, but it should be very similar to using these extensions indeed. Maybe just even installing this literal nuget and use that :) Thanks!
@caplens_apps
@caplens_apps 3 жыл бұрын
Thanks ! I am currently using the FreshMvvm Ioc in my apps, and I am hesitating to migrate as with the freshmvvm DI system, I don't need to register the viewModels before instantiating them. Any thoughts?
@jfversluis
@jfversluis 3 жыл бұрын
If you are already using FreshMvvm definitely keep using that. This is just an alternative :)
@MiguelGarcia-mb6bu
@MiguelGarcia-mb6bu 3 жыл бұрын
Great tutorial! Thanks for do it, by chance You will have an sample about dependency service with xamarin forms and native using Bluetooth API?
@jfversluis
@jfversluis 3 жыл бұрын
Using it with Bluetooth is no different than using it with anything else :) you might also want to check out Shiny
@woistdasniveau8290
@woistdasniveau8290 2 жыл бұрын
Could you make a video on autofac too please? All the tutorials i find are quite outdated.
@jfversluis
@jfversluis 2 жыл бұрын
Oh that might be a nice idea! Anything specific?
@TVsBen
@TVsBen 2 жыл бұрын
This was super helpful today in late 2022. Part of reducing technical debt included removing un-maintained NuGets, like TinyIoC, so I had my work cut out for me. At first I struggled to get platform-specific implementations of services injected but in the end I just added the Microsoft.Extensions libraries to all the projects in my solution and used the IServiceCollection extension methods to make it work. I add all the platform-specific service implementations in the Android and iOS projects, and it calls the extension method to add all my PCL services, and the App class's static ServiceProvider gets built from the platform code (MainActivity.OnCreate / AppDelegate.FinishedLaunching) after that. That way the ServiceContainer is in the App class, and I populate it before calling Forms.Init(). When Forms starts, all the services are already there.
@UzairAli001
@UzairAli001 3 жыл бұрын
What are the benefits of using this over 3rd party libraries like AutoFac, I've already created a robust service for Autofac so should I switch to microsoft's DI?
@jfversluis
@jfversluis 3 жыл бұрын
If you already have something in place that you are happy about how it's working and performing, please keep using that!
@jmoralesv03
@jmoralesv03 3 жыл бұрын
Great video Gerald! I think .NET MAUI will be more DI friendly, right? I remember following James' blog some time ago and it works great but I had the feeling DI was being added on top of Xamarin.Forms instead of being a first class feature, in the same way .NET Core 3.1 and .NET 5 already have it. I'm looking forward to see the DI improvements in .NET MAUI 💻📱
@jfversluis
@jfversluis 3 жыл бұрын
Thank you! .NET MAUI will definitely be more DI friendly, although that just means it already has some things on board to make it easier. It's a concept, not so much a technical implementation so it being "on top of" Xamarin.Forms, I don't know about that. In the end the concept still works the same between Forms and .NET MAUI, just the implementation is different. But anyway... Yea! It will be better with .NET MAUI :D
@mandardesai3841
@mandardesai3841 3 жыл бұрын
Hi Gerald Thanks for the tutorial Will you make a video on complete xamarin app development like DevOps means how we use azure, jira, Github, visual studio, app center some analytic tools and other tools in smart way. inshort all modern tools that use in xamarin application development. i hope you understand what i mean. Thanks again.
@philippedoumet6073
@philippedoumet6073 3 жыл бұрын
Hello Gerald, can you please make a video about integrating stripe payments in xamarin forms?🙏🏻🙏🏻
@philippedoumet6073
@philippedoumet6073 3 жыл бұрын
And I have an error that is coming when i upload a picture in firebase, can I send it to you?
@jfversluis
@jfversluis 3 жыл бұрын
You can post it in the Discord server so other people might be able to help as well :)
@checox1909
@checox1909 3 жыл бұрын
Great video man, can you do something about how to use bluetooth with dependency services to implement our own methods without depending on any 3rd party library... I'm trying to do something like that in a project but could be cool if there are any docs of someone implementing that.
@jfversluis
@jfversluis 3 жыл бұрын
Why would you want to do that? I guess you could just take a look at an open-source library that does this and implement your own from that :)
@checox1909
@checox1909 3 жыл бұрын
​@@jfversluis Hehehehe, Yes that's exactly what I'm doing, I just wanted to know if you have a better way to do it, I'm using plugin.ble, but that library has poor documentation, but I'm using it to implement it on my own
@thatrandomguybob4800
@thatrandomguybob4800 3 жыл бұрын
I am also trying to get bluetooth (BLE) integrated into my app, using Shiny 2.0. I am having a heck of a time as I am not a seasoned developer and I am new to DI.
Dependency Injection in .NET Core (.NET 6)
1:00:32
IAmTimCorey
Рет қаралды 197 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Dependency Injection with .NET MAUI Explained! Full Beginner's Guide
19:18
Dependency Injection & IoC containers with Xamarin Forms
23:30
Houssem Dellai
Рет қаралды 15 М.
Dependency Injection for Absolute Beginners with C# and .NET
17:02
Gerald Versluis
Рет қаралды 203 М.
Create Custom Controls using BindableProperty for Xamarin.Forms
17:48
Gerald Versluis
Рет қаралды 16 М.
CRUD Operations with SQLite for Xamarin.Forms and .NET MAUI
18:53
Gerald Versluis
Рет қаралды 15 М.
Dependency injection fundamentals in C# - DI vs IoC vs DIP
13:30
Amichai Mantinband
Рет қаралды 45 М.
Xamarin.Forms ListView vs. CollectionView - Which to use and why!
20:14
James Montemagno
Рет қаралды 31 М.
Getting Started with Dependency Injection in Xamarin.Forms
19:41
James Montemagno
Рет қаралды 16 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН