// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy(name: "AllowOrigin", configurePolicy: builder => builder.WithOrigins("htpp://localhost:3000")); }); var tokenOptions = Configuration.GetSection(key: "TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:4200"));//localhost default angular 4200 rect için 3000 }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(optins => { optins.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddDependencyResolvers(new Core.Utilities.IoC.ICoreModule[] { new BusinessModule() }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer( options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey) }; } ); services.AddAuthorization(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(); //services.AddSingleton<IProductService,ProductManager>(); //services.AddSingleton<IProductDal,EfProductDal>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); }
// This method gets called by the runtime. Use this method to add services to the container. /// <summary> /// /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddSwaggerGen(c => { c.IncludeXmlComments(Path.ChangeExtension(typeof(Startup).Assembly.Location, ".xml")); }); services.AddMediatR(Assembly.GetAssembly(typeof(SecuredOperation))); services.AddDependencyResolvers(new ICoreModule[] { new BusinessModule(), new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //services.AddSingleton<IProductService, ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); services.AddSwaggerGen(x => { x.SwaggerDoc("v1", new OpenApiInfo { Title = "ECommerce API", Description = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); ////Business Layer //services.AddSingleton<IGameService, GameManager>(); //services.AddSingleton<IGamerService, GamerManager>(); //services.AddSingleton<ICampaignService, CampaignManager>(); //services.AddSingleton<ISoldGameService, SoldGameManager>(); ////Dal Layer //services.AddSingleton<IGameDal, EfGameDal>(); //services.AddSingleton<IGamerDal, EfGamerDal>(); //services.AddSingleton<ICampaignDal, EfCampaignDal>(); //services.AddSingleton<ISoldGameDal, EfSoldGameDal>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers( new ICoreModule[] { new CoreModule() } ); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Autofac, Ninject, CastleWindsor, StructureMap, LightInject, DryInject -- > IoC Container //AOP bir methodun önünde veya sonunda, sen nasýl konfigure ettiysen çalýþan kod parçacýklarýna denir. //Autofac bu iþin en iyisi services.AddControllers(); //services.AddSingleton<IProductService,ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); //Geliþtirme (backend) ortamý ile Frontend ortamýndaki browser'lerdeki //web adreslerinin birbirine güvenmesi saðlanmalý services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); //CoreModule gibi Farklý moduleleri ekleyebileceðimiz yapýyý oluþturmuþ oluruz. //AspectModule, SecurityModule gibi services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //services.AddCors(options => //{ // options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://www.localhost:52468")); //}); // services.AddSwaggerGen(options => // { // options.SwaggerDoc("v2", new Microsoft.OpenApi.Models.OpenApiInfo // { // Title = "Place Info Service API", // Version = "v2", // Description = "Sample service for Learner", // }); // }); services.AddDbContext <FoodDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); services.AddCors(options => { options.AddPolicy("CorsPolicy", policy => { policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:3000"); }); }); // Token Islemlerinin ve Auth Islemlerinin Calismasi icin assagida app.UseAuthentication(); yazdik ve burada service ekledik; var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Autofac, Ninject, CastleWindsor, StructureMap, LightInject, DrtInject -->IoC Container //AOP //Postsharp (Ücretli) //Biri arka planda IProductService isterse ProductManager'i new leyip gönderiyor services.AddControllers(); //services.AddSingleton<IProductService, ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); //services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); //ServiceTool.Create(services); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //services.AddSingleton<ICarService, CarManager>(); //services.AddSingleton<ICarDal, EFCarDal>(); //services.AddSingleton<ICarColorService, CarColorManager>(); //services.AddSingleton<IColorDal, EFCarColorDal>(); //services.AddSingleton<ICarBrandService, CarBrandManager>(); //services.AddSingleton<IBrandDal, EFCarBrandDal>(); //services.AddSingleton<ICustomerService, CustomerManager>(); //services.AddSingleton<ICustomerDal, EFCustomerDal>(); //services.AddSingleton<IUserService, UserManager>(); //services.AddSingleton<IUserDal, EFUserDal>(); //services.AddSingleton<IRentalService, RentalManager>(); //services.AddSingleton<IRentalDal, EFRentalDal>(); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(); // if you need ICarService, give CarManager // services.AddSingleton<ICarService, CarManager>(); Autofac'le yapılandırıldı. // services.AddSingleton<ICarDal,EfCarDal>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //services.AddSingleton<IProductService,ProductManager>(); //services.AddSingleton<IProductDal,EfProductDal>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:3000")); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //AOP //AutoFac, Ninjet, CastleWindsor, StructureMap,LightInject, DryInject --> IoC Containers services.AddControllers(); //services.AddSwaggerGen(c => //{ // c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); //}); //services.AddSingleton<IProductService, ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Autofac = AOP kullanýyor, Ninject, CastleWinsdor, StructureMap, LightInject, DryInject --IoC Container //AOP - Bir metodun baþýnda, sonunda ve içinde hata veren //Postsharp services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:3000")); }); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); // services.AddSingleton<IProductService, ProductManager>(); // services.AddSingleton<IProductDal, EFProductDal>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddControllers(); services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Transient); services.AddTransient <ApplicationDbContext>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); services.AddCors(options => { options.AddPolicy(name: MyAllowSpecificOrigins, builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new IGlobalModule[] { new GlobalModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:4200")); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule(), }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); }); services.AddDbContext <BaseDbContext>(options => options.UseInMemoryDatabase(databaseName: "BoardGames")); var tokenOptions = _configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddControllers() .AddJsonOptions(opt => opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())) .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddDependencyResolvers(_configuration, new ICoreModule[] { new CoreModule(), new ServiceModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); ServiceTool.Create(services); //services.AddSingleton<ICarService,CarManager>(); //services.AddSingleton<ICarDal, EfCarDal>(); //services.AddSingleton<IBrandService, BrandManager>(); //services.AddSingleton<IBrandDal, EfBrandDal>(); //services.AddSingleton<IColorService, ColorManager>(); //services.AddSingleton<IColorDal, EfColorDal>(); //services.AddSingleton<ICustomerService, CustomerManager>(); //services.AddSingleton<ICustomerDal, EfCustomerDal>(); //services.AddSingleton<IRentalService, RentalManager>(); //services.AddSingleton<IRentalDal, EfRentalDal>(); //services.AddSingleton<IUserService, UserManager>(); //services.AddSingleton<IUserDal, EfUserDal>(); // services.AddSingleton<ICarImageDAL, EfCarImageDAL>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //AOP //Autofac, Ninject,CastleWindsor, StructureMap, LightInject, DryInject -->IoC Container //AOP //Postsharp services.AddControllers(); //services.AddSingleton<IProductService,ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.AllowAnyOrigin()); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors();//frontendden istek yapýnca sorun çýkmasýn diye yazdýk var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); /* * BUNU KULLANMIYORUZ ARTIK * * Bu kýsmý kaldýrýp bununla ayný iþi yapmasý için autofac kullandýk. Böylece projede baþka api gelse * bile autofac business katmanýnda olduðu için sorun yaþamayýz * * //birisi IProductService isterse arkaplanda bir ProductManager oluþtur ve onu ver * services.AddSingleton<IProductService,ProductManager>(); //burayý biz ekledik * //birisi IProductDal isterse arkaplanda bir EfProductDal oluþtur ve onu ver * services.AddSingleton<IProductDal, EfProductDal>(); //burayý biz ekledik */ }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Autofac, Ninject, CastleWindsor, StructureMap, LightInject, DryInject -->IoC Container //AoP services.AddControllers(); //services.AddSingleton<IPoductService, ProductManager>(); //services.AddSingleton<IProductDal, EfProductDal>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //Ýsteklere izin verilir services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:3000")); }); //JWT configuration var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); //services.AddMemoryCache(); //Bu sýnýf içerisinde eklenebilecek herhangi bir servisin(Örnek olarak bir üst satýrda AddMemoryCache), core seviyesinde tanýmlanabilmesi için yazýlan extension. services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. #region Not //Web apinin kendi içerisinde bir IoC yapýsý vardýr.Bana arka planda bir referans oluþtur demek kýsacasý IoC'ler bizim yerimize new'liyor biz diyorizki birisi senden //IProductService istersen ona arka planda ProductManager oluþtur onu ver demek.AddSingleton ayný tek bir instance'ý üretmeyi saglýyor içerisinde data tutmuyorsak //singleton kullanabiliriz.Kýsacasý bu þu demek biri Constructur'da IProductService isterse ona arka planda bir tane ProductManager new'i ver demek.Bu yapýyý daha //farklý bir mimariye taþýyor olacagýz bu mimarinin adý Autofac,Ninject,CastleWindsor,StructureMap,LightInject,DyrInject bunlar .net projelerinde aþagýdaki adamýn //yaptýgý harekti yapýyor bunlar daha .net 'de built in de IoC yapýsý yokken daha bu adamlar bu þekilde çalýþmak isteyenler için alt yapý sunuyor.Autofac bize AOP //imkani sunuyor o yüzden .net'in kendi IoC container'na Autofac enjekte edicez. //Autofact'te aþagýdaki yapýnýn aynýsý yapýyor.Bu IOC yapýlandýrmasýný hangi interface 'in karþýlýgý nedir þeklinde yapýlandýrmayý api kýsmýnda degil biraz daha //backend kýsmýnda yapmanýn(Business kýsmýnda yapýcaz) çok fazla avantajý var nedir bunlar mesela biz burda startup da yaparsak yarýn öbürgün bir tane daha api //eklersek veya bambaþka bir servis mimarisi eklersek bizim bütün konfigurasyonumuz api'de kalýyor aslýnda bu konfigurasyonu dogru yapmka için yerimiz burasý olmamalý. #endregion public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddCors(); #region Not //Bu kýsýmda bir bu sistemde Authentication olarak JwtBearerDefaults token kullanýlacak haberin olsun dedigimiz yer burasý yani biz Asp.net web apiye diyorizki //bu sistemde jwt kullanýlacak haberin olsun. //HttpContextAccessor aslýnda her yapýlan istekle ile ilgili oluþan context diyebiliriz yani bizim clientimiz bir istek yaptýgýnda o istegin baþlangýcýndan //bitiþine kadar yani istek request in yapýlmasýndan yanýt response verilmesine kadar ki süreçte o kullanýcýnýn o isteginin takip edilmesi iþlemini bu //HttpContextAccessor yapýyor. #endregion var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() // oluþturdugumuz modülleri "," atarak burda ekleyebiliriz }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddSingleton<IProductService, ProductManager>(); //services.AddSingleton<IProductDAL, EfProductDAL>(); //services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); //ServiceTool.Create(services); services.AddDependencyResolvers(new ICoreModule[] { new CoreModule() });//Baþka Modülleri de ekleyebilmek istiyorum. services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:3000")); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) }; }); services.AddDependecyResolvers(new ICoreModule[] { new CoreModule(), }); services.AddSwaggerDocumentation(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }