Esempio n. 1
0
        public async Task Initialize()
        {
            context = await UtilityFactory.CreateContextAsync();

            countryService = new CountryService(UtilityFactory.CreateMapper(), context,
                                                new AsyncReaderWriterLock(), ModifierParserContainer.CreateDefault());
        }
        public async Task Initialize()
        {
            context = await UtilityFactory.CreateContextAsync();

            turnService = new TurnHandlingService(ModifierParserContainer.CreateDefault(), new AsyncReaderWriterLock());
        }
Esempio n. 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <PasswordHasherOptions>(options => options.IterationCount = 100000);
            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireNonAlphanumeric = false;
            });

            services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext <UnderSeaDatabaseContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDefaultIdentity <User>()
            .AddEntityFrameworkStores <UnderSeaDatabaseContext>();

            services.AddIdentityServer()
            .AddCorsPolicyService <IdentityServerCorsPolicyService>()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
            .AddInMemoryApiResources(IdentityServerConfig.GetApiResources(Configuration))
            .AddInMemoryClients(IdentityServerConfig.GetClients(Configuration))
            .AddAspNetIdentity <User>();

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.Authority                 = Configuration["Authority"];
                options.Audience                  = Configuration["ApiName"];
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    NameClaimType = JwtClaimTypes.Name
                };
            });

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(policy =>
                {
                    var allowedOrigins = Configuration.GetSection("CorsOrigins")
                                         .GetChildren()
                                         .Select(x => x.Value)
                                         .ToArray();

                    policy.WithOrigins(allowedOrigins)
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining <PurchaseValidator>());

            services.AddSignalR();

            services.AddSwaggerDocument(options =>
            {
                options.Title       = "Undersea API";
                options.Version     = "1.0";
                options.Description = "API for the game called Under sea, which is a turn based online multiplayer strategy game.";

                options.PostProcess = document =>
                {
                    var settings = new TypeScriptClientGeneratorSettings
                    {
                        ClassName = "{controller}Client",
                        Template  = TypeScriptTemplate.Axios
                    };

                    var generator = new TypeScriptClientGenerator(document, settings);
                    var code      = generator.GenerateFile();

                    var path      = Directory.GetCurrentDirectory();
                    var directory = new DirectoryInfo(path + @"\TypeScript");
                    if (!directory.Exists)
                    {
                        directory.Create();
                    }

                    var filePath = path + @"\TypeScript\Client.ts";
                    File.WriteAllText(filePath, code);
                };
            });

            services.AddAutoMapper(typeof(KnownValues).Assembly);

            services.AddSingleton(ModifierParserContainer.CreateDefault());
            services.AddSingleton <IUserTracker, UserTracker>();
            services.AddSingleton <AsyncReaderWriterLock>();

            services.AddTransient <ITurnHandlingService, TurnHandlingService>();
            services.AddTransient <ICountryService, CountryService>();
            services.AddTransient <IResearchService, ResearchService>();
            services.AddTransient <IBuildingService, BuildingService>();
            services.AddTransient <IUnitService, UnitService>();
            services.AddTransient <ICommandService, CommandService>();
            services.AddTransient <IReportService, ReportService>();
            services.AddTransient <IDbLogger, DbLogger>();

            // User ID provider for SignalR Hub
            services.AddTransient <IUserIdProvider, UserIdProvider>();
        }