logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class StructuredBackendStores

    Shared construction of IStructuredStore instances from the shared backend assets, used by every consumer factory (structured logging, leaderboard). Each consumer keeps its own dispatch switch, fallback target and final wrap; everything that was byte-identical between the factories — the environment-variable override chain, the shared System.Net.Http.HttpClient, the per-backend Try-construction with its SERENITY_STRUCTURED_* guards, and the custom-backend contract — lives here once, parameterized by a StructuredBackendConsumerProfile.

    Inheritance
    object
    StructuredBackendStores
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.StructuredPersistence.Backends
    Assembly: Serenity.UnityStructuredPersistence.Backends.dll
    Syntax
    public static class StructuredBackendStores
    Remarks

    Every Try* method preserves the consumer factories' never-throw contract: a missing configuration, a missing scripting define, or a construction failure logs a warning (worded through the profile so each consumer's messages stay exactly as before) and returns null, letting the caller fall back to its own default backend.

    Fields

    ApiKeyEnvironmentVariableSuffix

    Environment-variable suffix overriding an Http backend's API key ({PREFIX}_API_KEY).

    Declaration
    public const string ApiKeyEnvironmentVariableSuffix = "API_KEY"
    Field Value
    Type Description
    string

    BaseUrlEnvironmentVariableSuffix

    Environment-variable suffix overriding an Http backend's base URL ({PREFIX}_BASE_URL).

    Declaration
    public const string BaseUrlEnvironmentVariableSuffix = "BASE_URL"
    Field Value
    Type Description
    string

    ConnectionStringEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's full connection string ({PREFIX}_CONNECTION_STRING).

    Declaration
    public const string ConnectionStringEnvironmentVariableSuffix = "CONNECTION_STRING"
    Field Value
    Type Description
    string

    DatabaseEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's database name ({PREFIX}_DATABASE).

    Declaration
    public const string DatabaseEnvironmentVariableSuffix = "DATABASE"
    Field Value
    Type Description
    string

    HostEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's host ({PREFIX}_HOST).

    Declaration
    public const string HostEnvironmentVariableSuffix = "HOST"
    Field Value
    Type Description
    string

    PasswordEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's password ({PREFIX}_PASSWORD).

    Declaration
    public const string PasswordEnvironmentVariableSuffix = "PASSWORD"
    Field Value
    Type Description
    string

    PlayerPrefsKeyPrefix

    Key prefix shared by every Serenity PlayerPrefs key-value store.

    Declaration
    public const string PlayerPrefsKeyPrefix = "Serenity_"
    Field Value
    Type Description
    string

    PortEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's port ({PREFIX}_PORT).

    Declaration
    public const string PortEnvironmentVariableSuffix = "PORT"
    Field Value
    Type Description
    string

    UsernameEnvironmentVariableSuffix

    Environment-variable suffix overriding a database backend's username ({PREFIX}_USERNAME).

    Declaration
    public const string UsernameEnvironmentVariableSuffix = "USERNAME"
    Field Value
    Type Description
    string

    Methods

    CreatePlayerPrefsStore(StructuredBackendConsumerProfile, ILogService)

    Builds the consumer's PlayerPrefs key-value store — the never-fail local backend: a KeyValueStructuredStore over UnityPlayerPrefsKeyValueStore, partitioned by the profile's partition field and encoded with the profile's PlayerPrefs serializer.

    Declaration
    public static IStructuredStore CreatePlayerPrefsStore(StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    ResolveEnvironmentOverride(string, string, string)

    Resolves a credential/config value, preferring the environment variable {prefix}_{suffix} over serializedValue when prefix is set and that environment variable is present. This lets a project keep production secrets (e.g. the API key) out of the serialized asset.

    Declaration
    public static string ResolveEnvironmentOverride(string prefix, string suffix, string serializedValue)
    Parameters
    Type Name Description
    string prefix
    string suffix
    string serializedValue
    Returns
    Type Description
    string

    ResolveEnvironmentOverrideInt(string, string, int)

    Integer counterpart of ResolveEnvironmentOverride(string, string, string), falling back to serializedValue when the environment variable is absent or is not a valid integer.

    Declaration
    public static int ResolveEnvironmentOverrideInt(string prefix, string suffix, int serializedValue)
    Parameters
    Type Name Description
    string prefix
    string suffix
    int serializedValue
    Returns
    Type Description
    int

    TryCreateCustomStore(ICustomStructuredBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Attempts to build a project-defined custom backend. Honors the CreateStore(ILogService) contract: a throw or a null return means "backend unavailable" — both are logged as a warning and return null, so the caller falls back to its default backend. This never throws.

    Declaration
    public static IStructuredStore TryCreateCustomStore(ICustomStructuredBackendDefinition customBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    ICustomStructuredBackendDefinition customBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreateHttpStore(UnityHttpBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Attempts to build the Http backend from httpBackend. Returns null (after logging a warning) when no base URL is configured, so the caller falls back to its default backend — this never throws. Every Http store shares one System.Net.Http.HttpClient whose own timeout is disabled, keeping the store's per-call linked token the sole timeout authority.

    Declaration
    public static IStructuredStore TryCreateHttpStore(UnityHttpBackendDefinition httpBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnityHttpBackendDefinition httpBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreateLocalFileStore(UnityLocalFileBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Builds the LocalFile backend: a FileKeyValueStore over a real FileStore rooted at a subdirectory of UnityEngine.Application.persistentDataPath, persisting each partition through the profile's LocalFile serializer (human-readable JSON for both current consumers) so a partition file can be opened and inspected by hand. A null asset or blank DirectoryName uses the profile's default directory. Never throws — any construction failure is logged as a warning and returns null; the warning always names the PlayerPrefs backend because it is the only backend that cannot itself fail to construct, so every consumer's terminal fallback lands there.

    Declaration
    public static IStructuredStore TryCreateLocalFileStore(UnityLocalFileBackendDefinition localFileBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnityLocalFileBackendDefinition localFileBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreateMongoStore(UnityMongoBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Attempts to build the Mongo backend from mongoBackend. Returns null (after logging a warning) when the SERENITY_STRUCTURED_MONGO scripting define is not set or construction fails, so the caller falls back to its default backend — this never throws.

    Declaration
    public static IStructuredStore TryCreateMongoStore(UnityMongoBackendDefinition mongoBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnityMongoBackendDefinition mongoBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreateMySqlStore(UnityMySqlBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Attempts to build the MySql backend from mySqlBackend. Returns null (after logging a warning) when the SERENITY_STRUCTURED_MYSQL scripting define is not set or construction fails, so the caller falls back to its default backend — this never throws.

    Declaration
    public static IStructuredStore TryCreateMySqlStore(UnityMySqlBackendDefinition mySqlBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnityMySqlBackendDefinition mySqlBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreatePostgresStore(UnityPostgresBackendDefinition, StructuredBackendConsumerProfile, ILogService)

    Attempts to build the Postgres backend from postgresBackend. Returns null (after logging a warning) when the SERENITY_STRUCTURED_POSTGRES scripting define is not set or construction fails, so the caller falls back to its default backend — this never throws.

    Declaration
    public static IStructuredStore TryCreatePostgresStore(UnityPostgresBackendDefinition postgresBackend, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnityPostgresBackendDefinition postgresBackend
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore

    TryCreateSqliteStore(UnitySqliteBackendDefinition, StoreTable, StructuredBackendConsumerProfile, ILogService)

    Attempts to build the Sqlite backend from sqliteBackend. Returns null (after logging a warning) when the SERENITY_STRUCTURED_SQLITE scripting define is not set or construction fails, so the caller falls back to its default backend — this never throws. Resolves the database file path under UnityEngine.Application.persistentDataPath (a blank DatabaseFileName uses the profile's default file name); the shared asset carries no timeout knob, so the driver default applies. When the profile declares a SqliteSchemaFactory, the store is wrapped in an EnsureSchemaOnFirstUseStructuredStore that creates the consumer's schema automatically before the first operation — the SQLite file lives on the player's device where no administrator exists to provision it. A null factory hands back the raw store.

    Declaration
    public static IStructuredStore TryCreateSqliteStore(UnitySqliteBackendDefinition sqliteBackend, StoreTable table, StructuredBackendConsumerProfile profile, ILogService logService)
    Parameters
    Type Name Description
    UnitySqliteBackendDefinition sqliteBackend
    StoreTable table
    StructuredBackendConsumerProfile profile
    ILogService logService
    Returns
    Type Description
    IStructuredStore
    In this article
    © 2026 Serenity. All Rights Reserved