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
[Request] Allow self-registration of handlers, etc. #7258
Comments
One potential use case is to make something like we have in the sample app that allows for a single // in the builder
builder.UseBorderlessEntry(); // <- bad name, should be UseBigLibrary() or something
// in the xaml control static ctor
BordelessEntryServiceBuilder.TryAddHandler<BordelessEntry, BordelessEntryHandler>(); Both have bad names, but I could see something like SkiaSharp doing this with a: builder.UseSkiaSharp() And then in the HandlersHelper.TryAddHandler<SKCanvasView, SKCanvasViewHandler>(); This could actually be made to work generally and then Maui exposes this "helper" class like this: MauiHandlerRegistrar.TryAddHandler<SKCanvasView, SKCanvasViewHandler>(); One issue with this is that this registrar is now a static thing, so should probably live in the Controls layer and Comet can copy. This way we preserve the fact that Core is testable because there is no singleton that lives forever. |
What if we enable the ability to return the desired handler from the concrete type? I know @Clancey enabled this at one point and then it got lost in the repository shuffle. If the concrete type could just return the handler type it wants to use. We wouldn't need to pass the handler collection around. We could have something like if (concreteType is IHaveMyOwnHandler myOwnHandler)
return myOwnHandler.GetHandlerType(); And then people could also more easily customize handlers per controls if they wanted to. |
I support this 1000%. I’m already time after time again seeing people not understanding why our controls don’t work, simply because they didn’t know they needed to call some obscure UseXxx() method in the builder. While I get the technical reason for it, it is incredibly developer unfriendly for 3rd party component customers. |
I also support this request. MAUI's lack of self-registration for custom handlers is a major step backward for anyone coming to MAUI from Xamarin and wanting to convert Xamarin custom renderers to handlers. In Xamarin, we could self-register a custom renderer using the
We use this pattern for custom renderers in internal NuGet libs that are used by multiple mobile apps within our company. Apps can use the cross-platform base class without having to know anything about the underlying custom renderer. Now, if I understand the MAUI documentation here and here correctly, every custom renderer or custom handler in our libs will have to be explicitly registered in each app's |
It is wrt startup time. The attribute approach is pretty bad because it relies on reflection, and it also runs the risk of the optimizer optimizing things away. |
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
Description
Imagine a library with a big amount of handlers, effects, etc.
UseLibrary()
extension method, but there are huge consequences for using such an approach. The problem is as follows - in the UseLibrary() method, we need to register everything - all handlers, renderers, effects, everything. Now the linker will not be able to strip away unused code - even if the client-dev uses only a couple of our controls.Public API Changes
We have to analyze possibilities to allow this.
Intended Use-Case
MauiApp.Current.TryAddHandler(Component1, Component1Handler)
The text was updated successfully, but these errors were encountered: