Skip to content

[Request] Allow self-registration of handlers, etc.  #7258

@jsuarezruiz

Description

@jsuarezruiz

Description

Imagine a library with a big amount of handlers, effects, etc.

  • If a client-dev wants to use the components - he needs to put a lot of code in the CreateMauiApp() method. If the client-dev uses a NuGet - it will not be obvious that there is an additional step he needs to do to get the components working.
  • We can implement a single 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.
  • It will be very useful if we can introduce a property in the MauiApp class that will allow to dynamically register a handler. For example, the static constructor of a Component1 can execute a call like MauiApp.Current.TryAddHandler(Component1, Component1Handler). This way if a client-dev uses Component1 - the handler will be registered automatically. If the client-dev does not use it - the linker would be able to properly strip away the component and the handler. Note that the name of the method is TryAddHandler() - so it can check if a handler was already registered for this type and not overwrite it.

Public API Changes

We have to analyze possibilities to allow this.

Intended Use-Case

MauiApp.Current.TryAddHandler(Component1, Component1Handler)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-generalGeneral issues that span multiple controls, or common base classes such as View or ElementpartnerIssue or Request from a partner teamproposal/opent/enhancement ☀️New feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions