public EfGraphQLService( IModel model, ResolveDbContext <TDbContext> resolveDbContext, ResolveFilters resolveFilters = null) { Guard.AgainstNull(nameof(model), model); Guard.AgainstNull(nameof(resolveDbContext), resolveDbContext); this.resolveFilters = resolveFilters; this.resolveDbContext = resolveDbContext; 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)); }
/// <summary> /// Register the necessary services with the service provider for a data context of <typeparamref name="TDbContext"/> /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param> /// <param name="resolveDbContext">A function to obtain the <typeparamref name="TDbContext"/> from the GraphQL user context. If null, then it will be extracted from the <see cref="IServiceProvider"/>.</param> /// <param name="model">The <see cref="IModel"/> to use. If null, then it will be extracted from the <see cref="IServiceProvider"/>.</param> /// <param name="resolveFilters">A function to obtain a list of filters to apply to the returned data. If null, then it will be extracted from the <see cref="IServiceProvider"/>.</param> #region RegisterInContainer public static void RegisterInContainer <TDbContext>( IServiceCollection services, ResolveDbContext <TDbContext> resolveDbContext = null, IModel model = null, ResolveFilters resolveFilters = null) #endregion where TDbContext : DbContext { Guard.AgainstNull(nameof(services), services); RegisterScalarsAndArgs(services); services.AddSingleton( provider => Build(resolveDbContext, model, resolveFilters, provider)); }
static IEfGraphQLService <TDbContext> Build <TDbContext>( ResolveDbContext <TDbContext> dbContext, IModel model, ResolveFilters filters, IServiceProvider provider) where TDbContext : DbContext { model = model ?? ResolveModel <TDbContext>(provider); filters = filters ?? provider.GetService <ResolveFilters>(); if (dbContext == null) { dbContext = context => provider.GetRequiredService <TDbContext>(); } return(new EfGraphQLService <TDbContext>( model, dbContext, filters)); }