public static IDataLoader <TKey, TValue[]> GroupDataLoader <TKey, TValue>(
            this IResolverContext context,
            FetchGroup <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 <FetchGroupedDataLoader <TKey, TValue> > createDataLoader =
                () => new FetchGroupedDataLoader <TKey, TValue>(
                    services.GetRequiredService <IBatchScheduler>(),
                    fetch);

            return(key is null
                ? reg.GetOrRegister(createDataLoader)
                : reg.GetOrRegister(key, createDataLoader));
        }
 public FetchGroupedDataLoader(
     IBatchScheduler batchScheduler,
     FetchGroup <TKey, TValue> fetch)
     : base(batchScheduler)
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }
Esempio n. 3
0
        public void CheckFetchGroupInitializationWithExpressions()
        {
            FetchGroup <Mitarbeiter> fg = new FetchGroup <Mitarbeiter>(m => m.Vorname, m => m.Nachname);

            Assert.AreEqual(fg.Count, 2, "Count should be 2");
            Assert.AreEqual("Vorname", fg[0], "Name wrong #1");
            Assert.AreEqual("Nachname", fg[1], "Name wrong #2");
        }
 public FetchGroupedDataLoader(FetchGroup <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[]> GroupDataLoader <TKey, TValue>(
            this IResolverContext context,
            string key,
            FetchGroup <TKey, TValue> fetch)
            where TKey : notnull
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          nameof(key));
            }

            return(GroupDataLoader(context, fetch, key));
        }
Esempio n. 6
0
        public static bool Register <TKey, TValue>(
            this IDataLoaderRegistry registry,
            string key,
            FetchGroup <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 FetchGroupedDataLoader <TKey, TValue>(fetch)));
        }
Esempio n. 7
0
        GroupDataLoader <TKey, TValue>(
            this IResolverContext context,
            string key,
            FetchGroup <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(GroupDataLoaderFactory(context, key, services => fetch));
        }
Esempio n. 8
0
 public FetchGroupedDataLoader(FetchGroup <TKey, TValue> fetch)
 {
     _fetch = fetch ?? throw new ArgumentNullException(nameof(fetch));
 }