Browse Source

增加飘逸雪花

master
Nice 2 years ago
parent
commit
85c04592da
  1. 20
      Easy.Snowflakes/Easy.Snowflakes.csproj
  2. 16
      Easy.Snowflakes/Easy/Extensions/ServiceCollectionServiceExtensions.cs
  3. 24
      Easy.Snowflakes/Easy/Realization/DriftingSnowflakeIdGenerator.cs
  4. 5
      Easy.Snowflakes/Easy/Snowflakes/ISnowflakeIdGenerator.cs
  5. 7
      Easy.sln
  6. 2
      src/Easy.Uow/Easy.UnitOfWork.csproj
  7. 3
      src/Easy.Uow/Easy/Extensions/ServiceCollectionServiceExtensions.cs

20
Easy.Snowflakes/Easy.Snowflakes.csproj

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.0</Version>
<RootNamespace />
<!--<Nullable>enable</Nullable>-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Yitter.IdGenerator" Version="1.0.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Easy.DI\Easy.DI.csproj" />
</ItemGroup>
</Project>

16
Easy.Snowflakes/Easy/Extensions/ServiceCollectionServiceExtensions.cs

@ -0,0 +1,16 @@
using Easy.Snowflakes;
using Microsoft.Extensions.DependencyInjection;
namespace Easy.Extensions;
public static class ServiceCollectionServiceExtensions
{
public static IServiceCollection AddDriftingSnowflakes(this IServiceCollection services, ushort workId)
{
services.AddSingleton(typeof(ISnowflakeIdGenerator), o =>
{
return new DriftingSnowflakeIdGenerator(workId);
});
return services;
}
}

24
Easy.Snowflakes/Easy/Realization/DriftingSnowflakeIdGenerator.cs

@ -0,0 +1,24 @@
using Yitter.IdGenerator;
namespace Easy.Snowflakes;
public class DriftingSnowflakeIdGenerator : ISnowflakeIdGenerator
{
private readonly IIdGenerator Generator;
public DriftingSnowflakeIdGenerator(ushort workerId)
{
Generator = new DefaultIdGenerator(new IdGeneratorOptions()
{
WorkerId = workerId,
BaseTime = DateTime.Parse("2022-01-01 00:00:00")
});
}
/// <summary>
/// 生成新的Id
/// </summary>
/// <returns></returns>
public long Create()
{
return Generator.NewLong();
}
}

5
Easy.Snowflakes/Easy/Snowflakes/ISnowflakeIdGenerator.cs

@ -0,0 +1,5 @@
namespace Easy.Snowflakes;
public interface ISnowflakeIdGenerator
{
long Create();
}

7
Easy.sln

@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthorityManagementCenter",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.DDD.Application", "src\Easy.DDD.Application\Easy.DDD.Application.csproj", "{8D281035-BB53-4377-9386-0CB664A5C6B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Easy.Snowflakes", "Easy.Snowflakes\Easy.Snowflakes.csproj", "{9D31086B-1333-4745-AEC2-7966141E503C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -105,6 +107,10 @@ Global
{8D281035-BB53-4377-9386-0CB664A5C6B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D281035-BB53-4377-9386-0CB664A5C6B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D281035-BB53-4377-9386-0CB664A5C6B3}.Release|Any CPU.Build.0 = Release|Any CPU
{9D31086B-1333-4745-AEC2-7966141E503C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D31086B-1333-4745-AEC2-7966141E503C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D31086B-1333-4745-AEC2-7966141E503C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D31086B-1333-4745-AEC2-7966141E503C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -128,6 +134,7 @@ Global
{3509F9B3-6B41-4E99-B8DE-2A3E3753AFF3} = {3CD21B92-C376-437C-AE85-7D1669AC1A37}
{CEE286C3-D107-497B-8D4A-1F1199A40A10} = {F59B534D-D72A-462B-B8B9-CD3A11B21C49}
{8D281035-BB53-4377-9386-0CB664A5C6B3} = {A263D7E3-0153-48D0-822D-E3E0B51A4890}
{9D31086B-1333-4745-AEC2-7966141E503C} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7260112B-0232-4725-AB84-EF4DCCABFD77}

2
src/Easy.Uow/Easy.UnitOfWork.csproj

@ -6,7 +6,7 @@
<!--<Nullable>enable</Nullable>-->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RootNamespace />
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>
<ItemGroup>

3
src/Easy.Uow/Easy/Extensions/ServiceCollectionServiceExtensions.cs

@ -8,8 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace Easy.Extensions;
public static class ServiceCollectionServiceExtensions
{
public static IServiceCollection AddUnitOfWork<TDbContext>(this IServiceCollection services, Type unitOfWork)
where TDbContext : DbContext
public static IServiceCollection AddUnitOfWork(this IServiceCollection services, Type unitOfWork)
{
services.AddScoped(typeof(IUnitOfWork), unitOfWork);
services.Configure<MvcOptions>(options =>

Loading…
Cancel
Save