diff --git a/docs/en/framework/infrastructure/guid-generation.md b/docs/en/framework/infrastructure/guid-generation.md index 6b3177ae22..fb45b829c8 100644 --- a/docs/en/framework/infrastructure/guid-generation.md +++ b/docs/en/framework/infrastructure/guid-generation.md @@ -24,6 +24,8 @@ So, **never use `Guid.NewGuid()` to create Ids** for your entities! One good solution to this problem is to generate **sequential GUIDs**, which is provided by the ABP out of the box. `IGuidGenerator` service creates sequential GUIDs (implemented by the `SequentialGuidGenerator` by default). Use `IGuidGenerator.Create()` when you need to manually set Id of an [entity](../architecture/domain-driven-design/entities.md). +Additionally, the `IGuidGenerator` interface includes a `Create(SequentialGuidType guidType)` method that allows specifying the type of sequential GUID to generate. See the [AbpSequentialGuidGeneratorOptions](#AbpSequentialGuidGeneratorOptions) section for more information about the `SequentialGuidType`. + **Example: An entity with GUID primary key and creating the entity** Assume that you've a `Product` [entity](../architecture/domain-driven-design/entities.md) that has a `Guid` key: diff --git a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/IGuidGenerator.cs b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/IGuidGenerator.cs index 64ae0f2a83..e3701deea3 100644 --- a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/IGuidGenerator.cs +++ b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/IGuidGenerator.cs @@ -11,4 +11,10 @@ public interface IGuidGenerator /// Creates a new . /// Guid Create(); + + /// + /// Creates a new . + /// + /// Sequential Guid type. + Guid Create(SequentialGuidType guidType); } diff --git a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs index 1ac752d9c3..c0f4939651 100644 --- a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs +++ b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs @@ -15,19 +15,19 @@ public class SequentialGuidGenerator : IGuidGenerator, ITransientDependency { public AbpSequentialGuidGeneratorOptions Options { get; } - private static readonly RandomNumberGenerator RandomNumberGenerator = RandomNumberGenerator.Create(); + private readonly static RandomNumberGenerator RandomNumberGenerator = RandomNumberGenerator.Create(); public SequentialGuidGenerator(IOptions options) { Options = options.Value; } - public Guid Create() + public virtual Guid Create() { return Create(Options.GetDefaultSequentialGuidType()); } - public Guid Create(SequentialGuidType guidType) + public virtual Guid Create(SequentialGuidType guidType) { // We start with 16 bytes of cryptographically strong random data. var randomBytes = new byte[10]; diff --git a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SimpleGuidGenerator.cs b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SimpleGuidGenerator.cs index 612dc41aff..f5868c8a2b 100644 --- a/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SimpleGuidGenerator.cs +++ b/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SimpleGuidGenerator.cs @@ -13,4 +13,9 @@ public class SimpleGuidGenerator : IGuidGenerator { return Guid.NewGuid(); } + + public virtual Guid Create(SequentialGuidType guidType) + { + return Guid.NewGuid(); + } }