Simple explanation James, thank you! One thing to note here is that (since it may not be clear with View-ViewModel example), avoid injecting transient into singletons. Because the object you define as 'short living or stateless' is now living in an object you define as 'global'. Your transient will live inside this singleton for the whole application lifetime and it may create thread safety issues.
Awesome! In the last example where the page was defined as single and model as transient if cliqued on increase button certainly the number goes from 5 to 1. James should have done this.
Thanks for the explanation. I am used to c# windows application designs and familiar with binding the UI with a database like SQL or mySQL directly or via background code, but am struggling to understand the structure when it comes to MVVM and .net MAUI and linking to a hosted sql DB. I would appreciate if this is something you could give your opinion about. Thanks for the good content.
Thanks James. Was Using Maui for Windows App. Was using Transient for a Page which used Events (Events were enabled on appearing and disabled on disappearing). But noticed that the previously used transient Pages remained in memory and their event triggers triggered events in the New Page, so after leaving and returning to this page 3 or 4 times I was receiving 3 or 4 events when I should have received one!! Indicating the transient pages are remaining in memory! By switching the ViewModel and the the Page to Singletons this issue disappeared as would be expected. What I didn't understand is when transient pages are no longer being used why are they retained in memory?
Thanks for explanation, James. Nice video. I am curios, what is practical difference between Get() and Resolve() when using introduced in Xamarin Forms, DependencyService?
So when you register a class with a dependency injection service, and somewhere in the app an instance is being instantiated, does it automatically consult the service to see if there's an object? And does that apply to *any* object that's being created? And is the dependency injection service just storing the objects to be injected (the dependencies) or does it also store the objects that will be the recipients of the dependencies? So, if MainPage depends on a View Model, do you need to store both the Main Page and View Model, or just the View Model? [I feel like I am soooo close to understanding this 😀
Hello, I want to ask something I'm curious about. I create an instance of another class in a service registered as a singleton, with its new keyword. There will be only one instance of the singleton service within the application, but it will create another class inside it each time it is called. For example, if it is called 100 times, it will create 100 class instances. The last sample can be used but what about the previous 99 samples? Does the garbage collector detect and clean them or is this a memory leak issue? It's not the lifetime of the service I'm wondering about, it's what will be the class instances created in the singleton service.
Still to early in the day for me to get this. What I've been doing lately is creating ViewModels that function as services. I instance them using a script and keep the instance reference in a Dictionary. Every instance contains a GetView(string name) which can return any bound named view and a Process(string command) which allows me to script the object.
Some may be backwards compatible and some may to be updated, it depends on the package. On nuget you can see if it targets net6 then you know it is updated
Great explanation of singleton and transient. What would you recommend in order to handle Android screen rotations in Maui? When using Xamarin a screen rotation caused the activity to be recreated which effectively destroyed the data in the view. I suppose my real question is does Maui preserve the contents of the view when the screen is rotated?
just fyi when I want to create pdf's in Xamarin I open a web page from the app and send the app data to the web page and then save as pdf, a lot simpler, let me know if you find a better and cheaper way :) as not the fastest and easiest solution :( I tried all the other solution's on the net but couldn't get on with any of them
Want to learn about Scoped dependencies? Checkout my followup! th-cam.com/video/HMN26wQ8J54/w-d-xo.html
Simple explanation James, thank you!
One thing to note here is that (since it may not be clear with View-ViewModel example), avoid injecting transient into singletons. Because the object you define as 'short living or stateless' is now living in an object you define as 'global'. Your transient will live inside this singleton for the whole application lifetime and it may create thread safety issues.
Shared, subscribed, and liked. You deserve it. All of it brother. Best wishes to you for your progression and may you excel to your very best.
Thanks for such a great explanation, James. Since I started following you I'm learning a lot!
Congrats James as always is comming awesome content!
Great video. Nothing new to me, but it's great to actually see the differences in this way, it helps and confirms existing practices.
Excellent. It cleared all the doubts. Thanks James.
Finally an example without GUIDs, thank you
very good explanation of dependency injection, thank you james!
Thanks ! Very easy to understand and super interesting.
Thank for the video James. Super helpful.
Awesome! In the last example where the page was defined as single and model as transient if cliqued on increase button certainly the number goes from 5 to 1. James should have done this.
Que gran maestro James, te felicito por la excelencia de tus tutoriales
Will add this in next weeked side project.
Very good explanation, thank you for clarifying this.
Great example, astonishing app 🙂
Great explanation. You could talk about STATIC variables inside Transient injections too. Thx James
Very clear to the point.
Thank you very much for your effort
Hi James can you please make a video on unit testing
Thanks for the explanation. I am used to c# windows application designs and familiar with binding the UI with a database like SQL or mySQL directly or via background code, but am struggling to understand the structure when it comes to MVVM and .net MAUI and linking to a hosted sql DB. I would appreciate if this is something you could give your opinion about. Thanks for the good content.
Great video @james. When would you use scope in a WPF/MAUI application? Maybe when you open a file the application can work on?
Never, for web apps only docs.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#scoped
Smooth. Nice!!!!
Thanks!
Thanks James. Was Using Maui for Windows App. Was using Transient for a Page which used Events (Events were enabled on appearing and disabled on disappearing). But noticed that the previously used transient Pages remained in memory and their event triggers triggered events in the New Page, so after leaving and returning to this page 3 or 4 times I was receiving 3 or 4 events when I should have received one!! Indicating the transient pages are remaining in memory! By switching the ViewModel and the the Page to Singletons this issue disappeared as would be expected. What I didn't understand is when transient pages are no longer being used why are they retained in memory?
Thanks for explanation, James. Nice video.
I am curios, what is practical difference between Get() and Resolve() when using introduced in Xamarin Forms, DependencyService?
Amazing explanation!
So when you register a class with a dependency injection service, and somewhere in the app an instance is being instantiated, does it automatically consult the service to see if there's an object? And does that apply to *any* object that's being created? And is the dependency injection service just storing the objects to be injected (the dependencies) or does it also store the objects that will be the recipients of the dependencies? So, if MainPage depends on a View Model, do you need to store both the Main Page and View Model, or just the View Model? [I feel like I am soooo close to understanding this 😀
Transient pages loaded from the shell do not behave transient. This is a bug which is already open for months.
Have you find any workaround to this?
can you do a video on how to connect netmaui app to sqlserver
Amazing explanation 👌
Thanks James!
I really understand Singeltons and Transients but I’ve got problems with the third type. What’s the secret of the Scoped instances?
Gotta wait until next week to find out tehehehe
Hello, I want to ask something I'm curious about.
I create an instance of another class in a service registered as a singleton, with its new keyword.
There will be only one instance of the singleton service within the application, but it will create another class inside it each time it is called.
For example, if it is called 100 times, it will create 100 class instances. The last sample can be used but what about the previous 99 samples? Does the garbage collector detect and clean them or is this a memory leak issue?
It's not the lifetime of the service I'm wondering about, it's what will be the class instances created in the singleton service.
how do I get back to a previous page but when a button is clicked?
Still to early in the day for me to get this.
What I've been doing lately is creating ViewModels that function as services. I instance them using a script and keep the instance reference in a Dictionary. Every instance contains a GetView(string name) which can return any bound named view and a Process(string command) which allows me to script the object.
Hi James do you have a course in Udemy?
6:40 어렵지만 중요한 내용. 난 그냥 new를 쓰고 싶다. ㅎㅎ
does Xamarin packages still work with Maui ? things like Macha for background tasks for example
Some may be backwards compatible and some may to be updated, it depends on the package. On nuget you can see if it targets net6 then you know it is updated
Great explanation of singleton and transient. What would you recommend in order to handle Android screen rotations in Maui? When using Xamarin a screen rotation caused the activity to be recreated which effectively destroyed the data in the view. I suppose my real question is does Maui preserve the contents of the view when the screen is rotated?
It preserves the screen state automatically. Android does by default now
Very concise.😁
AWESOME 👌 🆒️ 🙌 👍👍👍😁
Is Singleton per user or global for everyone?
Singleton will return the same instance when requested.
And AddScooped ?
For web projects only really docs.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#scoped
By "request" do you mean a http request or do you mean request for an object?
Need to create a pdf / printable page like receipt printing /barcode stickers printing using .Net Maui, please help.
just fyi when I want to create pdf's in Xamarin I open a web page from the app and send the app data to the web page and then save as pdf, a lot simpler, let me know if you find a better and cheaper way :) as not the fastest and easiest solution :( I tried all the other solution's on the net but couldn't get on with any of them
JamesMontemagno => GEMSMontemagno ♥