-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b73d0f
commit 46ed986
Showing
8 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@using Microsoft.Extensions.Logging | ||
|
||
@inject ILogger<Foo> logger; | ||
|
||
<strong>Hello from Foo!</strong> | ||
|
||
@code { | ||
protected override void OnInitialized() | ||
{ | ||
logger.LogInformation("Initialized FOO"); | ||
base.OnInitialized(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace Piral.Blazor.Core; | ||
|
||
public interface ICacheManipulatorService | ||
{ | ||
void UpdateComponentCache(Type componentType, IServiceProvider provider); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Piral.Blazor.Core; | ||
|
||
internal class PiletComponentActivator(IModuleContainerService container, ICacheManipulatorService cacheManipulator) : IComponentActivator | ||
{ | ||
private readonly IModuleContainerService _container = container; | ||
private readonly ICacheManipulatorService _cacheManipulator = cacheManipulator; | ||
private readonly HashSet<Type> _seen = []; | ||
|
||
public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType) | ||
{ | ||
if (!typeof(IComponent).IsAssignableFrom(componentType)) | ||
{ | ||
throw new ArgumentException($"The type {componentType.FullName} does not implement {nameof(IComponent)}.", nameof(componentType)); | ||
} | ||
|
||
if (_seen.Add(componentType)) | ||
{ | ||
var origin = componentType.Assembly; | ||
var provider = _container.GetProvider(origin); | ||
|
||
// local DI has been found - use it | ||
if (provider is not null) | ||
{ | ||
_cacheManipulator.UpdateComponentCache(componentType, provider); | ||
} | ||
} | ||
|
||
return (IComponent)Activator.CreateInstance(componentType)!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.