Example #1
0
 public static void RegisterInContainer <TDbContext>(
     IServiceCollection services,
     TDbContext dbContext,
     DbContextFromUserContext <TDbContext> dbContextFromUserContext,
     GlobalFilters filters = null)
     where TDbContext : DbContext
 #endregion
 {
     Guard.AgainstNull(nameof(services), services);
     Guard.AgainstNull(nameof(dbContext), dbContext);
     services.AddTransient(typeof(ConnectionType <>));
     services.AddTransient(typeof(EdgeType <>));
     services.AddSingleton <PageInfoType>();
     RegisterInContainer((type, instance) => { services.AddSingleton(type, instance); }, dbContext, dbContextFromUserContext, filters);
 }
        public EfGraphQLService(IModel model, GlobalFilters filters, DbContextFromUserContext <TDbContext> dbContextFromUserContext)
        {
            Guard.AgainstNull(nameof(model), model);
            Guard.AgainstNull(nameof(dbContextFromUserContext), dbContextFromUserContext);
            this.filters = filters;
            this.dbContextFromUserContext = dbContextFromUserContext;
            foreach (var entityType in model.GetEntityTypes())
            {
                var primaryKey = entityType.FindPrimaryKey();
                //This can happen for views
                if (primaryKey == null)
                {
                    continue;
                }

                var names = primaryKey.Properties.Select(x => x.Name).ToList();
                keyNames.Add(entityType.ClrType, names);
            }

            includeAppender = new IncludeAppender(NavigationReader.GetNavigationProperties(model));
        }
Example #3
0
        public static void RegisterInContainer <TDbContext>(
            Action <Type, object> register,
            TDbContext dbContext,
            DbContextFromUserContext <TDbContext> dbContextFromUserContext,
            GlobalFilters filters = null)
            where TDbContext : DbContext
        #endregion
        {
            Guard.AgainstNull(nameof(register), register);
            Guard.AgainstNull(nameof(dbContextFromUserContext), dbContextFromUserContext);
            Guard.AgainstNull(nameof(dbContext), dbContext);
            Scalars.RegisterInContainer(register);
            ArgumentGraphs.RegisterInContainer(register);

            if (filters == null)
            {
                filters = new GlobalFilters();
            }

            var service = new EfGraphQLService <TDbContext>(dbContext.Model, filters, dbContextFromUserContext);

            register(typeof(IEfGraphQLService <TDbContext>), service);
        }