mirror of
https://github.com/bitwarden/server
synced 2025-12-31 23:53:17 +00:00
Use a header to track seeded data. This has benefits client side in simplicity and allows us to track entities added during a test, as long as they include the play id header.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
@@ -11,3 +13,38 @@ public class PlayIdService(IHostEnvironment hostEnvironment) : IPlayIdService
|
||||
return !string.IsNullOrEmpty(PlayId) && hostEnvironment.IsDevelopment();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayIdSingletonService(IHttpContextAccessor httpContextAccessor, IHostEnvironment hostEnvironment) : IPlayIdService
|
||||
{
|
||||
private PlayIdService Current
|
||||
{
|
||||
get
|
||||
{
|
||||
var httpContext = httpContextAccessor.HttpContext;
|
||||
if (httpContext == null)
|
||||
{
|
||||
throw new InvalidOperationException("HttpContext is not available");
|
||||
}
|
||||
return httpContext.RequestServices.GetRequiredService<PlayIdService>();
|
||||
}
|
||||
}
|
||||
|
||||
public string? PlayId
|
||||
{
|
||||
get => Current.PlayId;
|
||||
set => Current.PlayId = value;
|
||||
}
|
||||
|
||||
public bool InPlay(out string playId)
|
||||
{
|
||||
if (hostEnvironment.IsDevelopment())
|
||||
{
|
||||
return Current.InPlay(out playId);
|
||||
}
|
||||
else
|
||||
{
|
||||
playId = string.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user