public static IServiceCollection AddIdGen(this IServiceCollection services, IConfiguration configuration) { IdGenSettings settings = new IdGenSettings(); configuration.Bind(settings); IdGenDistributedId.Initialize(settings); return(services); }
public static IServiceCollection AddIdGen(this IServiceCollection services, Action <IdGenSettings> action) { IdGenSettings settings = new IdGenSettings(); action(settings); IdGenDistributedId.Initialize(settings); return(services); }
public async Task Test1Async() { IdGenDistributedId.Initialize(new Microsoft.Extensions.DependencyInjection.IdGenSettings { MachineId = 0 }); ConcurrentDictionary<long, int> dict = new ConcurrentDictionary<long, int>(); List<Task> tasks = new List<Task>(); for (int i = 0; i < 100; ++i) { tasks.Add(GenerateIdAsync(dict)); } await Task.WhenAll(tasks).ConfigureAwait(false); var ordered = dict.OrderBy(kv => kv.Key); }