コード例 #1
0
ファイル: Startup.cs プロジェクト: RamanPaliakou/time-tracker
        public void ConfigureServices(IServiceCollection services)
        {
            MongoDbCreator.CreateDbInstance(Configuration.GetValue <string>("MongoInstancePath"), Configuration.GetValue <int>("MongoInstancePort"));

            services.AddDbContext <RDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddCors(x => x.AddPolicy("Default", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowCredentials()
                .AllowAnyHeader();
            }));

            services.AddMvc();

            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.Secret);



            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;//false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true, // The signing key is valid and is trusted by the server
                    //ValidateLifetime = false, // The token has not expired
                    ValidateIssuer   = false,        // The issuer is the actual server that created the token
                    ValidateAudience = false,        // The receiver of the token is a valid recipient

                    //ValidIssuer = "http://localhost:5000",
                    //ValidAudience = "http://localhost:5000",
                    IssuerSigningKey = new SymmetricSecurityKey(key),
                };
            });

            // configure DI for application services
            services.AddSingleton <INRDbContext, NRDbContext>();
            services.AddScoped <ICardRepository, CardRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IViewCardRepository, ViewCardRepository>();
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <ICardAggregate, CardAggregate>();


            //Connect to React
            //services.AddSpaStaticFiles(configuration =>
            //{
            //    configuration.RootPath = "ClientApp/build";
            //});
        }
コード例 #2
0
 public BaseMongoRepositoryAdd(MongoDbCreator mongoDbCreator)
 {
     _mongoDbCreator = mongoDbCreator;
 }