---
title: CookieService
summary: API reference for CookieService.
status: draft
owner: SAIF IT Core Services
last_reviewed: 2026-10-12
library: BolMiddleware
reference_type: package
---

# CookieService

Implementation of `ICookieService` that writes and reads cookies through the current `HttpContext`. It sets the HttpOnly flag but not Secure or SameSite, and computes expiry from the server's local time.

## Purpose
- Persist cookies with a timeout ([BR-BOLMIDDLEWARE-004](../../business-rules.md#br-bolmiddleware-004-context-cookie-lifetime-and-flags)).

## Context
- Namespace: `BolMiddleware.Services.CookieService`
- Assembly/package: `BolMiddleware`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Constructor | `CookieService(IHttpContextAccessor accessor)` | Receives the accessor used to reach the response and request cookies. |
| `SetCookie` | `void SetCookie(string name, string value, int timeout)` | Appends the cookie with expiry of local `DateTime.Now` plus the timeout. |
| `SetCookieObject<T>` | `void SetCookieObject<T>(string name, T value, int timeout)` | Serializes the object to JSON and sets it. |
| `GetCookie` | `string? GetCookie(string name)` | Returns the request cookie value. |
| `GetCookieObject<T>` | `T? GetCookieObject<T>(string name)` | Deserializes the request cookie. |
| `DoesCookieExist` | `bool DoesCookieExist(string name)` | Checks the request cookies. |
| `DeleteCookie` | `void DeleteCookie(string name)` | Deletes the cookie from the response. |

## Behavioral notes
- No Secure or SameSite attribute is set; see [Security and authorization](../../security-authorization.md).

## Constraints and usage notes
- Requires an active `HttpContext`.

## Sources
- src/BolMiddleware/Services/CookieService/CookieService.cs
