Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Logging;
  6. using NLog.Web;
  7. using NLog.Extensions.Logging;
  8. using Microsoft.EntityFrameworkCore;
  9. using DataAccess.Context;
  10. using Core.CategoriesApi.Containers;
  11.  
  12. namespace CategoriesApi
  13. {
  14. public class Startup
  15. {
  16. public Startup(IConfiguration configuration, IHostingEnvironment env)
  17. {
  18. env.ConfigureNLog("nlog.config");
  19. Configuration = configuration;
  20. var asdf = Configuration.GetConnectionString("GymAppDatabase");
  21. }
  22.  
  23. public IConfiguration Configuration { get; set; }
  24.  
  25. // This method gets called by the runtime. Use this method to add services to the container.
  26. public void ConfigureServices(IServiceCollection services)
  27. {
  28. services.AddCors(options =>
  29. {
  30. options.AddPolicy("CorsPolicy",
  31. builder => builder.AllowAnyOrigin()
  32. .AllowAnyMethod()
  33. .AllowAnyHeader()
  34. .AllowCredentials());
  35. });
  36. services.AddMvc();
  37. services.Configure<PostgreConnectionStringConfig>( Configuration);
  38. services.AddDbContext<TrainingsPlanPostgreDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("GymAppDatabase")));
  39.  
  40. }
  41.  
  42. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  43. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  44. {
  45. app.UseCors("CorsPolicy");
  46. //add NLog to ASP.NET Core
  47. loggerFactory.AddNLog();
  48.  
  49. //add NLog.Web
  50. app.AddNLogWeb();
  51.  
  52.  
  53. if (env.IsDevelopment())
  54. {
  55. app.UseDeveloperExceptionPage();
  56. }
  57.  
  58. app.UseMvc(routes =>
  59. {
  60. routes.MapRoute(
  61. name: "default",
  62. template: "{controller=Home}/{action=Index}/{id?}");
  63. });
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement