예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

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

            services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));


            services.AddScoped(typeof(IUserRepository), typeof(UserRepository));

            services.AddScoped(typeof(IUserService), typeof(UserService));

            services.AddAutoMapper(typeof(Startup));

            var datatableOptions = new DataTables.AspNet.AspNetCore.Options()
                                   .EnableRequestAdditionalParameters()
                                   .EnableResponseAdditionalParameters();

            var dataTableBinder = new ModelBinder();

            dataTableBinder.ParseAdditionalParameters = Parser;
            services.RegisterDataTables(datatableOptions, dataTableBinder);

            services.AddDbContext <UserDataDbContext>(options =>
                                                      options.UseSqlServer(Configuration.GetConnectionString("UserDataDbContext")));
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IConfiguration>(Configuration);

            // Use a PostgresSQL Database
            var sqlConnectionString = Configuration["DataAccessPostgreSqlProvider:ConnectionString"];

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseNpgsql(
                                                             sqlConnectionString,
                                                             b => b.MigrationsAssembly("App.Web")
                                                             )
                                                         );

            services.Configure <IdentityOptions>(options =>
            {
                options.Tokens.EmailConfirmationTokenProvider = EmailConfirmationTokenProviderName;
                options.Tokens.PasswordResetTokenProvider     = PasswordResetTokenProviderName;
            });

            services.Configure <ConfirmEmailDataProtectionTokenProviderOptions>(options =>
            {
                options.TokenLifespan = TimeSpan.FromHours(5);
            });

            services.Configure <PasswordResetProtectionTokenProviderOptions>(options =>
            {
                options.TokenLifespan = TimeSpan.FromMinutes(5);
            });

            services.Configure <HostConfiguration>(HostConfiguration =>
            {
                HostConfiguration.Name     = Configuration["host:name"];
                HostConfiguration.Protocol = Configuration["host:protocol"];
            });

            services.AddIdentity <ApplicationUser, ApplicationRole>(config =>
            {
                config.User.RequireUniqueEmail = true;
                config.Password = new PasswordOptions
                {
                    RequireDigit           = false,
                    RequireNonAlphanumeric = false,
                    RequireLowercase       = false,
                    RequireUppercase       = false,
                    RequiredLength         = 8,
                };
                config.Cookies.ApplicationCookie.LoginPath = "/Account/Login";
            })
            .AddEntityFrameworkStores <ApplicationDbContext, string>()
            .AddDefaultTokenProviders()
            .AddTokenProvider <ConfirmEmailDataProtectorTokenProvider <ApplicationUser> >(EmailConfirmationTokenProviderName)
            .AddTokenProvider <PasswordResetDataProtectorTokenProvider <ApplicationUser> >(PasswordResetTokenProviderName);

            services.AddApplicationInsightsTelemetry(Configuration);

            services.Configure <IISOptions>(options =>
            {
                options.AutomaticAuthentication = true;
            });

            services.AddSession();

            services.AddScoped <LogFilter>();

            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.MaxDepth = 1;
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            var dtTablesOptions = new DataTables.AspNet.AspNetCore.Options(10, true, true, true, new CamelCaseRequestNameConvention(),
                                                                           new CamelCaseResponseNameConvention());

            services.RegisterDataTables(dtTablesOptions);

            MapperConfig.Map(services);

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

            services.AddScoped <LogFilter>();

            ServicesRegistrar.Register(services);

            HelperRegistrar.Register(services);

            services.AddSingleton <ISmtpOptionsService, SmtpOptionsService>(x => new SmtpOptionsService()
            {
                User                   = "******",
                Password               = "******",
                Server                 = "smtp.gmail.com",
                Port                   = 465,
                UseSsl                 = true,
                FromEmail              = "*****@*****.**",
                FromName               = "*****@*****.**",
                PrefferedEncoding      = null,
                RequiresAunthetication = true
            });

            services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddInMemoryClients(IdSrvConfig.GetClients())
            .AddInMemoryScopes(IdSrvConfig.GetScopes())
            .AddAspNetIdentity <ApplicationUser>()
            .AddProfileService <IdentityWithAdditionalClaimsProfileService>();

            services.AddCors(options =>
            {
                options.AddPolicy("AllowSpecificOrigin",
                                  builder => builder.AllowAnyOrigin());
            });
        }