{"id":18327671,"url":"https://github.com/dario-l/compositekeygen","last_synced_at":"2025-08-29T13:16:19.599Z","repository":{"id":73986297,"uuid":"226133471","full_name":"dario-l/CompositeKeyGen","owner":"dario-l","description":"Allows to create composite key encoded as Int64 (long).","archived":false,"fork":false,"pushed_at":"2022-11-09T09:30:10.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-19T06:39:45.549Z","etag":null,"topics":["asp-net-core","composite","generator","identifier","multitenancy","multitenant","netcore","snowflake","snowflake-net-core"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dario-l.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-05T15:32:58.000Z","updated_at":"2024-09-11T19:33:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcd1e4ba-2fd5-444f-aac7-1e1889d3f38a","html_url":"https://github.com/dario-l/CompositeKeyGen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dario-l/CompositeKeyGen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FCompositeKeyGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FCompositeKeyGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FCompositeKeyGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FCompositeKeyGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dario-l","download_url":"https://codeload.github.com/dario-l/CompositeKeyGen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FCompositeKeyGen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272690607,"owners_count":24977011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","composite","generator","identifier","multitenancy","multitenant","netcore","snowflake","snowflake-net-core"],"created_at":"2024-11-05T19:11:57.409Z","updated_at":"2025-08-29T13:16:19.581Z","avatar_url":"https://github.com/dario-l.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CompositeKeyGen\n![CompositeKeyGen](https://img.shields.io/nuget/v/CompositeKeyGen)\n\nAllows to create composite key encoded as Int64 (long).\n\n*Usually you should use these identifiers in domain objects (aggregates).*\n\nEach key is composed from 3 elements:\n- instanceId - could be server identifier\n- tenantId - could be tenant identifier\n- sequenceId - incrementing identifier from other source\n\n## Configuration\nThis should be done once at application startup:\n``` c#\n// Define configuration\nvar config = new MaskConfig(instanceBits: 5, tenantBits: 14);\n\n// Create key generator\nvar serverId = _application.Configuration.GetServerId(); // this is your code :)\nvar generator = new KeyGenerator(serverId, config);\n```\n\nConfiguration defined above will give you the following maximum values:\n```\n   Max InstanceId:     31\n   Max TenantId:       16383\n   Max SequenceId:     17592186044415\n```\n\nFor given configuration max sequenceId will be 8192 times bigger than int.MaxValue.\n\n## Usage\n\nWhen you need to create key:\n``` c#\n// Create key providing tenantId and sequenceId\nvar sequenceId = _hiloGenerator.GetNext(); // this is your code :)\nvar id = generator.Create(tenantId, sequenceId);\n```\n*Instead of HiLo you can use [LinearKeyAllocator](https://github.com/dario-l/LinearKeyAllocator).*\n\nOutput for example data:\n```\n    For:\n        instanceId = 1;\n        tenantId = 10;\n        sequenceId = 100;\n\n    Created id will be:\n        long id = 288406298012156004\n```\n\nWhen you need to verify key for given tenantId you can reconstruct provided identifier:\n``` c#\nCompositeKey reconstructed = generator.Reconstruct(id);\nif (reconstructed.TenantId != _userContext.TenantId) throw...\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-l%2Fcompositekeygen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdario-l%2Fcompositekeygen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-l%2Fcompositekeygen/lists"}