Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a86364

Browse files
authored
Merge pull request#3219 from PrismLibrary/dev/ds/module-fix
Modularity Fix
2 parentse275b7e +ec5e8a6 commit6a86364

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed

‎src/Maui/Prism.Maui/Modularity/ModuleCatalog.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Prism.Modularity;
1010
#else
1111
[ContentProperty(nameof(Items))]
1212
#endif
13-
publicclassModuleCatalog:ModuleCatalogBase
13+
publicclassModuleCatalog(IEnumerable<IModuleInfo>modules):ModuleCatalogBase(modules)
1414
{
1515

1616
}

‎src/Maui/Prism.Maui/PrismAppBuilder.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,21 @@ internal void OnInitialized()
205205
{
206206
try
207207
{
208+
logger.LogDebug("Initializing modules.");
208209
varmanager=_container.Resolve<IModuleManager>();
209210
manager.Run();
211+
logger.LogDebug("Modules Initialized.");
210212
}
211213
catch(Exceptionex)
212214
{
213215
logger.LogError(ex,"An error ocurred while initializing the Modules.");
214216
thrownewPrismInitializationException("An error occurred while initializing the Modules.",ex);
215217
}
216218
}
219+
else
220+
{
221+
logger.LogDebug("No Modules found to initialize.");
222+
}
217223

218224
varnavRegistry=_container.Resolve<INavigationRegistry>();
219225
if(!navRegistry.IsRegistered(nameof(NavigationPage)))

‎src/Maui/Prism.Maui/PrismAppBuilderExtensions.cs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Prism;
1111
/// </summary>
1212
publicstaticclassPrismAppBuilderExtensions
1313
{
14-
privatestaticbools_didRegisterModules=false;
15-
1614
/// <summary>
1715
/// Configures the <see cref="MauiAppBuilder"/> to use Prism with a callback for the <see cref="PrismAppBuilder"/>
1816
/// </summary>
@@ -45,15 +43,13 @@ public static PrismAppBuilder OnInitialized(this PrismAppBuilder builder, Action
4543
/// <param name="configureCatalog">Delegate to configure the <see cref="IModuleCatalog"/>.</param>
4644
publicstaticPrismAppBuilderConfigureModuleCatalog(thisPrismAppBuilderbuilder,Action<IModuleCatalog>configureCatalog)
4745
{
48-
if(!s_didRegisterModules)
46+
builder.RegisterTypes(container=>
4947
{
50-
varservices=builder.MauiBuilder.Services;
51-
services.AddSingleton<IModuleCatalog,ModuleCatalog>();
52-
services.AddSingleton<IModuleManager,ModuleManager>();
53-
services.AddSingleton<IModuleInitializer,ModuleInitializer>();
54-
}
48+
container.TryRegisterSingleton<IModuleCatalog,ModuleCatalog>();
49+
container.TryRegisterSingleton<IModuleManager,ModuleManager>();
50+
container.TryRegisterSingleton<IModuleInitializer,ModuleInitializer>();
51+
});
5552

56-
s_didRegisterModules=true;
5753
returnbuilder.OnInitialized(container=>
5854
{
5955
varmoduleCatalog=container.Resolve<IModuleCatalog>();
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespacePrism.DryIoc.Maui.Tests.Fixtures.Modularity;
2+
3+
publicclassModuleCatalogTests(ITestOutputHelpertestOutputHelper):TestBase(testOutputHelper)
4+
{
5+
publicreadonlyIModuleInfoModuleA=newModuleInfo(typeof(MockModuleA));
6+
publicreadonlyIModuleInfoModuleB=newModuleInfo(typeof(MockModuleB));
7+
8+
[Fact]
9+
publicvoidUsesCustomModuleCatalog()
10+
{
11+
varbuilder=CreateBuilder(prism=>
12+
{
13+
prism.RegisterTypes(c=>c.RegisterSingleton<IModuleCatalog,CustomMoudleCatalog>())
14+
.ConfigureModuleCatalog(catalog=>{});
15+
});
16+
varapp=builder.Build();
17+
18+
varmoduleCatalog=app.Services.GetService<IModuleCatalog>();
19+
Assert.NotNull(moduleCatalog);
20+
Assert.IsType<CustomMoudleCatalog>(moduleCatalog);
21+
}
22+
23+
[Fact]
24+
publicvoidInjectsModulesFromDI()
25+
{
26+
varbuilder=CreateBuilder(prism=>
27+
{
28+
prism.RegisterTypes(c=>c.RegisterInstance<IModuleInfo>(ModuleA))
29+
.ConfigureModuleCatalog(c=>{});
30+
});
31+
varapp=builder.Build();
32+
33+
varmoduleCatalog=app.Services.GetService<IModuleCatalog>();
34+
Assert.Single(moduleCatalog.Modules);
35+
Assert.Equal(ModuleA.ModuleType,moduleCatalog.Modules.Single().ModuleType);
36+
}
37+
38+
[Fact]
39+
publicvoidInjectsModulesFromConfigureDelegate()
40+
{
41+
varbuilder=CreateBuilder(prism=>
42+
prism.ConfigureModuleCatalog(c=>c.AddModule<MockModuleA>()));
43+
varapp=builder.Build();
44+
45+
varmoduleCatalog=app.Services.GetService<IModuleCatalog>();
46+
Assert.Single(moduleCatalog.Modules);
47+
Assert.Equal(ModuleA.ModuleType,moduleCatalog.Modules.Single().ModuleType);
48+
}
49+
50+
[Fact]
51+
publicvoidCombinesModulesFromConfigureMethodAndDI()
52+
{
53+
varbuilder=CreateBuilder(prism=>
54+
{
55+
prism.RegisterTypes(c=>c.RegisterInstance<IModuleInfo>(ModuleA))
56+
.ConfigureModuleCatalog(c=>c.AddModule<MockModuleB>());
57+
});
58+
varapp=builder.Build();
59+
60+
varmoduleCatalog=app.Services.GetService<IModuleCatalog>();
61+
Assert.Equal(2,moduleCatalog.Modules.Count());
62+
Assert.Contains(ModuleA.ModuleType,moduleCatalog.Modules.Select(m=>m.ModuleType));
63+
Assert.Contains(ModuleB.ModuleType,moduleCatalog.Modules.Select(m=>m.ModuleType));
64+
}
65+
66+
publicclassCustomMoudleCatalog:ModuleCatalogBase{}
67+
68+
publicclassMockModuleA:IModule
69+
{
70+
publicvoidOnInitialized(IContainerProvidercontainerProvider)
71+
{
72+
}
73+
74+
publicvoidRegisterTypes(IContainerRegistrycontainerRegistry)
75+
{
76+
}
77+
}
78+
79+
publicclassMockModuleB:IModule
80+
{
81+
publicvoidOnInitialized(IContainerProvidercontainerProvider)
82+
{
83+
}
84+
85+
publicvoidRegisterTypes(IContainerRegistrycontainerRegistry)
86+
{
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp