using Bit.Core.Abstractions; using System; using System.Threading.Tasks; namespace Bit.Core.Services { public class AppIdService { private readonly IStorageService _storageService; public AppIdService(IStorageService storageService) { _storageService = storageService; } public Task GetAppIdAsync() { return MakeAndGetAppIdAsync("appId"); } public Task GetAnonymousAppIdAsync() { return MakeAndGetAppIdAsync("anonymousAppId"); } private async Task MakeAndGetAppIdAsync(string key) { var existingId = await _storageService.GetAsync(key); if(existingId != null) { return existingId; } var guid = Guid.NewGuid().ToString(); await _storageService.SaveAsync(key, guid); return guid; } } }