PrismLibrary / PrismLibrary/Prism
[Enhancement] Allow `UsePrism` to be called multiple times
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.8k
- Forks
- 1.6k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 1
Description
Summary
As requested by @aritchie, there may be times in which you want to write extensions for the MauiAppBuilder to bring in features and those features would benefit from modifying the PrismAppBuilder as the example below shows adding a module.
public static MauiAppBuilder AddMapsFeature(this MauiAppBuilder builder)
{
builder.UsePrism(x => x.ConfigureModuleCatalog(modules => modules.AddModule<MapsModule>()));
return builder;
}
This is currently not recommended in Prism 9.0 as each call to UsePrism initializes a new instance of the PrismAppBuilder and can prevent you from successfully getting callbacks such as Navigating when CreateWindow is called or callbacks for OnInitialized.
Proposed API
I believe we want to ensure that the behavior of UsePrism remains intact as this is also important for Unit Testing. To provide the proper behavior we can instead look at introducing something like:
public static class PrismAppBuilderExtensions
{
// Ensure that `UsePrism` is called first
public static MauiAppBuilder ConfigurePrism(this MauiAppBuilder builder, Action<PrismAppBuilder> configure)
{
var prism = ContainerLocator.Container.Resolve<PrismAppBuilder>();
configure(prism);
return builder;
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing UsePrism extension and the PrismAppBuilder initialization and registration path. Review how repeated calls affect callbacks such as Navigating and OnInitialized, while preserving the current behavior used by unit tests. Done means extensions can configure the same PrismAppBuilder across multiple calls without losing those callbacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100