Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            bool useSqLite = false;

            bool.TryParse(Configuration["Data:useSqLite"], out useSqLite);
            string baglantiSatiri = useSqLite ? Configuration["Data:SqlLiteConnectionString"] : Configuration["Data:SqlServerConnectionString"];

            services.AddAutoMapper();
            services.Configure <CloudinarySettings>(Configuration.GetSection("CloudinarySettings"));
            services.Configure <FotografAyarlari>(Configuration.GetSection("FotografAyarlari"));
            services.Configure <ApiTercihleri>(Configuration.GetSection("ApiTercihleri"));
            services.Configure <UygulamaAyarlari>(Configuration.GetSection("AppSettings"));
            services.Configure <EpostaHesapBilgileri>(Configuration.GetSection("SistemPostaHesapBilgileri"));
            services.Configure <SMSHesapBilgileri>(Configuration.GetSection("SistemSMSHesapBilgileri"));



            var sp = services.BuildServiceProvider();

            Tercihler = sp.GetService <IOptions <ApiTercihleri> >().Value;


            services.AddTransient <IEmailSender, PostaciKit>();
            services.AddTransient <IPropertyMappingService, PropertyMappingService>();
            services.AddTransient <ITypeHelperService, TypeHelperService>();
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IUrlHelper, UrlHelper>(implementationFactory =>
            {
                var actionContext = implementationFactory.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });

            services.AddDbContexts(useSqLite, baglantiSatiri, Tercihler);

            if (Tercihler.AspNetCoreIdentityKullan)
            {
                services.AddMTIdentity(Configuration);
            }
            services.AddTransient <KullaniciRepository>();
            services.AddTransient <ISeederManager, SeederManager>();


            services.AddScoped <IKullaniciRepository, KullaniciRepository>();



            services.AddScoped <ICinsiyetRepository, CinsiyetRepository>();
            services.AddScoped <IArkadaslikRepository, ArkadaslikRepository>();
            services.AddScoped <IMesajlasmaRepository, MesajlasmaRepository>();

            services.AddScoped <IUykuTestRepository, UykuTestRepository>();
            var uygulamaAyarlari = sp.GetService <IOptions <UygulamaAyarlari> >().Value;


            services.AddAuthentication()
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(uygulamaAyarlari.JwtKey)),
                    ValidIssuer      = "",
                    ValidateIssuer   = false,
                    ValidAudience    = "",
                    ValidateAudience = false
                };
            });
            services.AddMvc().AddJsonOptions(opt =>
            {
                opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                opt.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            });
            services.AddScoped <KullaniciAktiviteleriniTakipEt>();
        }
Beispiel #2
0
 public static IServiceCollection AddDbContexts(this IServiceCollection services, bool useSqLite, string baglantiSatiri, ApiTercihleri tercihler)
 {
     AddApplicationDbContext(services, useSqLite, baglantiSatiri);
     AddSoruDepoDbContext(services, useSqLite, baglantiSatiri);
     AddPsgContext(services, useSqLite, baglantiSatiri);
     return(services);
 }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            bool useSqLite = false;

            bool.TryParse(Configuration["Data:useSqLite"], out useSqLite);
            string baglantiSatiri = useSqLite ? Configuration["Data:SqlLiteConnectionString"] : Configuration["Data:SqlServerConnectionString"];

            services.AddAutoMapper();
            services.Configure <CloudinarySettings>(Configuration.GetSection("CloudinarySettings"));
            services.Configure <FotografAyarlari>(Configuration.GetSection("FotografAyarlari"));
            services.Configure <ApiTercihleri>(Configuration.GetSection("ApiTercihleri"));
            services.Configure <JwtIssuerOptions>(Configuration.GetSection("JwtIssuerOptions"));
            services.Configure <FacebookAuthSettings>(Configuration.GetSection("FacebookAuthSettings"));
            services.Configure <EpostaHesapBilgileri>(Configuration.GetSection("SistemPostaHesapBilgileri"));
            services.Configure <SMSHesapBilgileri>(Configuration.GetSection("SistemSMSHesapBilgileri"));



            var sp = services.BuildServiceProvider();

            Tercihler = sp.GetService <IOptions <ApiTercihleri> >().Value;


            services.AddTransient <IEmailSender, PostaciKit>();
            services.AddTransient <IPropertyMappingService, PropertyMappingService>();
            services.AddTransient <ITypeHelperService, TypeHelperService>();
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IJwtFactory, JwtFactory>();
            services.AddScoped <IUrlHelper, UrlHelper>(implementationFactory =>
            {
                var actionContext = implementationFactory.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });

            services.AddDbContexts(useSqLite, baglantiSatiri, Tercihler);

            if (Tercihler.AspNetCoreIdentityKullan)
            {
                services.AddMTIdentity(Configuration);
            }
            //services.AddTransient<KullaniciRepository>();

            services.AddApplicationRepositories();


            services.AddScoped <IUykuTestRepository, UykuTestRepository>();


            services.AddSoruRepositories();


            services.AddTransient <ISeederManager, SeederManager>();

            var uygulamaAyarlari = sp.GetService <IOptions <JwtIssuerOptions> >().Value;

            SymmetricSecurityKey _signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(uygulamaAyarlari.SecretKey));

            services.Configure <JwtIssuerOptions>(options =>
            {
                options.Issuer             = uygulamaAyarlari.Issuer;
                options.Audience           = uygulamaAyarlari.Audience;
                options.SigningCredentials = new SigningCredentials(_signingKey, SecurityAlgorithms.HmacSha256);
            });


            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = true,
                ValidIssuer    = uygulamaAyarlari.Issuer,

                ValidateAudience = true,
                ValidAudience    = uygulamaAyarlari.Audience,

                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = _signingKey,

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

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(configureOptions =>
            {
                configureOptions.ClaimsIssuer = uygulamaAyarlari.Issuer;
                configureOptions.TokenValidationParameters = tokenValidationParameters;
                configureOptions.SaveToken            = true;
                configureOptions.RequireHttpsMetadata = false;
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("ApiUser", policy => policy.RequireClaim(ClaimTypes.Role, "api_access"));
            });

            services.AddMvc().AddJsonOptions(opt =>
            {
                opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                opt.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            });
            services.AddScoped <KullaniciAktiviteleriniTakipEt>();
        }