public static bool Register <TValue>( this IDataLoaderRegistry registry, string key, FetchOnceFactory <TValue> factory) { if (string.IsNullOrEmpty(key)) { // TODO : Resources throw new ArgumentException( "The DataLoader key cannot be null or empty.", nameof(key)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } return(registry.Register(key, services => { FetchOnce <TValue> fetch = factory(services); return new FetchSingleDataLoader <string, TValue>( k => fetch(), DataLoaderDefaults.MinCacheSize); })); }
public static Func <Task <TValue> > DataLoader <TValue>( this IResolverContext context, string key, FetchOnce <TValue> fetch) { if (string.IsNullOrEmpty(key)) { // TODO : resources throw new ArgumentException( "The DataLoader key cannot be null or empty.", nameof(key)); } if (fetch == null) { throw new ArgumentNullException(nameof(fetch)); } return(DataLoader(context, key, services => fetch)); }
public static bool Register <TValue>( this IDataLoaderRegistry registry, string key, FetchOnce <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 => { return new FetchSingleDataLoader <string, TValue>( k => fetch(), DataLoaderDefaults.MinCacheSize); })); }
public static Task <TValue> FetchOnceAsync <TValue>( this IResolverContext context, string key, FetchOnce <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(FetchOnceFactory(context, key, services => fetch)()); }