Exemplo n.º 1
0
        private static IDataLoader <TKey, TValue[]> DataLoader <TKey, TValue>(
            this IResolverContext context,
            string key,
            FetchGroupedFactory <TKey, 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));
            }

            if (TryGetDataLoader(context, key,
                                 out IDataLoader <TKey, TValue[]> dataLoader,
                                 out IDataLoaderRegistry registry))
            {
                return(dataLoader);
            }

            return(GetOrCreate <IDataLoader <TKey, TValue[]> >(
                       key, registry, r => r.Register(key, factory)));
        }
        public static bool Register <TKey, TValue>(
            this IDataLoaderRegistry registry,
            string key,
            FetchGroupedFactory <TKey, 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 =>
                                     new FetchGroupedDataLoader <TKey, TValue>(
                                         factory(services))));
        }