コード例 #1
0
        public static IServiceCollection AddDqlite(this IServiceCollection services, IDqliteNodeStore store, Action <DqliteOptions> configureOptions = null)
        {
            store = store ?? throw new ArgumentNullException(nameof(store));

            var options = new DqliteOptions()
            {
                Id      = 1,
                DataDir = Path.Combine(Path.GetTempPath(), "dqlite")
            };

            configureOptions?.Invoke(options);

            if (options.Id == 0)
            {
                throw new ArgumentOutOfRangeException("Id");
            }

            if (string.IsNullOrEmpty(options?.Address))
            {
                throw new ArgumentNullException("Address");
            }

            if (string.IsNullOrEmpty(options?.DataDir))
            {
                throw new ArgumentNullException("DataDir");
            }

            if (options.Id != 1 && store.Get().Any(x => x != options.Address))
            {
                throw new ArgumentException($"{nameof(store)} only contains address for current node");
            }

            services.AddSingleton <IDqliteNodeStore>(store);
            services.AddHostedService <DqliteNodeService>(x => new DqliteNodeService(x.GetServices <IDqliteService>(), store, options));
            return(services);
        }
コード例 #2
0
 public DqliteNodeService(IEnumerable <IDqliteService> services, IDqliteNodeStore store, DqliteOptions options)
 {
     this.services = services;
     this.store    = store;
     this.options  = options;
 }