Beispiel #1
0
        public static T DataLoader <T>(
            this IResolverContext context,
            string key)
            where T : class, IDataLoader
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(
                          TypeResources.DataLoaderRegistry_KeyNullOrEmpty,
                          nameof(key));
            }

            if (TryGetDataLoader(context, key,
                                 out T dataLoader,
                                 out IDataLoaderRegistry registry))
            {
                return(dataLoader);
            }

            return(GetOrCreate <T>(key, registry, r => r.Register(
                                       key, ActivatorHelper.CreateInstanceFactory <T>())));
        }
        public static bool Register <T>(
            this IDataLoaderRegistry registry)
            where T : class, IDataLoader
        {
            Func <IServiceProvider, T> createInstance =
                ActivatorHelper.CreateInstanceFactory <T>();

            return(registry.Register(typeof(T).FullName, createInstance));
        }
Beispiel #3
0
        public static T DataLoader <T>(
            this IResolverContext context,
            string key)
            where T : class, IDataLoader
        {
            if (string.IsNullOrEmpty(key))
            {
                // TODO : resources
                throw new ArgumentException(
                          "The DataLoader key cannot be null or empty.",
                          nameof(key));
            }

            if (TryGetDataLoader(context, key,
                                 out T dataLoader,
                                 out IDataLoaderRegistry registry))
            {
                return(dataLoader);
            }

            return(GetOrCreate <T>(key, registry, r => r.Register(
                                       key, ActivatorHelper.CreateInstanceFactory <T>())));
        }