Skip to content

Instantly share code, notes, and snippets.

View trnktms's full-sized avatar
:octocat:

Tamás Tárnok trnktms

:octocat:
View GitHub Profile
> .\build-iar.ps1 -UnicornItemsRootPath c:\Temp\unicorn-cleanup\Unicorn\ -UnicornConfigsRootPath c:\Temp\unicorn-cleanup\App_Config\Include\ -OutputPath c:\Temp\unicorn-cleanup\
[CmdletBinding()]
param (
[ValidateScript({ Test-Path $_ -PathType Container })]
[string]$UnicornConfigsRootPath,
[ValidateScript({ Test-Path $_ -PathType Container })]
[string]$UnicornItemsRootPath,
[string]$OutputPath
)
Install-Module powershell-yaml -Scope CurrentUser -Force
@trnktms
trnktms / Startup.cs
Last active February 29, 2024 07:54
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
...
// Overwrite the default ApiContentResponseBuilder to resolve partial layouts
services.AddSingleton<IApiContentResponseBuilder, ExtendedApiContentResponseBuilder>();
services.AddSingleton<IComponentResolver, HeaderResolver>();
services.AddSingleton<IComponentResolver, FooterResolver>();
public class ExtendedApiContentResponseBuilder : LayoutBuilderBase<IApiContentResponse>, IApiContentResponseBuilder
{
private readonly IApiContentRouteBuilder _apiContentRouteBuilder;
public ExtendedApiContentResponseBuilder(
IApiContentNameProvider apiContentNameProvider,
IApiContentRouteBuilder apiContentRouteBuilder,
IOutputExpansionStrategyAccessor outputExpansionStrategyAccessor,
IEnumerable<IComponentResolver> componentResolvers,
IApiPublishedContentCache apiPublishedContentCache)
public abstract class LayoutBuilderBase<T> : ApiContentBuilderBase<T> where T : IApiContent
{
private const string LayoutPropertyKey = "layout";
protected readonly IEnumerable<IComponentResolver> ComponentResolvers;
protected readonly IApiPublishedContentCache ApiPublishedContentCache;
protected LayoutBuilderBase(
IApiContentNameProvider apiContentNameProvider,
IApiContentRouteBuilder apiContentRouteBuilder,
public interface IComponentResolver
{
int Order { get; }
IPublishedContent ResolveContent(IPublishedContent content);
}
public class FooterResolver : IComponentResolver
{
public int Order => 100;
private readonly IApiPublishedContentCache _apiPublishedContentCache;
public FooterResolver(IApiPublishedContentCache apiPublishedContentCache)
{
_apiPublishedContentCache = apiPublishedContentCache;
}
public class HeaderResolver : IComponentResolver
{
public int Order => -100;
private readonly IApiPublishedContentCache _apiPublishedContentCache;
public HeaderResolver(IApiPublishedContentCache apiPublishedContentCache)
{
_apiPublishedContentCache = apiPublishedContentCache;
}
public class FallbackDeliveryApiJsonTypeResolver : DeliveryApiJsonTypeResolver
{
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
var typeInfo = base.GetTypeInfo(type, options);
if (typeInfo.PolymorphismOptions != null)
{
typeInfo.PolymorphismOptions.UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType;
}
public class ExtendedApiContentResponse : ApiContentResponse, IApiContentResponse
{
public ExtendedApiContentResponse(
Guid id,
string name,
string contentType,
DateTime createDate,
DateTime updateDate,
IApiContentRoute route,
IDictionary<string, object?> properties,