zoukankan      html  css  js  c++  java
  • StowayNet.Extensions.Snowflake发布

    StowayNet.Extensions.Snowflake

    StowayNet.Extensions.Snowflake是针对雪花算法开发的.net core框架扩展组件。

    入门

    NuGet

    你可以运行以下命令在你的项目中安装 StowayNet.Extensions.Snowflake.

    PM> Install-Package StowayNet.Extensions.Snowflake
    

    配置

    首先配置 StowayNet.Extensions.SnowflakeStartup.cs 文件中,如下:

    ......
    using StowayNet;
    ......
    
    public void ConfigureServices(IServiceCollection services)
    {
        ......
    
        services.AddStowayNet();
    
        ......
    }
    
    

    你也可以通过配置选项 StowayNet.Extensions.Snowflake.SnowflakeIdOptions 来修改默认配置:

    public void ConfigureServices(IServiceCollection services)
    {
        ......
        services.AddStowayNet();
        services.Configure<StowayNet.Extensions.Snowflake.SnowflakeIdOptions>(options =>
        {
            options.ServerId = serverId;
        });
        ......
    }
    

    示例

        using StowayNet.Extensions.Snowflake;
        
        class TestSample
        {
            private readonly ILogger<TestSample> _logger;
            private readonly ISnowflakeIdWorker _idWorker;
    
            public TestSample(ILogger<TestSample> logger, ISnowflakeIdWorker idWorker)
            {
                _logger = logger;
                _idWorker = idWorker;
            }
    
            public void Execute()
            {
                _logger.LogDebug($"newid:{_idWorker.NewId()}");
    
            }
        }
    
  • 相关阅读:
    如何使用 systemctl 管理服务
    Linux 下 SVN 的安装和配置
    C语言程序设计
    mysql 常用关键字操作(字符串转数字,字符串截取)
    Spring入门学习---05
    Spring入门学习---03
    使用 TiUP 部署 TiDB 集群
    docker安装kafka+kafka-manager集群
    发发牢骚
    php修改JPG格式图片的dpi
  • 原文地址:https://www.cnblogs.com/stoway/p/13446707.html
Copyright © 2011-2022 走看看