// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Data Contexts services.AddScoped <ISecurityDbContext, SecurityDbContext>(); services.AddDbContext <SecurityDbContext>(option => option.UseSqlServer(Configuration.GetConnectionString("CoreSecurityDB"))); // MVC Version services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Add Sessions services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // Injection Dependences IoCRegister.AddRegistration(services); // Swagger SwaggerConfig.AddRegistration(services); // Enable Cors services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <ITeleSoftDBContext, TeleSoftDBContext>(); services.AddDbContext <TeleSoftDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); IoCRegister.AddRegistration(services); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <TeleSoftDBContext>() .AddDefaultTokenProviders(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = "yourdomain.com", ValidAudience = "yourdomain.com", IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(Configuration["Llave_super_secreta"])), ClockSkew = TimeSpan.Zero }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <IManagementUserDBContext, ManagementUserDBContext>(); services.AddDbContext <ManagementUserDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); 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.AddDbContext <ProyectDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); //services.AddMvc();//Controllers(); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <ICoworkingDBContext, CoworkingDBContext>(); services.AddDbContext <CoworkingDBContext>( options => options.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddTransient<ICuentaRepository, CuentaRepository>(); //services.AddTransient<ITransaccionRepository, TransaccionRepository>(); services.AddDbContext <AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("con"))); services.AddControllers().AddNewtonsoftJson(); IoCRegister.AddRegistration(services); //se configura la app para la comunicacion con el front-end en Angular ya que el front pertenece a otro dominio services.AddCors(options => options.AddPolicy("AllowWebApp", builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <IPosDBContext, PosDBContext>(); services.AddDbContext <PosDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("POSConnDB"))); IoCRegister.AddRegistration(services); services.AddControllers(); //Allow Cors RG //https://www.youtube.com/watch?v=MBpH8sGqrMs services.AddCors(options => options.AddDefaultPolicy( builder => builder.AllowAnyOrigin() )); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IPruebaTredaDBContext, PruebaTredaDBContext>(); services.AddDbContext <PruebaTredaDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); IoCRegister.AddRegistration(services); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <ICoworkingDataContext, CoworkingDataContext>(); services.AddDbContext <CoworkingDataContext>(options => { //options.UseSqlServer(Configuration.GetConnectionString("DataBaseCoworking")); options.UseSqlite("Data Source=coworking.db"); }); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); 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.AddScoped <ISolutionDBContext, SolutionDBContext>(); services.AddDbContext <SolutionDBContext>(op => op.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); IoCRegister.AddRegistration(services); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <IBibliotecaDBContext, BibliotecaDBContext>(); services.AddDbContext <BibliotecaDBContext>(Options => Options.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); IoCRegister.AddRegistration(services); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(options => { options.AddPolicy("EnableCORS", builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials().Build(); }); }); }
/// <summary> /// ConfigureServices. /// </summary> /// <param name="services">Colección de servicios.</param> public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(); services.AddSwaggerGen(configuration => { ApplicationEnvironment appInfo = PlatformServices.Default.Application; List <string> xmlFiles = Directory.GetFiles(appInfo.ApplicationBasePath, "*.xml", SearchOption.TopDirectoryOnly).ToList(); xmlFiles.ForEach(xmlFile => configuration.IncludeXmlComments(xmlFile)); configuration.SwaggerDoc("v1", new OpenApiInfo { Title = GlobalResource.SwaggerTitle, Version = "v1" }); }); services.AddSwaggerGenNewtonsoftSupport(); IoCRegister.AddRegistration(services); }
// 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_1); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // Inject Dependecies IoCRegister.AddRegistration(services); // JWT JwtAuthConfig.AddRegistration(services, this._configuration); // Cors CorsConfig.AddRegistration(services); //GraphQL GraphQLConfig.AddRegistration(services); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddTransient <IImagePickDbContext, ImagePickDbContext>(); services.AddDbContext <ImagePickDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))); IdentityConfig.CreateIdentityIfNotCreated(services); AuthenticationConfig.ConfigureAuthenticationSettings(services, Configuration); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); services.AddControllers(options => options.RespectBrowserAcceptHeader = true) .AddNewtonsoftJson(); }
public void ConfigureServices(IServiceCollection services) { //-------------- Configuration Database ----------------// services.AddDbContext <DataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); //-------------- DATABASE ----------------// services.AddScoped <IDataContext, DataContext>(); // -------REGISTER SERVICES ---------// IoCRegister.AddRegistration(services); services.AddControllersWithViews(); }
// 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_1); // Swagger SwaggerConfig.AddRegistration(services); // AutoMapper AutoMapperConfig.AddRegistration(services); // Inject Dependecies IoCRegister.AddRegistration(services); // JWT JwtAuthConfig.AddRegistration(services, _configuration); // Cors CorsConfig.AddRegistration(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <ICoworkingDBContext, CoworkingDBContext>(); IoCRegister.AddRegistration(services); services.AddDbContext <CoworkingDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); services.AddApplicationInsightsTelemetry(Configuration); SwaggerConfig.AddRegistration(services); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = "https://coworkingidentity.azurewebsites.net/"; options.RequireHttpsMetadata = false; options.ApiName = "api1"; }); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <ISolutionDBContext, SolutionDBContext>(); services.AddDbContext <SolutionDBContext>(op => op.UseSqlServer(Configuration.GetConnectionString("DataBaseConnection"))); //services.AddCors(options => //{ // options.AddPolicy("EnableCors", // builder => // { // builder // //.WithOrigins("http://localhost:4200") // .AllowAnyOrigin() // .AllowAnyHeader() // .AllowAnyMethod() // .AllowCredentials() // .Build(); // }); //}); services.AddCors(options => { options.AddPolicy(name: MyPolicy, builder => { builder.WithOrigins("http://localhost:4200") .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); //.WithHeaders(HeaderNames.ContentType, "x-custom-header") //.WithMethods("PUT", "DELETE", "GET", "OPTIONS"); }); }); IoCRegister.AddRegistration(services); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <HNomiContext>( options => options.UseMySql("Server=localhost;Database=hnomi;User=davidrgh;Password=0000;", mySqlOptions => { mySqlOptions.ServerVersion(new Version(5, 7, 17), ServerType.MySql); } )); services.AddCors(options => { options.AddDefaultPolicy( builder => { builder.WithOrigins("http://localhost:4200"); }); }); IoCRegister.AddRegistration(services); SwaggerConfig.AddRegistration(services); 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) { IoCRegister.AddRegistration(services, Configuration.GetConnectionString("DataBaseConnection")); SwaggerConfig.AddRegistration(services); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IWebHostEnvironment env) { // loggerFactory.AddFile(Configuration["Logging:Path"]); IoCRegister.AddRegistration(app, env); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { IoCRegister.AddRegistration(services, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { IoCRegister.AddRegistration(services); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])), ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Issuer"], ClockSkew = TimeSpan.Zero }; }); services.AddMvcCore() .AddAuthorization() .AddApiExplorer() .AddMvcOptions(option => { option.EnableEndpointRouting = false; option.Filters.Add(new ModelStateCheckFilter()); }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.Converters.Add(new TimeSpanToStringConverter()); }); services.AddCors(options => { options.AddPolicy(name: MyAllowSpecificOrigins, builder => { builder.WithOrigins("http://localhost:3000") .AllowAnyHeader() .AllowAnyMethod(); //.WithMethods("POST","PUT", "DELETE", "GET"); }); }); services.AddSingleton <IAuthorizationPolicyProvider, PermissionApiJwtPolicyProvider>(); services.AddSingleton <IAuthorizationHandler, PermissionApiJwtAuthorizationHandler>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Toka API", 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>() } }); ////Obtenemos el directorio actual //var basePath = AppContext.BaseDirectory; ////Obtenemos el nombre de la dll por medio de reflexión //var assemblyName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; ////Al nombre del assembly le agregamos la extensión xml //var fileName = System.IO.Path.GetFileName(assemblyName + ".xml"); ////Agregamos el Path, es importante utilizar el comando //// Path.Combine ya que entre windows y linux son diferentes las rutas de los archivos //// En windows es por ejemplo c:/Uusuarios con / //// y en linux es \usr con \ //var xmlPath = Path.Combine(basePath, fileName); //c.IncludeXmlComments(xmlPath); }); services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; // This is the setting options.SuppressConsumesConstraintForFormFileParameters = true; options.SuppressInferBindingSourcesForParameters = true; options.SuppressModelStateInvalidFilter = true; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Data Contexts services.AddScoped <ICoreDbContext, CoreDbContext>(); services.AddDbContext <CoreDbContext>(option => option.UseSqlServer(Configuration.GetConnectionString("CoreSecurityDB"))); // Header services.Configure <ForwardedHeadersOptions>(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; }); // Add Sessions services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // Enable Cors services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() .Build() ); }); // JWT services.AddAuthorization(option => { option.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["JWT:Issuer"], ValidAudience = Configuration["JWT:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Key"])) }; }); // Injection Dependences IoCRegister.AddRegistration(services); // Swagger SwaggerConfig.AddRegistration(services); // AutoMapper services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); // MVC Version services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// 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); IoCRegister.AddRegistration(services); }