diff --git a/packages/Ignis.Components.Server/ServerHostContext.cs b/packages/Ignis.Components.Server/ServerHostContext.cs index be96309e..732967f0 100644 --- a/packages/Ignis.Components.Server/ServerHostContext.cs +++ b/packages/Ignis.Components.Server/ServerHostContext.cs @@ -1,16 +1,18 @@ -using Microsoft.AspNetCore.Http; +using Ignis.Components.Extensions; +using Microsoft.AspNetCore.Http; namespace Ignis.Components.Server; -internal class ServerHostContext : IHostContext +internal class ServerHostContext : HostContextBase { private readonly IHttpContextAccessor _httpContextAccessor; - public bool IsPrerendering => !_httpContextAccessor.HttpContext?.Response.HasStarted ?? false; + public override bool IsPrerendering => !_httpContextAccessor.HttpContext?.Response.HasStarted ?? false; - public bool IsServerSide => true; + public override bool IsServerSide => true; - public ServerHostContext(IHttpContextAccessor httpContextAccessor) + public ServerHostContext(IEnumerable componentExtensions, + IHttpContextAccessor httpContextAccessor) : base(componentExtensions) { _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); } diff --git a/packages/Ignis.Components.WebAssembly/WebAssemblyHostContext.cs b/packages/Ignis.Components.WebAssembly/WebAssemblyHostContext.cs index f904468d..45a38d6e 100644 --- a/packages/Ignis.Components.WebAssembly/WebAssemblyHostContext.cs +++ b/packages/Ignis.Components.WebAssembly/WebAssemblyHostContext.cs @@ -1,8 +1,14 @@ -namespace Ignis.Components.WebAssembly; +using Ignis.Components.Extensions; -internal class WebAssemblyHostContext : IHostContext +namespace Ignis.Components.WebAssembly; + +internal class WebAssemblyHostContext : HostContextBase { - public bool IsPrerendering => false; + public override bool IsPrerendering => false; + + public override bool IsServerSide => false; - public bool IsServerSide => false; + public WebAssemblyHostContext(IEnumerable componentExtensions) : base(componentExtensions) + { + } } diff --git a/packages/Ignis.Components/HostContextBase.cs b/packages/Ignis.Components/HostContextBase.cs new file mode 100644 index 00000000..12545370 --- /dev/null +++ b/packages/Ignis.Components/HostContextBase.cs @@ -0,0 +1,27 @@ +using Ignis.Components.Extensions; + +namespace Ignis.Components; + +public abstract class HostContextBase : IHostContext +{ + public abstract bool IsPrerendering { get; } + + public abstract bool IsServerSide { get; } + + public IEnumerable ComponentExtensions { get; } + + protected HostContextBase(IEnumerable componentExtensions) + { + ComponentExtensions = componentExtensions ?? throw new ArgumentNullException(nameof(componentExtensions)); + } + + public void OnComponentUpdate(IgnisComponentBase component) + { + if (component == null) throw new ArgumentNullException(nameof(component)); + + foreach (var extension in ComponentExtensions) + { + extension.OnUpdate(component); + } + } +} diff --git a/packages/Ignis.Components/Ignis.Components.csproj b/packages/Ignis.Components/Ignis.Components.csproj index d21ac4a0..58f06c15 100644 --- a/packages/Ignis.Components/Ignis.Components.csproj +++ b/packages/Ignis.Components/Ignis.Components.csproj @@ -33,7 +33,7 @@ - + diff --git a/tests/Ignis.Tests.Common/TestHostContext.cs b/tests/Ignis.Tests.Common/TestHostContext.cs index 94b5dcd4..c4e9d57b 100644 --- a/tests/Ignis.Tests.Common/TestHostContext.cs +++ b/tests/Ignis.Tests.Common/TestHostContext.cs @@ -1,10 +1,15 @@ using Ignis.Components; +using Ignis.Components.Extensions; namespace Ignis.Tests.Common; -internal class TestHostContext : IHostContext +internal class TestHostContext : HostContextBase { - public bool IsPrerendering => false; + public override bool IsPrerendering => false; - public bool IsServerSide => true; + public override bool IsServerSide => true; + + public TestHostContext(IEnumerable componentExtensions) : base(componentExtensions) + { + } }