1
0
mirror of https://github.com/bitwarden/server synced 2026-01-20 01:13:18 +00:00

Inject playId services in tests and don't fail if it's not found

This commit is contained in:
Matt Gibson
2025-11-17 12:53:36 -08:00
parent d9134d2a60
commit 14044ff5fb
2 changed files with 25 additions and 2 deletions

View File

@@ -14,16 +14,31 @@ public class PlayIdService(IHostEnvironment hostEnvironment) : IPlayIdService
}
}
public class NeverPlayIdServices : IPlayIdService
{
public string? PlayId
{
get => null;
set { }
}
public bool InPlay(out string playId)
{
playId = string.Empty;
return false;
}
}
public class PlayIdSingletonService(IHttpContextAccessor httpContextAccessor, IHostEnvironment hostEnvironment) : IPlayIdService
{
private PlayIdService Current
private IPlayIdService Current
{
get
{
var httpContext = httpContextAccessor.HttpContext;
if (httpContext == null)
{
throw new InvalidOperationException("HttpContext is not available");
return new NeverPlayIdServices();
}
return httpContext.RequestServices.GetRequiredService<PlayIdService>();
}