• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API
v16
Search Results for

    Show / Hide Table of Contents

    Interface IKeyService

    WIP 16.04

    Namespace: ToSic.Sxc.Services
    Assembly: ToSic.Sxc.dll
    Syntax
    [InternalApi_DoNotUse_MayChangeWithoutNotice("Still WIP in v16.04")]
    public interface IKeyService

    Properties

    | Improve this Doc View Source

    UniqueKey

    A unique, random key for the current module. It's recommended for giving DOM elements a unique id for scripts to then access them.

    It's generated for every content-block, and more reliable than Module.Id since that sometimes results in duplicate keys, if the many blocks are used inside each other.

    It's generated using a GUID and converted/shortened. In the current version it's 8 characters long, so it has 10^14 combinations, making collisions extremely unlikely. (currently 8 characters)

    Tip

    To get a unique key which is based on additional objects such as Entities, use the UniqueKeyWith(params object[]) method.

    Declaration
    string UniqueKey { get; }
    Property Value
    Type Description
    string
    Remarks

    If you get a fresh IKeyService it will also create a new UniqueKey. So your code should usually use the built in property UniqueKey which comes from teh shared ServiceKit Key.

    Methods

    | Improve this Doc View Source

    UniqueKeyWith(params object[])

    Generate a unique key based on the UniqueKey and additional objects.

    It has a special mechanisms for creating unique keys for specific data types such as entities, so calling this multiple times with the same objects will still result in the same key being generated.

    Special behaviors:

    • Strings will use the HashCode
    • Entities and similar will use a shortened unique string based on the GUID
    • Assets (files, folders) will use the HashCode of their Url
    • Dates are converted to a safe string and trimmed for all trailing zeros
    • Most key parts will receive a simple prefix making debugging easier
    Declaration
    string UniqueKeyWith(params object[] partners)
    Parameters
    Type Name Description
    object[] partners
    Returns
    Type Description
    string
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX