Esempio n. 1
0
        /// <summary>
        /// 添加唯一Id生成器
        /// </summary>
        /// <param name="hostBuilder"></param>
        /// <param name="setup"></param>
        /// <returns></returns>
        public static IFlashHostBuilder AddUniqueIdGenerator(this IFlashHostBuilder hostBuilder, Action <IdGeneratorOption> setup)
        {
            var option = new IdGeneratorOption();

            setup(option);

            hostBuilder.Services.AddSingleton <IUniqueIdGenerator>(sp =>
            {
                var workId = option.WorkIdCreateStrategy.NextId();
                return(new SnowflakeUniqueIdGenerator(workId, option.CenterId));
            });
            return(hostBuilder);
        }
Esempio n. 2
0
 /// <summary>
 /// 使用静态机器标识
 /// </summary>
 /// <param name="option"></param>
 /// <param name="WorkId"></param>
 public static void UseStaticWorkIdCreateStrategy(this IdGeneratorOption option, int WorkId)
 {
     option.WorkIdCreateStrategy = new StaticWorkIdCreateStrategy(WorkId);
 }
Esempio n. 3
0
 public static void UseSqlServerWorkIdCreateStrategy(this IdGeneratorOption option, string ConnectionString, string WorkTag)
 {
     option.WorkIdCreateStrategy = new SqlServerWorkIdCreateStrategy(ConnectionString, WorkTag);
 }
Esempio n. 4
0
 public static void UseHostNameWorkIdCreateStrategy(this IdGeneratorOption option)
 {
     option.WorkIdCreateStrategy = new HostNameWorkIdCreateStrategy();
 }