// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddEntityFrameworkSqlServer() .AddDbContext <BaseContexto>( options => options.UseSqlServer( Configuration.GetConnectionString("BaseDatabase"))); InjectorDependencies.Registrer(services); services.AddAutoMapper(x => x.AddProfile(new BaseMapping())); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "API", Description = "", Contact = new OpenApiContact { Name = "Igor Andrade", Email = string.Empty } }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration.GetConnectionString("default"); services.AddDbContext <SqlContext>(options => { options.UseSqlServer(connection); options.EnableSensitiveDataLogging(); }); InjectorDependencies.Register(services); services.AddAutoMapper(x => x.AddProfile(new MappingEntity())); services.AddCors(); services.AddControllers(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); var key = Encoding.ASCII.GetBytes(Settings.Secret); 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(key), ValidateIssuer = false, ValidateAudience = false }; }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API Anúncios", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = SecuritySchemeType.ApiKey }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] { } } }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <Context>(o => o.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Users;Trusted_Connection=True;MultipleActiveResultSets=true")); InjectorDependencies.Registrar(services); services.AddScoped <ConsumerService>(); services.AddMassTransit(c => { c.AddConsumer <ConsumerService>(); }); services.AddSingleton(provider => Bus.Factory.CreateUsingRabbitMq( cfg => { var host = cfg.Host(new Uri("amqp://*****:*****@prawn.rmq.cloudamqp.com/bnydqltr"), "/", h => { }); cfg.ReceiveEndpoint(host, "document-service", e => { e.PrefetchCount = 16; e.LoadFrom(provider); EndpointConvention.Map <ConsumerService>(e.InputAddress); }); })); services.AddSingleton <IBus>(provider => provider.GetRequiredService <IBusControl>()); services.AddSingleton <IHostedService, BusService>(); Register(); services.AddAutoMapper(typeof(MappingEntity)); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Cadastro de usuários", Version = "v1" }); }); services.AddCors(options => { options.AddPolicy("AllowDev", builder => builder.WithOrigins("*").AllowAnyHeader() .AllowAnyMethod() ); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddEntityFrameworkSqlServer() .AddDbContext <BaseContexto>( options => options.UseSqlServer( Configuration.GetConnectionString("BaseDatabase"))); InjectorDependencies.Registrer(services); services.AddAutoMapper(x => x.AddProfile(new BaseMapping())); services.AddMvc(); services.AddControllers().AddNewtonsoftJson(); ConfigureAuth(services); ConfigureSwagger(services); }