Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/componentsBase/InfragisticsBlazorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public static class InfragisticsBlazorExtensions
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddIgniteUIBlazor(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection,
params Type[] modulesToLoad)
{
// Snapshot the caller's array immediately so any later mutation has no effect.
Type[] snapshot = modulesToLoad != null && modulesToLoad.Length > 0 ? [.. modulesToLoad] : [];

var s = collection.AddScoped(
typeof(IIgniteUIBlazorSettings),
(sp) =>
{
var bs = new IgniteUIBlazorSettings();
bs = bs.WithModulesToLoad(modulesToLoad != null && modulesToLoad.Length > 0 ? new ReadOnlyCollection<Type>(modulesToLoad) : null);
bs = bs.WithModulesToLoad(snapshot.Length > 0 ? new ReadOnlyCollection<Type>(snapshot) : null);
return bs;
});

Expand Down
17 changes: 17 additions & 0 deletions tests/IgniteUI.Blazor.Tests/ServiceRegistrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ public void Runtime_InvokesRegisterOnEveryListedModule()
Assert.Same(runtime, Assert.Single(SecondModule.Registrations));
}

/// <summary>
/// Mutating the original array after calling <c>AddIgniteUIBlazor</c> must not change which
/// modules the settings report. The overload snapshots the array at registration time.
/// </summary>
[Fact]
public void AddIgniteUIBlazor_MutatingOriginalArray_DoesNotAffectRegisteredModules()
{
var modules = new Type[] { typeof(FirstModule) };

using var host = new Host(s => s.AddIgniteUIBlazor(modules));

// Mutate after registration, before the first resolve.
modules[0] = typeof(SecondModule);

Assert.Equal([typeof(FirstModule)], SettingsOf(host).ModulesToLoad);
}

[Fact]
public void Runtime_IsScoped_SoEachScopeRegistersItsOwn()
{
Expand Down
Loading