-
-
Save tuannguyenssu/9fb027c5fdaeeabf39ad50ab7e4346cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.EntityFrameworkCore; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Microsoft.Extensions.Options; | |
using GraphQLTest.Services; | |
using GraphQLTest.GraphQL; | |
using GraphQL; | |
using GraphQL.Server; | |
using GraphQL.Server.Ui.Playground; | |
namespace GraphQLTest | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Inject các interfaces | |
services.AddScoped<ICustomerService, CustomerService>(); | |
services.AddScoped<IOrderService, OrderService>(); | |
// Cấu hình GraphQL | |
services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService)); | |
services.AddScoped<GraphTestSchema>(); | |
services.AddGraphQL(o => { | |
o.ExposeExceptions = true; | |
}).AddGraphTypes(ServiceLifetime.Scoped); | |
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
// Cấu hình GraphQL | |
app.UseGraphQL<GraphTestSchema>(); | |
// Ở đây sử dụng PlayGround UI | |
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions()); | |
app.UseMvc(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment