-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Experiments for Native Lifecycle #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- fonts into the new builder system - handlers now are configure/add - compat renderers are added like normal handlers - add a fe UseXxx extensions for "features"
mattleibow
commented
Apr 5, 2021
Comment on lines
+30
to
+37
| #if !WINDOWS_UWP | ||
| if (string.IsNullOrEmpty(args)) | ||
| { | ||
| var cliArgs = Environment.GetCommandLineArgs(); | ||
| if (cliArgs?.Length > 1) | ||
| args = cliArgs[1]; | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for this bug: microsoft/microsoft-ui-xaml#2005
Redth
approved these changes
Apr 5, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-essentials
Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info
fixed-in-6.0.100-preview.3.3
platform/android
platform/ios
platform/windows
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Description of Change
Hehe, OK. Probably went a bit nuts as I do when I am feeling zippy - whatever that means... As I was adding the configuration for essentials, I noticed a pattern. Each time I wanted to add a "feature" chunk, like configuring the handlers, configuring the lifecycle events, configuring essentials I could either take one of two approaches:
ConfigureServices. This is for example when adding the lifecycle, if I didbuilder.AddAndroid(...).AddAndroid(...)then I would end up with 2 service registrations. Things like essentials also do this to track events and we end up with even more service instances. This is all valid since we can doservices.GetServices<T>()and we get a collection back. However, this requires that we use the MS.Ext package, or we implement support for multiple services. Another down side is that I guess that returning multiple services, and then looking for the event in each of them is not as fast as a single dictionary lookup from a single service. And using the MS.Ext package adds overhead and perf things.IAppHostBuilder. This was done so that we could collect all the registrations, and then create and register a single service - reducing memory usage as well as unnecessary overhead of managing multiple services. I think @rmarinho did this for the handlers and was good enough. However as I started adding features, this started getting out of hand(lers ;)These issues are only there for the simple fact that we don't want to add overhead and avoid the perf issues with MS.Ext. And reduce work needed to do something simple.
So I was playing around with things and noticed these feature chunks were implemented in a "builder pattern" - most likely because I implemented them to be builders 😉 But, anyway, if we look at the handlers, for each hander registration, we would call
ConfigureHandlersonIAppHostBuilder. This adds the mapping to a list and then atBuild()time, we create a service collection. With the lifecycle event system, I configure the service and then for each event I would add the event delegate to a list. AtBuild()time I then collect all the events from the list and pass it to aILifecycleEventServiceand register that with the main collection.My solution for this was to use a new overload of
ConfigureServicesthat instead of having a delegate that passed theIServiceCollectiondirectly to you, I passed aIServiceCollectionBuilderThis means that there would only be one builder per concrete type. Each time you use that type, you get that same builder and additions to that builder are stored there. This also allows for some more flexible things without having to modify the main
IAppHostBuilderon each feature.An example of a library doing this for the user would be Essentials: https://github.com/dotnet/maui/blob/dev/native-lifecycle-events/src/Controls/samples/Controls.Sample/Extensions/EssentialsExtensions.cs
It would be consumed by the user in the simplest of ways:
When doing a feature, like lifecycle events, this also follows a simple pattern:
Each time either of the methods are called, they use the same builder object. Then, at the end of the day, we have a single builder, which means a single services, which means a single lookup.
PR Checklist
Does this PR touch anything that might effect accessibility?
If any of the above checkboxes apply to your PR then the PR will need to provide testing to demonstrate that accessibility still works.