Skip to content

Commit

Permalink
Improved CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Mar 25, 2024
1 parent 9b73d0f commit 46ed986
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 1 deletion.
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ steps:
displayName: 'Build Assemblies'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))

- script: |
rm ~/.nuget/packages/microsoft.aspnetcore.components/8.0.1/lib/net8.0/Microsoft.AspNetCore.Components.dll
cp tools/Microsoft.AspNetCore.Components.dll ~/.nuget/packages/microsoft.aspnetcore.components/8.0.1/lib/net8.0/Microsoft.AspNetCore.Components.dll
displayName: 'Change GAC'

- script: |
dotnet build tests
dotnet test tests
Expand Down
4 changes: 4 additions & 0 deletions example/standalone/Pilet/Components/CounterPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

<Foo @ref=foo></Foo>

<p>Also a counter with React for comparison:</p>

<Extension Name="react-counter" />

@code {
private Foo foo;

[Parameter]
[PiralQueryParameter]
public string Foo { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions example/standalone/Pilet/Components/Foo.razor
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();
}

}
2 changes: 1 addition & 1 deletion src/Piral.Blazor.Core/CacheManipulatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Piral.Blazor.Core;

internal class CacheManipulatorService
internal class CacheManipulatorService : ICacheManipulatorService
{
private readonly Type _ctiType;
private readonly Func<Type, Action<IServiceProvider, IComponent>> _createInitializer;
Expand Down
8 changes: 8 additions & 0 deletions src/Piral.Blazor.Core/ICacheManipulatorService.cs
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);
}
35 changes: 35 additions & 0 deletions src/Piral.Blazor.Core/PiletComponentActivator.cs
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)!;
}
}
2 changes: 2 additions & 0 deletions src/Piral.Blazor.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static async Task Main(string[] args)

builder.Services
.AddSingleton(new HttpClient { BaseAddress = baseAddress })
.AddSingleton<IComponentActivator, PiletComponentActivator>()
.AddSingleton<ICacheManipulatorService, CacheManipulatorService>()
.AddSingleton<IComponentActivationService, ComponentActivationService>()
.AddSingleton<IModuleContainerService, ModuleContainerService>();

Expand Down
Binary file added tools/Microsoft.AspNetCore.Components.dll
Binary file not shown.

0 comments on commit 46ed986

Please sign in to comment.