コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true);
            services.AddControllersWithViews()
            .AddFluentValidation(opt =>
            {
                opt.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly());
            });
            services.AddRazorPages();

            ConfigureCors(services);

            services.AddSingleton <ICloudStorage, AzureStorage>();
            services.AddSingleton <IStorageConnectionFactory, StorageConnectionFactory>(sp =>
            {
                CloudStorageOptions cloudStorageOptions = new CloudStorageOptions();
                cloudStorageOptions.ConnectionString    = Configuration["AzureBlobStorage:ConnectionString"];
                cloudStorageOptions.Container           = Configuration["AzureBlobStorage:BlobContainer"];
                return(new StorageConnectionFactory(cloudStorageOptions));
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Music File API", Version = "v1"
                });
            });
        }
コード例 #2
0
 public UserRepository(Func <QueryFactory> queryFactory, IPasswordHash passwordHash, ICloudStorage cloudStorage, IOptions <CloudStorageOptions> options, ITransactionRepository transactions) : base(queryFactory)
 {
     _queryFactory = queryFactory;
     _passwordHash = passwordHash;
     _cloudStorage = cloudStorage;
     _transactions = transactions;
     _options      = options.Value;
 }
コード例 #3
0
 public ApplicationRepository(Func <QueryFactory> queryFactory, ICloudStorage storage, IOptions <CloudStorageOptions> options, IDownloadRepository downloads, IUserRepository users) : base(queryFactory)
 {
     _queryFactory = queryFactory;
     _storage      = storage;
     _downloads    = downloads;
     _users        = users;
     _options      = options.Value;
 }
コード例 #4
0
        /// <summary>
        /// Add a health check for GCP CloudStorage.
        /// </summary>
        /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
        /// <param name="setup">The action to configure the Cloud Storage parameters.</param>
        /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'gcpcloudstorage' will be used for the name.</param>
        /// <param name="failureStatus">
        /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
        /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
        /// </param>
        /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
        /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
        public static IHealthChecksBuilder AddGcpCloudStorage(
            this IHealthChecksBuilder builder,
            Action <CloudStorageOptions> setup,
            string name = default,
            HealthStatus?failureStatus = default,
            IEnumerable <string> tags  = default)
        {
            var options = new CloudStorageOptions();

            setup?.Invoke(options);

            return(builder.Add(new HealthCheckRegistration(name ?? NAME,
                                                           sp => new GcpCloudStorageHealthCheck(options),
                                                           failureStatus,
                                                           tags)));
        }
コード例 #5
0
 public StorageConnectionFactory(CloudStorageOptions storageOptions)
 {
     _storageOptions = storageOptions;
 }
コード例 #6
0
 public DownloadFileRepository(Func <QueryFactory> queryFactory, ICloudStorage storage, IOptions <CloudStorageOptions> options) : base(queryFactory)
 {
     _queryFactory = queryFactory;
     _storage      = storage;
     _options      = options.Value;
 }
コード例 #7
0
 public HomeController(IOptions <CloudStorageOptions> options)
 {
     _options = options.Value;
     _storage = StorageClient.Create();
 }
コード例 #8
0
 public VisionService(ILogger <VisionService> logger, IOptions <CloudStorageOptions> options)
 {
     _logger  = logger;
     _options = options.Value;
     _storage = StorageClient.Create();
 }
