// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // IoC InjetorDependencias.Registrar(services); services.AddControllers(); // Polly services.AddHttpClient(Configuration["Api1:Instance"], c => { c.BaseAddress = new Uri(Configuration["Api1:Uri"]); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)) .AddPolicyHandler(GetRetryPolicy()); // Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Softplan API 2", Description = "API 2 do Desafio para Desenvolvedor Softplan", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <Contexto>(o => o.UseMySql(Configuration.GetConnectionString("CedroRestaurante"))); InjetorDependencias.Registrar(services); services.AddAutoMapper(x => x.AddProfile(new MappingEntidade())); services.AddMvc(); }
public void ConfigureServices(IServiceCollection services) { // Context services.AddDbContextPool <Contexto>(option => option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) ); // IoC InjetorDependencias.Registrar(services); // AutoMapper services.AddAutoMapper(x => x.AddProfile(new MappingEntities())); // JWT services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["iss"], ValidAudience = Configuration["aud"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecurityKey"])) }; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { Console.WriteLine("Token inválido... " + context.Exception.Message); return(Task.CompletedTask); }, OnTokenValidated = context => { Console.WriteLine("Token inválido... " + context.SecurityToken); return(Task.CompletedTask); } }; }); services.AddControllers(); // Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "MDC API", Description = "API de Teste para Desenvolvedor back-end", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <Contexto>(opt => opt.UseInMemoryDatabase(databaseName: "CotacaoDB")); InjetorDependencias.Registrar(services); services.AddAutoMapper(x => x.AddProfile(new MappingEntidade())); services.AddControllers(); }
public void ConfigureServices(IServiceCollection services) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json") .Build(); services.AddDbContext <AppDbContext>(o => o.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); InjetorDependencias.Registrar(services); //services.AddAutoMapper(x => x.AddProfile(new MappingEntidade())); services.AddAutoMapper(typeof(MappingEntidade).Assembly); #region token var key = System.Text.Encoding.ASCII.GetBytes(Settings.Secret); services.AddCors(); 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 }; }); #endregion final token #region Swagger services.AddSwaggerGen(c => { string caminhoAplicacao = PlatformServices.Default.Application.ApplicationBasePath; string nomeAplicacao = PlatformServices.Default.Application.ApplicationName; string caminhoDocumentacao = Path.Combine(caminhoAplicacao, $"{ nomeAplicacao}.xml"); c.IncludeXmlComments(caminhoDocumentacao); c.SwaggerDoc("v1", new Info { Title = "Erros da Squad1", Version = "v1" }); }); #endregion services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>(); InjetorDependencias.Registrar(services); services.AddAutoMapper(x => x.AddProfile(new MappingEntidade())); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(60); }); //Provide a secret key to Encrypt and Decrypt the Token var SecretKey = Encoding.ASCII.GetBytes("3x4c7s4135-4d3-201x"); //Configure JWT Token Authentication services.AddAuthentication(auth => { auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(token => { token.RequireHttpsMetadata = false; token.SaveToken = true; token.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(SecretKey), ValidateIssuer = true, ValidIssuer = "http://localhost:45092/", ValidateAudience = true, ValidAudience = "http://localhost:45092/", RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; }); 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.AddCors(options => { options.AddPolicy("EnableCORS", builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().Build(); }); }); services.AddDbContext <InstituicaoContext>(p => p.UseInMemoryDatabase("Teste2")); InjetorDependencias.Registra(services); services.AddAutoMapper(x => x.AddProfile(new MappingEntidade())); services.AddControllers(); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ContextoEFClientes>(o => o.UseSqlServer(this.Configuration.GetConnectionString("DefaultConnexion"))); InjetorDependencias.Registrar(services); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo() { Title = "Web-Api Air Liquede", Version = "Relase-" + DateTime.Now.ToString("yyyyMMdd"), }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //injeção do contexto para conexão com o Banco de Dados apontando a string de conexão para o arquivo appsetings.json services.AddDbContext <DatabaseContext>(options => options .UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))); //Injeção de todas dependências a partir do projeto IoC InjetorDependencias.Registrar(services); //Injeção de dependência do automapper services.AddAutoMapper(config => config.AddProfile(new MappingEntidade())); services.AddMvc(options => options.EnableEndpointRouting = false) .SetCompatibilityVersion(CompatibilityVersion.Latest); services.AddCors(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // IoC InjetorDependencias.Registrar(services); services.AddControllers(); // Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Softplan API 1", Description = "API 1 do Desafio para Desenvolvedor Softplan", Version = "v1" }); }); }
private static bool MainMenu() { var collection = new ServiceCollection(); InjetorDependencias.Registrar(collection); var serviceProvider = collection.BuildServiceProvider(); var calculadoraAppService = serviceProvider.GetService <ICalculadoraApp>(); Console.WriteLine("... Calculadora TesteDotNet ..."); Console.WriteLine("Escolha alguma operação: \n" + " 0 - Soma \n" + " 1 - Subtração \n" + " 2 - Multiplicação \n" + " 3 - Divisão \n" + " 4 - Soma ilimitada \n" + " 5 - Soma ilimitada de numeros pares \n" + " 6 - Média ilimitada \n" + " 7 - Criar arquivo de operações- Questão 13. \n" + " 8 - Ler arquivo criado e executar operações. Questão 14. \n" + " 9 - Limpar \n" + " 10 - Sair \n" + "*Observação: Digite os números separados por ';' como por exemplo: 10;30 \n" + "e para valores reais use ',' como por exemplo: 10,5;30,2\n\n" + "Sua opção: "); string opcao = Console.ReadLine(); int numOpcao; var isNumeric = int.TryParse(opcao, out numOpcao); if (isNumeric) { string valorDigitado; string resposta; switch (numOpcao) { case 0: Console.WriteLine("\n-- Opção 0: Soma -- \n Digite dois números para serem somados: \n" + " Ex.: 20;5 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.Soma(valorDigitado); ApresentaResposta(resposta); break; case 1: Console.WriteLine("\n-- Opção 1: Subtração --: \n Digite dois números para serem subtraídos: \n" + " Ex.: 20;5 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.Subtracao(valorDigitado); ApresentaResposta(resposta); break; case 2: Console.WriteLine("\n-- Opção 2: Multiplicacao -- \n Digite dois números para serem multiplicados: \n" + " Ex.: 20;5 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.Multiplicacao(valorDigitado); ApresentaResposta(resposta); break; case 3: Console.WriteLine("\nOpção 3 - Divisão: \n Digite dois números para serem divididos: \n" + " Ex.: 20;5 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.Divisao(valorDigitado); ApresentaResposta(resposta); break; case 4: Console.WriteLine("\nOpção 4 - Soma ilimitada: \n Digite dois ou mais números para serem somados: \n" + " Ex.: 20;5;10 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.SomaIlimitada(valorDigitado); ApresentaResposta(resposta); break; case 5: Console.WriteLine("\nOpção 5 - Soma ilimitada de numeros pares: \n Digite dois ou mais números para serem somados: \n" + " Ex.: 20;5;10 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.SomaIlimitada(valorDigitado); ApresentaResposta(resposta); break; case 6: Console.WriteLine("\nOpção 6 - Média ilimitada: \n Digite dois ou mais números para calcular a média: \n" + " Ex.: 20;5;10 \n\n Números: "); valorDigitado = Console.ReadLine(); resposta = calculadoraAppService.SomaIlimitada(valorDigitado); ApresentaResposta(resposta); break; case 7: Console.WriteLine("\nOpção 7 - Criar arquivo de operações. \n\n"); resposta = calculadoraAppService.CriarArquivo(); ApresentaResposta(resposta); break; case 8: Console.WriteLine("\nOpção 8 - Ler arquivo de operações. \n\n"); var leitura = calculadoraAppService.LerArquivo(); Console.WriteLine("--- Dicionário RESPOSTA --- \n\n"); foreach (var resp in leitura) { if (leitura.First().Key == resp.Key) { Console.WriteLine("Arquivo: " + resp.Key); Console.WriteLine("Conteúdo: " + resp.Value); } else { Console.WriteLine("Chave: " + resp.Key); ApresentaResposta("Valor: " + resp.Value + "\n\n"); } } Console.WriteLine("--------------------------- \n\n"); break; case 9: Console.Clear(); break; case 10: Environment.Exit(0); break; } Console.WriteLine("\n\nPressione qualquer tecla para continuar ou ESC para sair”"); ConsoleKeyInfo info = Console.ReadKey(true); if (info.Key == ConsoleKey.Escape) { Console.WriteLine("“Obrigado por utilizar nossa calculadora”"); Thread.Sleep(2000); Environment.Exit(0); } } else { Console.WriteLine("** Opção inválida. Tente novamente!"); } return(true); }