Created
August 2, 2019 08:58
-
-
Save ngohungphuc/2507e0d178c725bbc6abb41b5fc73e98 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); | |
services | |
.AddMvc() | |
.AddJsonOptions( | |
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore | |
) | |
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); | |
// In production, the Angular files will be served from this directory | |
services.AddSpaStaticFiles(configuration => | |
{ | |
configuration.RootPath = "ClientApp/dist"; | |
}); | |
services.AddScoped<Repository>(); | |
services.AddScoped<Seeder>(); | |
services.AddScoped<IDependencyResolver>(x => new FuncDependencyResolver(x.GetRequiredService)); | |
services.AddScoped<DataSchema>(); | |
services.AddGraphQL(x => | |
{ | |
x.ExposeExceptions = true; //set true only in development mode. make it switchable. | |
}) | |
.AddGraphTypes(ServiceLifetime.Scoped); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Seeder seeder) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ | |
app.UseExceptionHandler("/Error"); | |
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | |
app.UseHsts(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseStaticFiles(); | |
app.UseSpaStaticFiles(); | |
app.UseGraphQL<DataSchema>(); | |
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions()); | |
app.UseMvc(routes => | |
{ | |
routes.MapRoute( | |
name: "default", | |
template: "{controller}/{action=Index}/{id?}"); | |
}); | |
var post = File.ReadAllText(@"wwwroot/post.json"); | |
var comment = File.ReadAllText(@"wwwroot/comment.json"); | |
seeder.Seedit(post, comment); | |
app.UseSpa(spa => | |
{ | |
// To learn more about options for serving an Angular SPA from ASP.NET Core, | |
// see https://go.microsoft.com/fwlink/?linkid=864501 | |
spa.Options.SourcePath = "ClientApp"; | |
if (env.IsDevelopment()) | |
{ | |
spa.UseAngularCliServer(npmScript: "start"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment