/// <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> /// <param name="disableTracking">Use <see cref="EntityFrameworkQueryableExtensions.AsNoTracking{TEntity}"/> for all <see cref="IQueryable{T}"/> operations.</param> #region RegisterInContainer public static void RegisterInContainer <TDbContext>( IServiceCollection services, ResolveDbContext <TDbContext>?resolveDbContext = null, IModel?model = null, ResolveFilters?resolveFilters = null, bool disableTracking = false) #endregion where TDbContext : DbContext { Guard.AgainstNull(nameof(services), services); RegisterScalarsAndArgs(services); services.AddHttpContextAccessor(); services.AddTransient <HttpContextCapture>(); services.AddSingleton( provider => Build(resolveDbContext, model, resolveFilters, provider, disableTracking)); }
/// <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> /// <param name="disableTracking">Use <see cref="EntityFrameworkQueryableExtensions.AsNoTracking{TEntity}"/> for all <see cref="IQueryable{T}"/> operations.</param> #region RegisterInContainer public static void RegisterInContainer <TDbContext>( IServiceCollection services, ResolveDbContext <TDbContext>?resolveDbContext = null, IModel?model = null, ResolveFilters?resolveFilters = null, bool disableTracking = false) #endregion where TDbContext : DbContext { RegisterScalarsAndArgs(services); services.AddHttpContextAccessor(); services.AddTransient <HttpContextCapture>(); services.AddSingleton( provider => Build(resolveDbContext, model, resolveFilters, provider, disableTracking)); services.AddSingleton <IEfGraphQLService <TDbContext> >( provider => provider.GetRequiredService <EfGraphQLService <TDbContext> >()); }
/// <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); GraphTypeTypeRegistry.Register <PaginationMetaData, PaginationMetaDataType>(); GraphTypeTypeRegistry.Register(typeof(Pagination <>), typeof(PaginationType <>)); RegisterScalarsAndArgs(services); services.AddHttpContextAccessor(); services.AddTransient <HttpContextCapture>(); services.AddSingleton( provider => Build(resolveDbContext, model, resolveFilters, provider)); }
static IEfGraphQLService <TDbContext> Build <TDbContext>( ResolveDbContext <TDbContext>?dbContextResolver, IModel?model, ResolveFilters?filters, IServiceProvider provider) where TDbContext : DbContext { model ??= ResolveModel <TDbContext>(provider); filters ??= provider.GetService <ResolveFilters>(); if (dbContextResolver == null) { dbContextResolver = context => DbContextFromProvider <TDbContext>(provider); } return(new EfGraphQLService <TDbContext>( model, dbContextResolver, filters)); }
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)); }