// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddResponseCaching(); services.AddMvc(); services.AddHackerNews(); services.AddSingleton <IMapper>(MapperConfig.Create()); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "HackerNews API", Version = "version 1" }); }); }
public static void Main(String[] args) { var container = new UnityContainer(); container.RegisterInstance(MapperConfig.Create()); container.RegisterType <IArticleRepository, ArticleRepository>(); container.RegisterType <IWriterRepository, WriterRepository>(); container.RegisterType <IArticleValidator, ArticleValidator>(); container.RegisterInstance(new ArticleServerDbContext()); Database.SetInitializer(new ArticleServerDbContextInitializer()); var server = container.Resolve <Server>(); server.Start(); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("redditthreads.json", optional: true, reloadOnChange: true); var configuration = builder.Build(); var context = new TreasureEntities(configuration.GetConnectionString("TreasureEntities")); var mapper = MapperConfig.Create(); AssureContextOpen(context); RunParsers(context, mapper, configuration); while (Running || ParsersRunning > 0) { // ... } Debug.WriteLine("Seeya"); }
public static void Configure(IServiceCollection services, IConfigurationRoot configuration, SecurityKey securityKey) { // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( configuration.GetConnectionString("TreasureEntities"), sqlServerOptions => sqlServerOptions.CommandTimeout(10).EnableRetryOnFailure(0) )); services.AddIdentity <ApplicationUser, IdentityRole>(options => { options.User.RequireUniqueEmail = false; options.User.AllowedUserNameCharacters += " "; options.Cookies.ApplicationCookie.AutomaticChallenge = false; options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents { OnRedirectToLogin = (ctx) => { if (ctx.Request.Path.StartsWithSegments("/api")) { ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; ctx.Response.WriteAsync($"{{\"error\": {ctx.Response.StatusCode}}}"); } else { ctx.Response.Redirect(ctx.RedirectUri); } return(Task.FromResult(0)); } }; }) .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddMvc(options => { options.Filters.Add(new RequireHttpsAttribute()); options.Filters.Add(new ExceptionLoggerAttribute()); options.Filters.Add(new ThrottlingAttribute()); }).AddJsonOptions(json => { json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); json.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; json.SerializerSettings.Converters.Add(new StringTrimmingJsonConverter()); }); services.AddCors(options => { options.AddPolicy("NakamaCORS", config => config.AllowAnyOrigin().WithMethods("GET")); }); var defaultJson = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; JsonConvert.DefaultSettings = () => defaultJson; var jwtAppSettingOptions = configuration.GetSection(nameof(JwtIssuerOptions)); // Configure JwtIssuerOptions services.Configure <JwtIssuerOptions>(options => { options.Issuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)]; options.Audience = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)]; options.Subject = jwtAppSettingOptions[nameof(JwtIssuerOptions.Subject)]; options.SigningCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); options.ValidFor = TimeSpan.FromDays(3); }); services.AddResponseCompression(options => { options.Providers.Add <GzipCompressionProvider>(); options.EnableForHttps = true; }); services.Configure <GzipCompressionProviderOptions>(options => { options.Level = CompressionLevel.Fastest; }); var builder = services.AddDataProtection(); var store = Directory.GetCurrentDirectory() + "/keys"; builder.PersistKeysToFileSystem(new DirectoryInfo(store)); builder.SetApplicationName("NakamaNetwork"); services.AddScoped(x => new TreasureEntities(configuration.GetConnectionString("TreasureEntities"))); services.AddScoped <IAuthExportService, AuthExportService>(); services.AddScoped <IPreferenceService, PreferenceService>(); services.AddScoped <IEmailSender, EmailSender>(); services.AddScoped <ISmsSender, SmsSender>(); services.AddScoped <IThrottleService, ThrottleService>(); services.AddScoped <IMetadataService, MetadataService>(); services.AddScoped <IDonationService, PaypalDonationService>(); services.AddScoped <TeamSearchService, TeamMiniDbSearchService>(); services.AddSingleton(x => configuration); services.AddSingleton(x => MapperConfig.Create()); }
public void MapperConfig_GeneratesValidMapping() { var mapper = MapperConfig.Create(); Assert.IsNotNull(mapper); }