Skip to content

Hierarchical IDs? #82

@mikechristiansenvae

Description

@mikechristiansenvae

In one of my applications, I have a set of hierarchical IDs.

Take, for example, if I wanted to have a way to uniquely identify an aisle in a store. Without StronglyTypedId, I might do this:

public readonly record struct StoreId(int Id)
{
    public string ToString() => Id.ToString();
}
public readonly record struct SectionId(StoreId Store, int Id)
{
    public int StoreId => Store.Id;
    public string ToString() => $"{StoreId}/{Id}";
}
public readonly record struct AisleId(SectionId Section, int Id)
{
    public int SectionId => Section.Id;
    public int StoreId => Section.StoreId;
    public string ToString() => $"{StoreId}/{SectionId}/{Id}";
}

Each level of the hierarchy provides a different context. A SectionId with an integer value of 1, in StoreId 1 is not the same as a SectionId with an integer value of 1, in StoreId 2

It would be nice if I could do something similar with StronglyTypedId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions