示例#1
0
        public static IServiceCollection ConfigureSingletonServices(this IServiceCollection services)
        {
            services.AddSingleton <IEmailSender, EmailSender>();
            services.AddSingleton <IFileWriter, FileWriter>();
            services.AddSingleton <IFileReader, FileReader>();
            services.AddSingleton <ICookieClaimsPrincipalManager, CookieClaimsPrincipalManager>();
            services.AddSingleton <ICryptoService, CryptoService>();
            services.AddSingleton <IMimeMappingService>(new MimeMappingService(new FileExtensionContentTypeProvider()));

            services.AddSingleton <Alertify>(a => Alertify.Build());

            return(services);
        }
示例#2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <DataContext>(opt =>
            {
                opt.UseNpgsql(Configuration.GetConnectionString(AppSettingsKeys.ConnectionString));
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath      = Routes.LoginPath;
                options.LogoutPath     = Routes.LogoutPath;
                options.ExpireTimeSpan = TimeSpan.FromDays(Constants.TokenExpireTimeInDays);
            });


            services.AddControllersWithViews();

            services.AddHttpContextAccessor();
            services.AddSession();

            #region services
            services.AddSingleton <ITokenClaimsManager, TokenClaimsManager>();

            services.AddScoped <IDatabase, Database>();
            services.AddScoped(typeof(IRepository <>), typeof(Repository <>));

            services.AddScoped <IAuthService, AuthService>();
            services.AddScoped <IResetPasswordService, ResetPasswordService>();
            services.AddScoped <IProfileService, ProfileService>();
            services.AddScoped <IPostService, PostService>();
            services.AddScoped <IAnswerService, AnswerService>();
            services.AddScoped <IDatabaseManager, DatabaseManager>();
            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <ICryptoService, CryptoService>();
            services.AddScoped <IEmailSender, EmailSender>();

            services.AddSingleton <Alertify>(a => Alertify.Build());
            #endregion

            #region settings

            services.Configure <EmailSettings>(Configuration.GetSection(nameof(EmailSettings)));
            #endregion

            services.AddScoped <OnlyAnonymousFilter>();

            services.AddAutoMapper(typeof(Startup));
        }
        public static IServiceCollection ConfigureSingletonServices(this IServiceCollection services)
        {
            services.AddSingleton <IEmailSender, EmailSender>();
            services.AddSingleton <IFilesManager, FilesManager>();
            services.AddSingleton <IHashGenerator, HashGenerator>();
            services.AddSingleton <ICookieClaimsPrincipalGenerator, CookieClaimsPrincipalGenerator>();
            services.AddSingleton <IHttpContextService, HttpContextService>();
            services.AddSingleton <IHttpContextWriter, HttpContextService>();
            services.AddSingleton <IHttpContextReader, HttpContextService>();

            services.AddSingleton <IReadOnlyFilesManager, FilesManager>();

            services.AddSingleton <Alertify>(a => Alertify.Build());

            return(services);
        }