Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Lecti/Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ public async Task ProcessAsync(RequestContext context, ServiceContext stk)
var assignedTarget = await stk.DataRepositories.Context.Set<Target>().FindAsync(Guid.Parse(availableVariations[variation]));
context.Target = assignedTarget ?? throw new KeyNotFoundException("Assigned target not found in the database.");

// Capture values before queuing deferred task to avoid accessing disposed HTTP context
var ipAddress = context.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
var targetId = context.Target.Id.ToString();
var pluginNamespace = stk.Identity.OriginManifest.Name;

// Store the assigned variation in the scoped store
async Task Task(CancellationToken cancellationToken, Repositories dataRepos)
{
var data = new PluginData
{
Key = context.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(),
Value = context.Target.Id.ToString(),
Namespace = stk.Identity.OriginManifest.Name,
Key = ipAddress,
Value = targetId,
Namespace = pluginNamespace,
};
await dataRepos.Context.Set<PluginData>().AddAsync(data, cancellationToken);
await dataRepos.Context.SaveChangesAsync(cancellationToken);
Expand Down