Last active
January 11, 2021 19:45
-
-
Save JIOO-phoeNIX/6f9510b6b5d95f4fa90bbc139e1119c2 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 GraphQLSampleApp.DataAccess; | |
using GraphQLSampleApp.DataAccess.DAO; | |
using GraphQLSampleApp.DataAccess.Entity; | |
using HotChocolate; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.HttpsPolicy; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace GraphQLSampleApp | |
{ | |
public class Startup | |
{ | |
private readonly string AllowedOrigin = "allowedOrigin"; | |
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) | |
{ | |
services.AddDbContext<SampleAppDbContext>(options => | |
options.UseSqlServer(Configuration.GetConnectionString("SampleAppDbContext"))); | |
services.AddInMemorySubscriptions(); | |
services | |
.AddGraphQLServer() | |
.AddQueryType<Query>() | |
.AddMutationType<Mutation>() | |
.AddSubscriptionType<Subscription>(); | |
services.AddScoped<EmployeeRepository, EmployeeRepository>(); | |
services.AddScoped<DepartmentRepository, DepartmentRepository>(); | |
services.AddCors(option => { | |
option.AddPolicy("allowedOrigin", | |
builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader() | |
); | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseCors(AllowedOrigin); | |
app.UseWebSockets(); | |
app | |
.UseRouting() | |
.UseEndpoints(endpoints => | |
{ | |
endpoints.MapGraphQL(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment