Skip to content

Services IPropertyStore

Mika Berglund edited this page Dec 25, 2025 · 2 revisions

Property Store (IPropertyStore)

The Property Store is a small abstraction for storing and retrieving keyed values used by Blazorade ID. It provides a consistent contract regardless of whether values are stored in memory or in browser-backed storage.

Unlike token stores, the Property Store is intended for general-purpose state and configuration data that the library needs to persist and retrieve by key. Callers decide what keys to use and how to interpret the stored values.

Responsibilities

  • Determine whether a value exists for a given key.
  • Retrieve values by key and deserialize them to a requested type.
  • Store values by key.
  • Remove one or more values by key.

Members

  • ContainsKeyAsync: Determines whether an item with the given key exists in the storage.
  • GetPropertyAsync<T>: Returns a property for the given key if it exists. If the property does not exist, returns the default value of the requested type.
  • RemovePropertyAsync: Removes the property with the given key from the storage.
  • SetPropertyAsync<T>: Stores a property in the storage.

Behavioral notes

The store does not distinguish between "missing" and "present but set to the default value" when using GetPropertyAsync<T>. If you need to know whether a key exists, call ContainsKeyAsync first.

Because values are retrieved as T, callers should use a stable type for a given key. Changing the stored type for a key can cause invalid casts or deserialization failures in some store implementations.

The contract does not define any bulk operations. Removing multiple properties requires calling RemovePropertyAsync repeatedly, and callers should not assume any transactional behavior across calls.

Implementations

  • In-memory store.

    • Stores values in a process-local dictionary.
    • Values are lost when the application is restarted.
    • Suitable when persistence across browser sessions is not required.
  • Browser local storage store.

    • Stores values in the browser's local storage.
    • Values typically persist across browser sessions until explicitly removed.
  • Browser session storage store.

    • Stores values in the browser's session storage.
    • Values typically persist for the lifetime of the current browser tab or session.

Usage guidance

Prefer the in-memory store when you only need state for the current running instance and do not want browser persistence.

Prefer browser local storage when you want values to be available across multiple user sessions in the same browser.

Prefer browser session storage when you want values to be isolated to the current browser session.

When removing multiple properties, use RemovePropertiesAsync to keep the calling code concise. Note that some implementations may remove keys one-by-one internally, so the operation may not be materially different from calling RemovePropertyAsync in a loop.

References

Clone this wiki locally