public static IDataLoader <TKey, TValue> BatchDataLoader <TKey, TValue>(
            this IResolverContext context,
            FetchBatch <TKey, TValue> fetch,
            string?key = null)
            where TKey : notnull
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (fetch is null)
            {
                throw new ArgumentNullException(nameof(fetch));
            }

            IServiceProvider    services = context.Services;
            IDataLoaderRegistry reg      = services.GetRequiredService <IDataLoaderRegistry>();
            Func <FetchBatchDataLoader <TKey, TValue> > createDataLoader =
                () => new FetchBatchDataLoader <TKey, TValue>(
                    services.GetRequiredService <IBatchScheduler>(),
                    fetch);

            return(key is null
                ? reg.GetOrRegister(createDataLoader)
                : reg.GetOrRegister(key, createDataLoader));
        }
 public FetchBatchDataLoader(
     IBatchScheduler batchScheduler,
     FetchBatch <TKey, TValue> fetch)
     : base(batchScheduler)
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }
Esempio n. 3
0
 public FetchDataLoader(FetchBatch <TKey, TValue> fetch)
     : base(new DataLoaderOptions <TKey>
 {
     AutoDispatching   = false,
     Batching          = true,
     CacheSize         = DataLoaderDefaults.CacheSize,
     MaxBatchSize      = DataLoaderDefaults.MaxBatchSize,
     SlidingExpiration = TimeSpan.Zero
 })
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }
        public static IDataLoader <TKey, TValue> BatchDataLoader <TKey, TValue>(
            this IResolverContext context,
            string key,
            FetchBatch <TKey, TValue> fetch)
            where TKey : notnull
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          nameof(key));
            }

            return(BatchDataLoader(context, fetch, key));
        }
Esempio n. 5
0
        public static bool Register <TKey, TValue>(
            this IDataLoaderRegistry registry,
            string key,
            FetchBatch <TKey, TValue> fetch)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          nameof(key));
            }

            if (fetch == null)
            {
                throw new ArgumentNullException(nameof(fetch));
            }

            return(registry.Register(key, services =>
                                     new FetchDataLoader <TKey, TValue>(fetch)));
        }
Esempio n. 6
0
        public static IDataLoader <TKey, TValue> BatchDataLoader <TKey, TValue>(
            this IResolverContext context,
            string key,
            FetchBatch <TKey, TValue> fetch)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          nameof(key));
            }

            if (fetch == null)
            {
                throw new ArgumentNullException(nameof(fetch));
            }

            return(BatchDataLoaderFactory(context, key, services => fetch));
        }
Esempio n. 7
0
 public FetchBatchDataLoader(FetchBatch <TKey, TValue> fetch)
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }
Esempio n. 8
0
 public FetchDataLoader(FetchBatch <TKey, TValue> fetch, DataLoaderOptions <TKey> options)
     : base(options)
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }