//bizim asp.net uygulamamızın yani apimizin servis bağınmlılıklarını(dependedency injection) eklediğimiz //yada araya girmesini istediğimiz servisleri eklediğimiz collection'dur public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) //genişletmek istediğimiz şeyi this ile veririz { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { module.Load(serviceCollection); } //İstediğimiz kadar modul ekleyebiliriz. return(ServiceTool.Create(serviceCollection)); }
//Servis bağımlılıkları ya da araya girmesini istediğimiz servisleri eklediğimiz koleksiyon public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); //Bütün injectionları toplayabileceğimiz yapı. }
public static void InstallCoreServices(this IServiceCollection services) { services.AddSingleton <ITokenHelper, JwtHelper>(); services.AddSingleton <IActiveUserService, UserJwtService>(); services.AddSingleton <Stopwatch>(); services.AddTransient(typeof(IRepository <>), typeof(EfRepository <,>)); services.AddTransient(typeof(IDataAccessRepository <>), typeof(EfDataAccessRepository <>)); ServiceTool.Create(services); }
//api servis bağımlılıkları yada araya girmesini istediklerimiz. public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); //istediğimiz kadar modulu buraya eklemeye imkan sağlıyor. }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) { // this neyi genişletmek istediğini söyler. foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) // her bir modül için modülü yükleyecek. { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); // ServiceTool olarak create ettik ve serviceCollection'ları parametre olarak geçebiliriz. }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); // core katmanı dahil olmak üzere bütün incektionları burdan yönetebiliyorum }
//Core katmanı da dahil olmak üzere ekleyeceğimiz bütün injectionları bir arada toplayabileceğimiz yapı public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection services, ICoreModule[] modules) { // this => neyi genişletmek istiyoz. onu yazıyoruz. foreach (var module in modules) { module.Load(services); // tüm modullerimi .net core'a eklemiş olacam } return(ServiceTool.Create(services)); }
public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) //core katmanındaki bütün injectionları bir araya toplayacağımız yer { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); }
public void InstallSerive(IServiceCollection services, IConfiguration configuration) { var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new AutoMapperProfile()); }); var mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); ServiceTool.Create(services); }
//genişletmek istediğimiz olayı this ile veririz, sonrasında gerekli parametreler verilebilir public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) { foreach (var module in modules) { //gönderilen servisler tek tek yüklendi module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection));//burada ise build edildi }
public static IServiceCollection AddDependencyResolvers (this IServiceCollection serviceCollection, ICoreModule[] modules) { //Verdiğimiz modulleri dönüp tek tek hepsini yüklüyoruz foreach (var module in modules) { module.Load(serviceCollection); } //ve en son hepsini create ediyoruz. return(ServiceTool.Create(serviceCollection)); }
{ //bu extension class ı aslında bir polimorfizmdir. ServiceCollection a AddDependencyResolvers özelliği kazandırıyoruz. public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, //extent ettiğimiz tip ICoreModule[] modules) { // IServiceCollection araya girmesini istediğimiz dependencyresolvers ları yani servis bağımlılıklarını eklediğimiz // koleksiyonun ta kendisidir. // normnalde bunları startup a yazıyorduk artık core a aldık. foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); }
public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) //neyi genişletmek istiyorsun? { foreach (var module in modules) { module.Load(serviceCollection); } return(ServiceTool.Create(serviceCollection)); //bizim core katmanıda dahıl olmak uzere ekleyecegımız butun extensionsları bır arada tutar. }
/// <summary> /// 检测服务是否启动 /// </summary> /// <param name="serviceName">服务名称</param> /// <returns>服务状态</returns> public int CheckServiceState(string serviceName) { try { var serviceState = ServiceTool.CheckServiceState(serviceName); return(serviceState); } catch (Exception e) { Console.WriteLine(@"获取服务状态错误,原因:" + e.Message); return(-1); } }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddCors(); TokenOptions tokenOptions = new TokenOptions { Audience = "*****@*****.**", Issuer = "*****@*****.**", AccessTokenExpiration = 10, SecurityKey = "mysupersecretkeymysupersecretkeymysupersecretkeymysupersecretkey" }; 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(), }); //constructor iproductservice isterse ona arka planda newlenmiş product manager ver //IOC Containerlar bizim için instance üretimi yapıyorlar örn Autofac //services.AddSingleton<IProductService, ProductManager>(); //services.AddSingleton<IProductDal, EFProductDal>(); // Add services to the collection ServiceTool.Create(services); services.AddOptions(); // Create a container-builder and register dependencies var builder = new ContainerBuilder(); builder.Populate(services); builder.RegisterModule(new AutofacBusinessModule()); AutofacContainer = builder.Build(); return(new AutofacServiceProvider(AutofacContainer)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); #region Aciklama //Autofac yapısını kullanacagımız için .NetCore kendi bağımlılık çözme işlemlerini kaldırdır. Bu işlemi Web Apinin Program.cs içinde tanımlaması yapıldı //BUS //services.AddSingleton<ICarService, CarManager>(); //services.AddSingleton<IColorService, ColorManager>(); //services.AddSingleton<IUserService, UserManager>(); //services.AddSingleton<IRentalService, RentalManager>(); //services.AddSingleton<ICustomerService, CustomerManager>(); //services.AddSingleton<IBrandService, BrandManager>(); ////DAL //services.AddSingleton<ICarDal, EfCarDal>(); //services.AddSingleton<IColorDal, EfColorDal>(); //services.AddSingleton<IUserDal, EfUserDal>(); //services.AddSingleton<IRentalDal, EfRentalDal>(); //services.AddSingleton<ICustomerDal, EfCustomerDal>(); //services.AddSingleton<IBrandDal, EfBrandDal>(); #endregion //services.AddCors(options => //{ // options.AddPolicy("AllowOrigin", // builder => builder.WithOrigins("http://localhost:3000")); //}); 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); }
// 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<IBrandService, BrandManager>(); //services.AddSingleton<IBrandDal, EfBrandDal>(); //services.AddSingleton<IColorService, ColorManager>(); //services.AddSingleton<IColorDal, EfColorDal>(); //services.AddSingleton<IUserService, UserManager>(); //services.AddSingleton<IUserDal, EfUserDal>(); //services.AddSingleton<ICustomerService, CustomerManager>(); //services.AddSingleton<ICustomerDal, EfCustomerDal>(); //services.AddSingleton<IRentalService, RentalManager>(); //services.AddSingleton<IRentalDal, EfRentalDal>(); //services.AddSingleton<ICarImageService, CarImageManager>(); //services.AddSingleton<ICarImageDal, EfCarImageDal>(); // 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 CoreModule[] { new CoreModule() }); }
public static IServiceCollection AddDependencyResolvers( this IServiceCollection services, ICoreModule[] modules) { //IServiceCollection'ı extend eden bır yapı //bunu kullanarak api tarafında butun merkezı operasyonları eklıyor olacagım //parametrelerde goruldugu gıbı merkezı modullerı burda array olarak vermıs oluyoruz foreach (var module in modules) { module.Load(services); //butun modullerımı bu şekilde yukluyorum } return(ServiceTool.Create(services)); //bu kısımda da ServiceTool vasıtasıyla servislerı yapılandırıyoruz. //Son olarak api tarafına ekleyıp bundan sonra işi bitircez.starup.cs de yanı s2v16 }
public void InstallService(IServiceCollection services, IConfiguration configuration) { services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddCors(options => options.AddDefaultPolicy(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); //services.AddCors(opt => //{ // opt.AddPolicy("XXX", builder => // { // builder.AllowAnyOrigin().WithHeaders(HeaderNames.ContentType, "x-custom-header"); // }); //}); ServiceTool.Create(services); }
// 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); }
public void InstallService(IServiceCollection services, IConfiguration configuration) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Api Servisi", Description = ".NET Core 5.0", Contact = new OpenApiContact { Name = "Demo Api Project", Url = new Uri("http://www.google.com"), } }); var securitySchema = new OpenApiSecurityScheme { Description = "JWT Yetkilendirme, Bearer Şeması kullanarak. Örneğin: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.Http, Scheme = "bearer", Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }; c.AddSecurityDefinition("Bearer", securitySchema); var securityRequirement = new OpenApiSecurityRequirement { { securitySchema, new[] { "Bearer" } } }; c.AddSecurityRequirement(securityRequirement); //c.OperationFilter<RequiredHeaderParameter>(); }); ServiceTool.Create(services); }
// 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.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); }); //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(), }); }
public static void InstallBusinessServices(this IServiceCollection service) { ServiceTool.Create(service); }
public static void InstallCoreServices(this IServiceCollection services) { services.AddTransient(typeof(IRepository <>), typeof(EfRepository <,>)); services.AddTransient(typeof(IDataAccessRepository <>), typeof(EfDataAccessRepository <>)); ServiceTool.Create(services); }
// 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" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = @"JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below. \r\n\r\nExample: 'Bearer 12345abcdef'", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() } }); }); services.AddCors(options => options.AddDefaultPolicy(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())); services.AddHttpContextAccessor(); services.AddAutoMapper(typeof(MappingProfile)); // services.AddDbContext<RentaCarContext>(options => // options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddControllers().AddNewtonsoftJson(opt => { opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.Configure <TokenOptions>(Configuration.GetSection("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() }); ServiceTool.Create(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetValue <string>("ConnectionString"); services.AddDbContext <ApplicationContext>(options => options.UseSqlServer(connectionString)); services.AddIdentity <User, Role>(options => { options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(1d); options.Lockout.MaxFailedAccessAttempts = 5; options.User.RequireUniqueEmail = true; }).AddEntityFrameworkStores <ApplicationContext>(); services.AddScoped <IApplicationDbContext, ApplicationContext>(); services.AddMvc().AddFluentValidation(); services.Configure <JwtSettings>(Configuration.GetSection("Jwt")); var jwtSettings = Configuration.GetSection("Jwt").Get <JwtSettings>(); services.AddTransient <ITokenGenerator, TokenGenerator>(); //services.AddAuthentication(x=>x.DefaultScheme ="JWT").AddJwtBearer( // options => // { // options.TokenValidationParameters = new TokenValidationParameters // { // ValidateIssuer = true, // ValidateAudience = true, // ValidateLifetime = true, // ValidIssuer = jwtSettings.Issuer, // ValidateIssuerSigningKey = true, // IssuerSigningKey =new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Secret)) // }; // }); services.AddTransient <IValidator <DeleteProductRequest>, DeleteProductValidator>(); services.AddTransient <IValidator <UpsertProductRequest>, UpsertProductValidator>(); services.AddTransient <IValidator <GetProductByNameRequest>, GetProductByNameValidator>(); services.AddTransient <IValidator <SignUpRequest>, SignUpValidator>(); services.AddMediatR(typeof(GetProductsRequestHandler)); services.AddMediatR(typeof(DeleteProductRequestHandler)); services.AddMediatR(typeof(UpsertProductRequestHandler)); services.AddMediatR(typeof(GetProductByNameRequestHandler)); services.AddMediatR(typeof(SignUpRequestHandler)); services.AddMediatR(typeof(SignInRequestHandler)); services.AddMediatR(typeof(AddUserToRoleRequestHandler)); services.AddMediatR(typeof(ForgetPasswordRequestHandler)); services.AddMediatR(typeof(UpdatePasswordRequestHandler)); services.AddApiVersioning(o => { o.DefaultApiVersion = new ApiVersion(1, 0); o.ReportApiVersions = true; o.ApiVersionReader = new HeaderApiVersionReader("x-monosign-api-version"); }); services.AddVersionedApiExplorer( options => { // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service // note: the specified format code will format the version as "'v'major[.minor][-status]" options.GroupNameFormat = "'v'VVV"; // note: this option is only necessary when versioning by url segment. the SubstitutionFormat // can also be used to control the format of the API version in route templates options.SubstituteApiVersionInUrl = true; }); services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>(); services.AddSwaggerGen( options => { // add a custom operation filter which sets default values options.OperationFilter <SwaggerDefaultValues>(); // integrate xml comments options.IncludeXmlComments(XmlCommentsFilePath); }); var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MapperProfile()); mc.AddProfile(new IdentityMapperProfile()); }); var mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); services.AddControllers(); ServiceTool.CreateService(services); services.AddAuth(jwtSettings); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // services.AddDbContext<MSSQLDbContext>(options => //options.UseSqlServer(Configuration.GetConnectionString("MSSQLDbContext"))); // services.AddControllers(); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.AddControllers(); //Singletons: { services.AddSingleton <IOrder, Entities.Concrete.Order>(); { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IOperationServices, OperationManager>(); services.AddSingleton <IOrderItemServices, OrderItemManager>(); services.AddSingleton <IOrderServices, OrderManager>(); services.AddSingleton <IProductServices, ProductManager>(); services.AddSingleton <IStockServices, StockManager>(); services.AddSingleton <ISubProductTreeServices, SubProductTreeManager>(); services.AddTransient <IUserServices, UserManager>(); services.AddSingleton <IWorkCenterOperationServices, WorkCenterOperationManager>(); services.AddSingleton <IWorkCenterServices, WorkCenterManager>(); services.AddTransient <IAuthServices, AuthManager>(); services.AddSingleton <ITokenHelper, JwtHelper>(); } { services.AddSingleton <IStockDAL, EfStockDAL>(); services.AddSingleton <IOperationDAL, EfOperationDAL>(); services.AddSingleton <IOrderDAL, EfOrderDAL>(); services.AddSingleton <IOrderItemDAL, EfOrderItemDAL>(); services.AddSingleton <IProductDAL, EfProductDAL>(); services.AddSingleton <IUserDAL, EfUserDAL>(); services.AddSingleton <IWorkCenterDAL, EfWorkCenterDAL>(); services.AddSingleton <IWorkCenterOperationDAL, EfWorkCenterOperationDAL>(); services.AddSingleton <ISubProductTreeDAL, EfSubProductTreeDAL>(); } } 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); }