Exemplo n.º 1
0
    public async Task TransientDbContext()
    {
        await using var database = await sqlInstance.Build();

        var dbContext = database.Context;

        await AddData(dbContext);

        var services = BuildServiceCollection();

        services.AddTransient(_ => database.Context);

        EfGraphQLConventions.RegisterInContainer(
            services,
            userContext => ((UserContextSingleDb <DependencyDbContext>)userContext).DbContext);
        await using var provider      = services.BuildServiceProvider();
        using DependencySchema schema = new(provider);
        ExecutionOptions executionOptions = new()
        {
            Schema      = schema,
            Query       = query,
            UserContext = new UserContextSingleDb <DependencyDbContext>(dbContext),
            Inputs      = null
        };

        await ExecutionResultData(executionOptions);
    }
Exemplo n.º 2
0
    public static async Task <string> ExecuteQuery <TDbContext>(
        string query,
        ServiceCollection services,
        TDbContext data,
        Inputs?inputs,
        Filters?filters,
        bool disableTracking)
        where TDbContext : DbContext
    {
        query = query.Replace("'", "\"");
        EfGraphQLConventions.RegisterInContainer(
            services,
            _ => data,
            data.Model,
            _ => filters,
            disableTracking);
        EfGraphQLConventions.RegisterConnectionTypesInContainer(services);
        await using var provider = services.BuildServiceProvider();
        using Schema schema      = new(provider);
        EfDocumentExecuter executer = new();

        ExecutionOptions options = new()
        {
            Schema      = schema,
            Query       = query,
            UserContext = new UserContextSingleDb <TDbContext>(data),
            Inputs      = inputs,
        };

        var result = await executer.ExecuteWithErrorCheck(options);

        return(await result.Serialize());
    }
    public async Task ExplicitModel()
    {
        await using var database = await sqlInstance.Build();

        var dbContext = database.Context;

        await AddData(dbContext);

        var services = BuildServiceCollection();

        services.AddSingleton <DependencySchema>();
        EfGraphQLConventions.RegisterInContainer(
            services,
            userContext => ((UserContextSingleDb <DependencyDbContext>)userContext).DbContext,
            sqlInstance.Model);
        await using var provider = services.BuildServiceProvider();
        using var schema         = provider.GetRequiredService <DependencySchema>();
        ExecutionOptions executionOptions = new()
        {
            Schema      = schema,
            Query       = query,
            UserContext = new UserContextSingleDb <DependencyDbContext>(dbContext),
            Inputs      = null
        };

        await ExecutionResultData(executionOptions);
    }