Ejemplo n.º 1
0
        public static bool Register <TValue>(
            this IDataLoaderRegistry registry,
            string key,
            FetchOnceFactory <TValue> factory)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          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 bool Register <TValue>(
            this IDataLoaderRegistry registry,
            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(registry.Register(key, services =>
            {
                return new FetchSingleDataLoader <string, TValue>(
                    k => fetch(), DataLoaderDefaults.MinCacheSize);
            }));
        }