Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(IdGenerator): Add IdGenerator.SimpleGuid and IdGenerator.SequentialGuid and IdGenerator.Snowflake #76

Merged
merged 34 commits into from
Jun 7, 2022
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d7e04df
feat(IIdGenerator): Added support for snowflake id
zhenlei520 May 23, 2022
374be7a
feat(Snowflake): support snowflake id
zhenlei520 May 23, 2022
e8b71eb
feat(IdGenerator): Snowflake id supports distributed
zhenlei520 May 24, 2022
9e9ad25
refactor(IdGenerator): Optimize WorkerId
zhenlei520 May 24, 2022
e35079f
chore: Delete the IdGenerator.Yitter class library
zhenlei520 May 25, 2022
50fdad4
Merge branch 'feature/IdGenerator' of https://github.com/masastack/MA…
zhenlei520 May 25, 2022
288c5bf
feat(IdGenerator): Modify Distributed IdGenerator
zhenlei520 May 25, 2022
003adc5
docs: Modify the IdGenerator document
zhenlei520 May 25, 2022
a6ea17b
feat(IdGenerator): Timestamp supports seconds
zhenlei520 May 25, 2022
2951a5c
feat(IdGenerator): Add IdGenerator BenchmarkDotnet
zhenlei520 May 25, 2022
6b2fdf3
chore: remove invalid constructor
zhenlei520 May 25, 2022
36a2e37
chore: Adjust namespace order
zhenlei520 May 25, 2022
6b4b0b5
chore: update branch
zhenlei520 May 26, 2022
71f9cae
Merge branch 'main' of https://github.com/masastack/MASA.Contrib into…
zhenlei520 May 26, 2022
ac347b9
Merge branch 'main' of https://github.com/masastack/MASA.Contrib into…
zhenlei520 May 31, 2022
a49a642
feat(Mapping.Mapster): Extend object to support mapping
zhenlei520 May 31, 2022
31105ea
feat(IIdGenerator): Added IIdGenerator<long> service registration
zhenlei520 Jun 1, 2022
2a02e3a
docs(IdGenerator): Modify Snowflake document
zhenlei520 Jun 1, 2022
d6ca712
Merge branch 'main' of https://github.com/masastack/MASA.Contrib into…
zhenlei520 Jun 1, 2022
89d74dc
chore: MapperConfiguartionExtensions rename to MapperExtensions
zhenlei520 Jun 1, 2022
2e2f907
Refactors(IdGenerator): Refactor SnowflakeId
zhenlei520 Jun 2, 2022
1c4326d
feat(IdGenerator): Add SimpleGuidGenerator and SequentialGuidGenerator
zhenlei520 Jun 2, 2022
23278a1
chore: Modify IdGenerator
zhenlei520 Jun 2, 2022
9cd6472
docs(IdGenerator): Modify IdGenerator Document
zhenlei520 Jun 6, 2022
d90eb18
docs(IdGenerator): Modify IdGenerator Document
zhenlei520 Jun 6, 2022
bfc06a7
test(IdGenerator): Remove unit tests using redis
zhenlei520 Jun 6, 2022
d52797f
test(Mapping): Modify Mapping UnitTest
zhenlei520 Jun 6, 2022
5da5e56
chore(IdGenerator): Adjust parameter names, documentation, etc.
zhenlei520 Jun 6, 2022
ab4da40
chore: remove source
zhenlei520 Jun 6, 2022
1021804
docs(IdGenerator): Add Benchmark data
zhenlei520 Jun 6, 2022
66167ec
Update README.zh-CN.md
zhenlei520 Jun 6, 2022
66a6e09
chore: Modify SequentialGuidGenerator and handle warnings
zhenlei520 Jun 7, 2022
e961fda
chore: Add TimestampType
zhenlei520 Jun 7, 2022
faf8741
chore: Handling warnings
zhenlei520 Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Masa.Contrib.sln
Original file line number Diff line number Diff line change
@@ -211,10 +211,30 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.BuildingBlocks.Service
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.BuildingBlocks.BasicAbility.Auth", "src\BuildingBlocks\MASA.BuildingBlocks\src\BasicAbility\Masa.BuildingBlocks.BasicAbility.Auth\Masa.BuildingBlocks.BasicAbility.Auth.csproj", "{4B818EE6-8E13-40DA-B99A-218BB228EE91}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IdGenerator", "IdGenerator", "{6DB8780E-BA11-47CD-8FAB-D73A1F71B305}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.BasicAbility.Auth", "src\BasicAbility\Masa.Contrib.BasicAbility.Auth\Masa.Contrib.BasicAbility.Auth.csproj", "{CE1CABB0-B307-4709-84E0-583382FAAA29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake", "src\Data\IdGenerator\Masa.Contrib.Data.IdGenerator.Snowflake\Masa.Contrib.Data.IdGenerator.Snowflake.csproj", "{E7987CBB-8DDD-4AC5-B522-653E2F457C85}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Tests", "test\Masa.Contrib.Data.IdGenerator.Snowflake.Tests\Masa.Contrib.Data.IdGenerator.Snowflake.Tests.csproj", "{AD427256-9686-4289-A635-1B387BD56D15}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.BasicAbility.Auth.Tests", "test\Masa.Contrib.BasicAbility.Auth.Tests\Masa.Contrib.BasicAbility.Auth.Tests.csproj", "{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis", "src\Data\IdGenerator\Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis\Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.csproj", "{DC50078D-D706-4CB9-A301-F47CB3F46007}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IdGenerator", "IdGenerator", "{E6363F59-2BA4-4AA7-8578-C433A2C2567F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests", "test\Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests\Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests.csproj", "{D8E85337-A779-48FC-B822-CE8A850661DC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.BuildingBlocks.Data.MappingExtensions", "src\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data.MappingExtensions\Masa.BuildingBlocks.Data.MappingExtensions.csproj", "{30DC35DF-9D86-443C-B26C-9053E6FCA434}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.NormalGuid", "src\Data\IdGenerator\Masa.Contrib.Data.IdGenerator.NormalGuid\Masa.Contrib.Data.IdGenerator.NormalGuid.csproj", "{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.SequentialGuid", "src\Data\IdGenerator\Masa.Contrib.Data.IdGenerator.SequentialGuid\Masa.Contrib.Data.IdGenerator.SequentialGuid.csproj", "{B15F4561-E511-42EA-A02E-F772BAF41E20}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Data.IdGenerator.SequentialGuid.Tests", "test\Masa.Contrib.Data.IdGenerator.SequentialGuid.Tests\Masa.Contrib.Data.IdGenerator.SequentialGuid.Tests.csproj", "{32488758-25C9-4257-9B98-DAA034C19909}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -871,6 +891,22 @@ Global
{CE1CABB0-B307-4709-84E0-583382FAAA29}.Release|Any CPU.Build.0 = Release|Any CPU
{CE1CABB0-B307-4709-84E0-583382FAAA29}.Release|x64.ActiveCfg = Release|Any CPU
{CE1CABB0-B307-4709-84E0-583382FAAA29}.Release|x64.Build.0 = Release|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Debug|x64.Build.0 = Debug|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Release|Any CPU.Build.0 = Release|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Release|x64.ActiveCfg = Release|Any CPU
{E7987CBB-8DDD-4AC5-B522-653E2F457C85}.Release|x64.Build.0 = Release|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Debug|x64.ActiveCfg = Debug|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Debug|x64.Build.0 = Debug|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Release|Any CPU.Build.0 = Release|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Release|x64.ActiveCfg = Release|Any CPU
{AD427256-9686-4289-A635-1B387BD56D15}.Release|x64.Build.0 = Release|Any CPU
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -879,6 +915,54 @@ Global
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Release|Any CPU.Build.0 = Release|Any CPU
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Release|x64.ActiveCfg = Release|Any CPU
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3}.Release|x64.Build.0 = Release|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Debug|x64.ActiveCfg = Debug|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Debug|x64.Build.0 = Debug|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Release|Any CPU.Build.0 = Release|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Release|x64.ActiveCfg = Release|Any CPU
{DC50078D-D706-4CB9-A301-F47CB3F46007}.Release|x64.Build.0 = Release|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Debug|x64.ActiveCfg = Debug|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Debug|x64.Build.0 = Debug|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Release|Any CPU.Build.0 = Release|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Release|x64.ActiveCfg = Release|Any CPU
{D8E85337-A779-48FC-B822-CE8A850661DC}.Release|x64.Build.0 = Release|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Debug|x64.ActiveCfg = Debug|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Debug|x64.Build.0 = Debug|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Release|Any CPU.Build.0 = Release|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Release|x64.ActiveCfg = Release|Any CPU
{30DC35DF-9D86-443C-B26C-9053E6FCA434}.Release|x64.Build.0 = Release|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Debug|x64.ActiveCfg = Debug|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Debug|x64.Build.0 = Debug|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Release|Any CPU.Build.0 = Release|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Release|x64.ActiveCfg = Release|Any CPU
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}.Release|x64.Build.0 = Release|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Debug|x64.ActiveCfg = Debug|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Debug|x64.Build.0 = Debug|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Release|Any CPU.Build.0 = Release|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Release|x64.ActiveCfg = Release|Any CPU
{B15F4561-E511-42EA-A02E-F772BAF41E20}.Release|x64.Build.0 = Release|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Debug|x64.ActiveCfg = Debug|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Debug|x64.Build.0 = Debug|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Release|Any CPU.Build.0 = Release|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Release|x64.ActiveCfg = Release|Any CPU
{32488758-25C9-4257-9B98-DAA034C19909}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -984,8 +1068,18 @@ Global
{EB0F6BDA-C6AA-4859-834E-5613BB38862B} = {5DFAF4A2-ECB5-46E4-904D-1EA5F48B2D48}
{736F69E9-89D0-47E2-99AF-9412AAE1C6BB} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}
{4B818EE6-8E13-40DA-B99A-218BB228EE91} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}
{6DB8780E-BA11-47CD-8FAB-D73A1F71B305} = {E33ADF54-4D35-49B7-BDA6-412587CA39FF}
{CE1CABB0-B307-4709-84E0-583382FAAA29} = {5DFAF4A2-ECB5-46E4-904D-1EA5F48B2D48}
{E7987CBB-8DDD-4AC5-B522-653E2F457C85} = {6DB8780E-BA11-47CD-8FAB-D73A1F71B305}
{AD427256-9686-4289-A635-1B387BD56D15} = {E6363F59-2BA4-4AA7-8578-C433A2C2567F}
{2B644A8C-F0EE-4566-AB78-9E1C6D4185A3} = {38E6C400-90C0-493E-9266-C1602E229F1B}
{DC50078D-D706-4CB9-A301-F47CB3F46007} = {6DB8780E-BA11-47CD-8FAB-D73A1F71B305}
{E6363F59-2BA4-4AA7-8578-C433A2C2567F} = {38E6C400-90C0-493E-9266-C1602E229F1B}
{D8E85337-A779-48FC-B822-CE8A850661DC} = {E6363F59-2BA4-4AA7-8578-C433A2C2567F}
{30DC35DF-9D86-443C-B26C-9053E6FCA434} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}
{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F} = {6DB8780E-BA11-47CD-8FAB-D73A1F71B305}
{B15F4561-E511-42EA-A02E-F772BAF41E20} = {6DB8780E-BA11-47CD-8FAB-D73A1F71B305}
{32488758-25C9-4257-9B98-DAA034C19909} = {E6363F59-2BA4-4AA7-8578-C433A2C2567F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}
2 changes: 1 addition & 1 deletion src/BuildingBlocks/MASA.BuildingBlocks
Submodule MASA.BuildingBlocks updated 25 files
+7 −0 Masa.BuildingBlocks.sln
+22 −0 src/Data/Masa.BuildingBlocks.Data.Mapping/Mapper.cs
+5 −1 src/Data/Masa.BuildingBlocks.Data.Mapping/Masa.BuildingBlocks.Data.Mapping.csproj
+1 −0 src/Data/Masa.BuildingBlocks.Data.Mapping/_Imports.cs
+13 −0 src/Data/Masa.BuildingBlocks.Data.MappingExtensions/Masa.BuildingBlocks.Data.MappingExtensions.csproj
+19 −0 src/Data/Masa.BuildingBlocks.Data.MappingExtensions/ObjectExtensions.cs
+5 −0 src/Data/Masa.BuildingBlocks.Data.MappingExtensions/_Imports.cs
+26 −0 src/Data/Masa.BuildingBlocks.Data/Enum/SequentialGuidType.cs
+10 −0 src/Data/Masa.BuildingBlocks.Data/Enum/TimestampType.cs
+8 −0 src/Data/Masa.BuildingBlocks.Data/IdGenerator/IGuidGenerator.cs
+11 −0 src/Data/Masa.BuildingBlocks.Data/IdGenerator/IIdGenerator.cs
+9 −0 src/Data/Masa.BuildingBlocks.Data/IdGenerator/ISequentialGuidGenerator.cs
+8 −0 src/Data/Masa.BuildingBlocks.Data/IdGenerator/ISnowflakeGenerator.cs
+36 −0 src/Data/Masa.BuildingBlocks.Data/IdGenerator/IdGeneratorFactory.cs
+10 −6 src/Data/Masa.BuildingBlocks.Data/Masa.BuildingBlocks.Data.csproj
+0 −0 src/Data/Masa.BuildingBlocks.Data/Options/MasaDbConnectionOptions.cs
+9 −0 src/Data/Masa.BuildingBlocks.Data/System/SequentialGuid.cs
+9 −0 src/Data/Masa.BuildingBlocks.Data/System/Snowflake.cs
+1 −0 src/Data/Masa.BuildingBlocks.Data/_Imports.cs
+9 −1 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/AggregateRoot.cs
+9 −1 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/Auditing/AuditAggregateRoot.cs
+9 −1 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/Auditing/AuditEntity.cs
+7 −1 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/Entity.cs
+8 −0 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/Full/FullAggregateRoot.cs
+8 −0 src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Entities/Full/FullEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftPackageVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Data.IdGenerator.NormalGuid;

