public DataLoaderResolver(Func <TSource, TKey> keySelector, DataLoaderResolverDelegate <TKey, TReturn> resolverDelegate) { _keySelector = keySelector; _captureFieldContext = true; _loaderContext = new DataLoaderContext(); _loader = new DataLoader <TKey, TReturn>(ids => resolverDelegate(ids, _lastContext.Value), _loaderContext); }
public DataLoaderResolver(Func <TSource, TKey> keySelector, FetchDelegate <TKey, TReturn> fetchDelegate) { _keySelector = keySelector; _captureFieldContext = false; _loaderContext = new DataLoaderContext(); _loader = new DataLoader <TKey, TReturn>(fetchDelegate, _loaderContext); }
public static IDataLoader <T> GetOrAddLoader <T>(this DataLoaderContext context, string loaderKey, Func <Task <T> > fetchFunc) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } return(context.GetOrAdd(loaderKey, () => new SimpleDataLoader <T>(WrapNonCancellableFunc(fetchFunc)))); }
public static IDataLoader <TKey, T> GetOrAddBatchLoader <TKey, T>(this DataLoaderContext context, string loaderKey, Func <IEnumerable <TKey>, Task <Dictionary <TKey, T> > > fetchFunc, IEqualityComparer <TKey> keyComparer = null, T defaultValue = default(T)) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } return(context.GetOrAdd(loaderKey, () => new BatchDataLoader <TKey, T>(WrapNonCancellableFunc(fetchFunc), keyComparer, defaultValue))); }
/// <summary> /// Get or add a DataLoader instance for batching paginated data fetching operations. /// </summary> /// <typeparam name="TKey">The type of key used to load data</typeparam> /// <typeparam name="T">The type of data to be loaded</typeparam> /// <param name="context">The <seealso cref="DataLoaderContext"/> to get or add a DataLoader to</param> /// <param name="loaderKey">A unique key to identify the DataLoader instance</param> /// <param name="fetchFunc">A delegate to fetch paginated data for some keys asynchronously</param> /// <param name="keyComparer">An <seealso cref="IEqualityComparer{T}"/> to compare keys.</param> /// <returns>A new or existing DataLoader instance</returns> public static IRelayDataLoader <TKey, T> GetOrAddRelayBatchLoader <TKey, T>(this DataLoaderContext context, string loaderKey, Func <IEnumerable <PageRequest <TKey> >, CancellationToken, Task <IDictionary <TKey, Connection <T> > > > fetchFunc, IEqualityComparer <PageRequest <TKey> > keyComparer = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } return(context.GetOrAdd(loaderKey, () => new RelayBatchDataLoader <TKey, T>(fetchFunc, keyComparer))); }
/// <summary> /// Get or add a DataLoader instance for batching data fetching operations. /// </summary> /// <typeparam name="TKey">The type of key used to load data</typeparam> /// <typeparam name="T">The type of data to be loaded</typeparam> /// <param name="context">The <seealso cref="DataLoaderContext"/> to get or add a DataLoader to</param> /// <param name="loaderKey">A unique key to identify the DataLoader instance</param> /// <param name="fetchFunc">A cancellable delegate to fetch data for some keys asynchronously</param> /// <param name="keyComparer">An <seealso cref="IEqualityComparer{T}"/> to compare keys.</param> /// <param name="defaultValue">The value returned when no match is found in the dictionary, or default(T) if unspecified</param> /// <param name="maxBatchSize">The maximum number of keys passed to the fetch delegate at a time</param> /// <returns>A new or existing DataLoader instance</returns> public static IDataLoader <TKey, T> GetOrAddBatchLoader <TKey, T>(this DataLoaderContext context, string loaderKey, Func <IEnumerable <TKey>, CancellationToken, Task <IDictionary <TKey, T> > > fetchFunc, IEqualityComparer <TKey> keyComparer = null, T defaultValue = default, int maxBatchSize = int.MaxValue) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } return(context.GetOrAdd(loaderKey, () => new BatchDataLoader <TKey, T>(fetchFunc, keyComparer, defaultValue, maxBatchSize))); }
public static IDataLoader <TKey, T> GetOrAddBatchLoader <TKey, T>(this DataLoaderContext context, string loaderKey, Func <IEnumerable <TKey>, CancellationToken, Task <IEnumerable <T> > > fetchFunc, Func <T, TKey> keySelector, IEqualityComparer <TKey> keyComparer = null, T defaultValue = default(T)) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } return(context.GetOrAdd(loaderKey, () => new BatchDataLoader <TKey, T>(fetchFunc, keySelector, keyComparer, defaultValue))); }
public static IDataLoader <TKey, IEnumerable <T> > GetOrAddCollectionBatchLoader <TKey, T>(this DataLoaderContext context, string loaderKey, Func <IEnumerable <TKey>, Task <IEnumerable <T> > > fetchFunc, Func <T, TKey> keySelector, IEqualityComparer <TKey> keyComparer = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (fetchFunc == null) { throw new ArgumentNullException(nameof(fetchFunc)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } return(context.GetOrAdd(loaderKey, () => new CollectionBatchDataLoader <TKey, T>(WrapNonCancellableFunc(fetchFunc), keySelector, keyComparer))); }