mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00
adjust service lifetimes
This commit is contained in:
parent
bd46349e27
commit
8d37f1c946
@ -25,23 +25,23 @@ namespace Bit.Core
|
|||||||
{
|
{
|
||||||
services.AddSingleton<ICipherService, CipherService>();
|
services.AddSingleton<ICipherService, CipherService>();
|
||||||
services.AddScoped<IUserService, UserService>();
|
services.AddScoped<IUserService, UserService>();
|
||||||
services.AddScoped<IDeviceService, DeviceService>();
|
services.AddSingleton<IDeviceService, DeviceService>();
|
||||||
services.AddScoped<IOrganizationService, OrganizationService>();
|
services.AddSingleton<IOrganizationService, OrganizationService>();
|
||||||
services.AddScoped<ICollectionService, CollectionService>();
|
services.AddSingleton<ICollectionService, CollectionService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddDefaultServices(this IServiceCollection services)
|
public static void AddDefaultServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IMailService, SendGridMailService>();
|
services.AddSingleton<IMailService, SendGridMailService>();
|
||||||
services.AddScoped<IPushService, PushSharpPushService>();
|
services.AddSingleton<IPushService, PushSharpPushService>();
|
||||||
services.AddScoped<IBlockIpService, AzureQueueBlockIpService>();
|
services.AddSingleton<IBlockIpService, AzureQueueBlockIpService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddNoopServices(this IServiceCollection services)
|
public static void AddNoopServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IMailService, NoopMailService>();
|
services.AddSingleton<IMailService, NoopMailService>();
|
||||||
services.AddScoped<IPushService, NoopPushService>();
|
services.AddSingleton<IPushService, NoopPushService>();
|
||||||
services.AddScoped<IBlockIpService, NoopBlockIpService>();
|
services.AddSingleton<IBlockIpService, NoopBlockIpService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ using Newtonsoft.Json;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -21,20 +22,20 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
private readonly IDeviceRepository _deviceRepository;
|
private readonly IDeviceRepository _deviceRepository;
|
||||||
private readonly ILogger<IPushService> _logger;
|
private readonly ILogger<IPushService> _logger;
|
||||||
private readonly CurrentContext _currentContext;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private GcmServiceBroker _gcmBroker;
|
private GcmServiceBroker _gcmBroker;
|
||||||
private ApnsServiceBroker _apnsBroker;
|
private ApnsServiceBroker _apnsBroker;
|
||||||
|
|
||||||
public PushSharpPushService(
|
public PushSharpPushService(
|
||||||
IDeviceRepository deviceRepository,
|
IDeviceRepository deviceRepository,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<IPushService> logger,
|
ILogger<IPushService> logger,
|
||||||
CurrentContext currentContext,
|
|
||||||
IHostingEnvironment hostingEnvironment,
|
IHostingEnvironment hostingEnvironment,
|
||||||
GlobalSettings globalSettings)
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_deviceRepository = deviceRepository;
|
_deviceRepository = deviceRepository;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_currentContext = currentContext;
|
|
||||||
|
|
||||||
InitGcmBroker(globalSettings);
|
InitGcmBroker(globalSettings);
|
||||||
InitApnsBroker(globalSettings, hostingEnvironment);
|
InitApnsBroker(globalSettings, hostingEnvironment);
|
||||||
@ -96,9 +97,11 @@ namespace Bit.Core.Services
|
|||||||
};
|
};
|
||||||
|
|
||||||
var excludedTokens = new List<string>();
|
var excludedTokens = new List<string>();
|
||||||
if(!string.IsNullOrWhiteSpace(_currentContext.DeviceIdentifier))
|
var currentContext = _httpContextAccessor?.HttpContext?.
|
||||||
|
RequestServices.GetService(typeof(CurrentContext)) as CurrentContext;
|
||||||
|
if(!string.IsNullOrWhiteSpace(currentContext?.DeviceIdentifier))
|
||||||
{
|
{
|
||||||
excludedTokens.Add(_currentContext.DeviceIdentifier);
|
excludedTokens.Add(currentContext.DeviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
await PushToAllUserDevicesAsync(cipher.UserId.Value, JObject.FromObject(message), excludedTokens);
|
await PushToAllUserDevicesAsync(cipher.UserId.Value, JObject.FromObject(message), excludedTokens);
|
||||||
@ -116,9 +119,11 @@ namespace Bit.Core.Services
|
|||||||
};
|
};
|
||||||
|
|
||||||
var excludedTokens = new List<string>();
|
var excludedTokens = new List<string>();
|
||||||
if(!string.IsNullOrWhiteSpace(_currentContext.DeviceIdentifier))
|
var currentContext = _httpContextAccessor?.HttpContext?.
|
||||||
|
RequestServices.GetService(typeof(CurrentContext)) as CurrentContext;
|
||||||
|
if(!string.IsNullOrWhiteSpace(currentContext?.DeviceIdentifier))
|
||||||
{
|
{
|
||||||
excludedTokens.Add(_currentContext.DeviceIdentifier);
|
excludedTokens.Add(currentContext.DeviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
await PushToAllUserDevicesAsync(folder.UserId, JObject.FromObject(message), excludedTokens);
|
await PushToAllUserDevicesAsync(folder.UserId, JObject.FromObject(message), excludedTokens);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user