public class NormalGuidGenerator : IGuidGenerator
{
public Guid Create() => Guid.NewGuid();
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Medium | [EN](README.md)

## Masa.Contrib.Data.IdGenerator.SimpleGuid

Masa.Contrib.Data.IdGenerator.SimpleGuid is a simple guid constructor that provides a unique identifier of type Guid

## Example:

1. Install `Masa.Contrib.Data.IdGenerator.SimpleGuid`

````c#
Install-Package Masa.Contrib.Data.IdGenerator.SimpleGuid
````

2. Use `Masa.Contrib.Data.IdGenerator.SimpleGuid`

```` C#
builder.Services.AddSimpleGuidGenerator();
````

3. Get Id

````
IGuidGenerator generator;// Get it through DI, or get it through IdGeneratorFactory.GuidGenerator
generator.Create();//Create a unique id
````
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
中 | [EN](README.md)

## Masa.Contrib.Data.IdGenerator.NormalGuid

Masa.Contrib.Data.IdGenerator.NormalGuid是一个简单的Guid构造器,提供Guid类型的唯一标识

## 用例:

1. 安装`Masa.Contrib.Data.IdGenerator.NormalGuid`

```c#
Install-Package Masa.Contrib.Data.IdGenerator.NormalGuid
```

2. 使用`Masa.Contrib.Data.IdGenerator.NormalGuid`

``` C#
builder.Services.AddSimpleGuidGenerator();
```

3. 获取Id

```
IGuidGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.GuidGenerator获取
generator.Create();//创建唯一id
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Data.IdGenerator.NormalGuid;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddSimpleGuidGenerator(this IServiceCollection services)
{
services.TryAddSingleton<IGuidGenerator, NormalGuidGenerator>();
services.TryAddSingleton<IIdGenerator<Guid, Guid>, IGuidGenerator>();
IdGeneratorFactory.SetGuidGenerator(services.BuildServiceProvider().GetRequiredService<IGuidGenerator>());
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

global using Masa.BuildingBlocks.Data;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftPackageVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Medium | [EN](README.md)

## Masa.Contrib.Data.IdGenerator.SequentialGuid

Masa.Contrib.Data.IdGenerator.SequentialGuid is an ordered Guid constructor that provides a unique identifier of the Guid type

## Example:

1. Install `Masa.Contrib.Data.IdGenerator.SequentialGuid`

````c#
Install-Package Masa.Contrib.Data.IdGenerator.SequentialGuid
````

2. Use `Masa.Contrib.Data.IdGenerator.SequentialGuid`

```` C#
builder.Services.AddSequentialGuidGenerator();
````

3. Get Id

````
ISequentialGuidGenerator generator;// Obtained through DI, or obtained through IdGeneratorFactory.SequentialGuidGenerator
generator.Create();//Create a unique id
````
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
中 | [EN](README.md)

## Masa.Contrib.Data.IdGenerator.SequentialGuid

Masa.Contrib.Data.IdGenerator.SequentialGuid是一个有序的Guid构造器,提供Guid类型的唯一标识

## 用例:

1. 安装`Masa.Contrib.Data.IdGenerator.SequentialGuid`

```c#
Install-Package Masa.Contrib.Data.IdGenerator.SequentialGuid
```

2. 使用`Masa.Contrib.Data.IdGenerator.SequentialGuid`

``` C#
builder.Services.AddSequentialGuidGenerator();
```

3. 获取Id

```
ISequentialGuidGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.SequentialGuidGenerator获取
generator.Create();//创建唯一id
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.Data.IdGenerator.SequentialGuid;

public class SequentialGuidGenerator : ISequentialGuidGenerator
{
private static readonly RandomNumberGenerator RandomGenerator = RandomNumberGenerator.Create();

private readonly SequentialGuidType _guidType;

public SequentialGuidGenerator(SequentialGuidType guidType) => _guidType = guidType;

public Guid Create() => Create(_guidType);

public Guid Create(SequentialGuidType guidType)
{
byte[] randomBytes = GetRandomBytes();
byte[] timestampBytes = GetTimestampBytes();
byte[] guidBytes = GetGuidBytes(guidType, timestampBytes, randomBytes);
return new Guid(guidBytes);
}

private byte[] GetTimestampBytes()
{
long timestamp = DateTime.UtcNow.Ticks / 10000L;
byte[] timestampBytes = BitConverter.GetBytes(timestamp);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(timestampBytes);
}
return timestampBytes;
}

private byte[] GetRandomBytes()
{
byte[] randomBytes = new byte[10];
RandomGenerator.GetBytes(randomBytes);
return randomBytes;
}

private byte[] GetGuidBytes(SequentialGuidType sequentialGuidType, byte[] timestampBytes, byte[] randomBytes)
{
byte[] guidBytes = new byte[16];
switch (sequentialGuidType)
{
case SequentialGuidType.SequentialAtEnd:

Buffer.BlockCopy(randomBytes, 0, guidBytes, 0, 10);
Buffer.BlockCopy(timestampBytes, 2, guidBytes, 10, 6);
break;

case SequentialGuidType.SequentialAsString:
case SequentialGuidType.SequentialAsBinary:

Buffer.BlockCopy(timestampBytes, 2, guidBytes, 0, 6);
Buffer.BlockCopy(randomBytes, 0, guidBytes, 6, 10);

if (sequentialGuidType == SequentialGuidType.SequentialAsString && BitConverter.IsLittleEndian)
{
Array.Reverse(guidBytes, 0, 4);
Array.Reverse(guidBytes, 4, 2);
}
break;

default:
throw new NotSupportedException($"unsupported {sequentialGuidType}");
}
return guidBytes;
}
}
Loading