diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/CookieService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/CookieService.cs new file mode 100644 index 0000000000..3d90d68ccd --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/CookieService.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + [Dependency(ReplaceServices = true)] + public class CookieService : ICookieService, ITransientDependency + { + public IJSRuntime JsRuntime { get; } + + public CookieService(IJSRuntime jsRuntime) + { + JsRuntime = jsRuntime; + } + + public async ValueTask SetAsync(string key, string value, DateTimeOffset? expireDate = null, string path = null) + { + await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, expireDate?.ToString("r"), path); + } + + public async ValueTask GetAsync(string key) + { + return await JsRuntime.InvokeAsync("abp.utils.getCookieValue", key); + } + + public async ValueTask DeleteAsync(string key, string path = null) + { + await JsRuntime.InvokeVoidAsync("abp.utils.deleteCookie", key); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ICookieService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ICookieService.cs new file mode 100644 index 0000000000..63eebb6a5e --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ICookieService.cs @@ -0,0 +1,12 @@ +using System; +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + public interface ICookieService + { + public ValueTask SetAsync(string key, string value, DateTimeOffset? expireDate = null, string path = null); + public ValueTask GetAsync(string key); + public ValueTask DeleteAsync(string key, string path = null); + } +} \ No newline at end of file