コード例 #1
0
 public NewsController(INewsRepository repository,
                       INewsDetailRepository ndRepository,
                       IYouTubeService youTube,
                       IKotraNewsService kotraNews,
                       IMemoryCache memoryCache)
 {
     _repository   = repository;
     _ndRepository = ndRepository;
     _youTube      = youTube;
     _kotraNews    = kotraNews;
     _memoryCache  = memoryCache;
 }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DbInitializer seeder, IAntiforgery antiforgery, IKotraNewsService kotra, IMemoryCache memoryCache, ExodusKoreaContext ekcontext)
        {
            // load kotra news in background and store in cache
            //foreach (var c in ekcontext.News)
            //{
            //    var cache = memoryCache.Get<List<KotraNewsVM>>(c.Topic);
            //    if (cache == null)
            //        kotra.GetKotraNewsByCountry(c.Topic);
            //}

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.Clear();

            app.UseStaticFiles();

            app.UseCors(builder =>
            {
                if (_appSettingsEnv.Equals("Live"))
                {
                    builder.WithOrigins("https://talchoseon.com");
                }
                else if (_appSettingsEnv.Equals("Development"))
                {
                    builder.WithOrigins("http://localhost:4200");
                }
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowCredentials();
            });

            app.UseExceptionHandler(builder =>
            {
                builder.Run(async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        //context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                    }
                });
            });

            app.Use(next => context =>
            {
                if (context.Request.Path.Value.IndexOf("/", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    var tokens = antiforgery.GetAndStoreTokens(context);
                    context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions()
                    {
                        HttpOnly = false
                    });
                }

                return(next(context));
            });

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute("DefaultApi", "api/{controller}/{id?}");
            });

            app.UseWelcomePage();

            //seeder.InitializeData().Wait();
        }