コード例 #9
0
ファイル: Startup.cs プロジェクト: iceebajs/MordorFanficWeb
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AppDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("MordorFanficWeb")));

            services.AddSingleton <IJwtFactory, JwtFactory>();

            var jwtAppSettingsOptions = Configuration.GetSection(nameof(JwtIssuerOptions));

            services.Configure <JwtIssuerOptions>(options =>
            {
                options.Issuer             = jwtAppSettingsOptions[nameof(JwtIssuerOptions.Issuer)];
                options.Audience           = jwtAppSettingsOptions[nameof(JwtIssuerOptions.Audience)];
                options.SigningCredentials = new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256);
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AccountUser", policy =>
                {
                    policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
                    policy.RequireAuthenticatedUser();
                    policy.RequireClaim(Constants.Strings.JwtClaimIdentifiers.Rol, Constants.Strings.JwtClaims.ApiAccess);
                });

                options.AddPolicy("Admin", policy =>
                {
                    policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
                    policy.RequireAuthenticatedUser();
                    policy.RequireClaim(Constants.Strings.JwtClaimIdentifiersAdmin.Rol, Constants.Strings.JwtClaims.ApiAccess);
                });

                options.AddPolicy("RegisteredUsers", policy =>
                {
                    policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
                    policy.RequireAuthenticatedUser();
                    policy.Requirements.Add(new RegisteredUserRequirement());
                });
            });

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidIssuer    = jwtAppSettingsOptions[nameof(JwtIssuerOptions.Issuer)],

                    ValidateAudience = true,
                    ValidAudience    = jwtAppSettingsOptions[nameof(JwtIssuerOptions.Audience)],

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = signinKey,

                    RequireExpirationTime = false,
                    ValidateLifetime      = true,
                    ClockSkew             = TimeSpan.Zero
                };
            });

            services.AddIdentity <AppUser, IdentityRole>(
                options =>
            {
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = true;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddSingleton <IAuthorizationHandler, UserRegisteredHandler>();
            services.AddScoped <IAccountService, AccountService>();
            services.AddScoped <IAccountAdapter, AccountAdapter>();
            services.AddScoped <ICompositionService, CompositionService>();
            services.AddScoped <ICompositionAdapter, CompositionAdapter>();
            services.AddScoped <IChapterService, ChapterService>();
            services.AddScoped <IChapterAdapter, ChapterAdapter>();
            services.AddScoped <ITagsService, TagsService>();
            services.AddScoped <ITagsAdapter, TagsAdapter>();
            services.AddScoped <ICompositionTagsService, CompositionTagsService>();
            services.AddScoped <ICompositionTagsAdapter, CompositionTagsAdapter>();
            services.AddScoped <ICommentsService, CommentsService>();
            services.AddScoped <ICommentsAdapter, CommentsAdapter>();
            services.AddScoped <ICompositionRatingsService, CompositionRatingsService>();
            services.AddScoped <ICompositionRatingsAdapter, CompositionRatingsAdapter>();
            services.AddScoped <IChapterLikesService, ChapterLikesService>();
            services.AddScoped <IChapterLikesAdapter, ChapterLikesAdapter>();
            services.AddScoped <IAppDbContext, AppDbContext>();

            services.AddTransient <IValidator <ChangeUserPasswordViewModel>, ChangeUserPasswordValidator>();
            services.AddTransient <IValidator <RegistrationViewModel>, RegistrationViewModelValidator>();
            services.AddTransient <IValidator <UpdateUserViewModel>, UpdateUserViewModelValidator>();
            services.AddTransient <IValidator <CredentialsViewModel>, CredentialsViewModelValidator>();
            services.AddTransient <IValidator <CompositionViewModel>, CompositionViewModelValidator>();
            services.AddTransient <IValidator <ChapterViewModel>, ChapterViewModelValidator>();

            services.AddSingleton <IStorageConnectionFactory, StorageConnectionFactory>(sp => {
                CloudStorageOptions cloudStorageOptions = new CloudStorageOptions();
                cloudStorageOptions.ConnectionString    = Configuration["AzureBlobStorage:ConnectionString"];
                cloudStorageOptions.ImagesContainerName = Configuration["AzureBlobStorage:BlobContainer"];
                return(new StorageConnectionFactory(cloudStorageOptions));
            });
            services.AddSingleton <ICloudStorageService, CloudStorageService>();
            services.AddSingleton(typeof(WebSocketService), new WebSocketService());

            services.AddSingleton(Common.AutoMapper.AutoMapper.Configure());

            services.AddMvc(
                options => options.EnableEndpointRouting = false)
            .AddFluentValidation();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }