remove type collection from context

This commit is contained in:
2026-04-13 12:42:11 +02:00
parent 5d63ca70c8
commit 7a34c642ce
+11 -57
View File
@@ -1,42 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Finch.Context;
public class FinchContext : IFinchContext
public class FinchContext(
IFinchOptions options,
ICultureResolver cultureResolver,
IServiceProvider services)
: IFinchContext
{
/// <inheritdoc />
public IFinchOptions Options { get; protected set; }
public IFinchOptions Options { get; } = options;
/// <inheritdoc />
public IServiceProvider Services { get; }
protected ICultureResolver CultureResolver { get; }
protected ILogger<FinchContext> Logger { get; private set; }
protected IHandlerHolder Handler { get; private set; }
protected IHttpContextAccessor HttpContextAccessor { get; private set; }
protected IPrimitiveTypeCollection ValueCollection { get; }
public IServiceProvider Services { get; } = services;
bool _resolved = false;
public FinchContext(IFinchOptions options, IHttpContextAccessor httpContextAccessor, ICultureResolver cultureResolver,
ILogger<FinchContext> logger, IHandlerHolder handler, IServiceProvider services)
{
Options = options;
CultureResolver = cultureResolver;
Logger = logger;
Handler = handler;
ValueCollection = new PrimitiveTypeCollection();
HttpContextAccessor = httpContextAccessor;
Services = services;
}
/// <inheritdoc />
public virtual async Task Resolve(HttpContext context)
{
@@ -45,23 +26,11 @@ public class FinchContext : IFinchContext
return;
}
_resolved = true;
// set current culture
await CultureResolver.Resolve(this);
await cultureResolver.Resolve(this);
_resolved = true;
}
/// <inheritdoc />
public T Get<T>() => ValueCollection.Get<T>();
/// <inheritdoc />
public void Set<T>(T value) => ValueCollection.Set(value);
/// <inheritdoc />
public void Remove<T>() => ValueCollection.Remove<T>();
}
@@ -83,19 +52,4 @@ public interface IFinchContext
/// the currently active backoffice user, as users are not signed in with the default scheme and do therefore not populate HttpContext.User
/// </summary>
Task Resolve(HttpContext context);
/// <summary>
/// Get a custom property from this scoped context
/// </summary>
T Get<T>();
/// <summary>
/// Add a custom property to this scoped context
/// </summary>
void Set<T>(T value);
/// <summary>
/// Remove a custom property from this scoped context
/// </summary>
void Remove<T>();
}