コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.

        public void ConfigureServices(IServiceCollection services)
        {
            // Context

            services.AddDbContextPool <ContextIplanRio>(option =>
                                                        option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                                        );

            // IoC

            InjectorDependency.Register(services);

            // AutoMapper

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingEntities());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Context

            services.AddDbContext <ToBrasilContext>(options => options.UseInMemoryDatabase(databaseName: "ToBrasil"));

            // IoC

            InjectorDependency.Register(services);

            // AutoMapper

            services.AddAutoMapper(x => x.AddProfile(new Mapping()));

            // JWT

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                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"]))
                };

                options.Events = new JwtBearerEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        Console.WriteLine("Não autorizado" + context.Exception.Message);
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = context =>
                    {
                        Console.WriteLine("Sessão inválida" + context.SecurityToken);
                        return(Task.CompletedTask);
                    }
                };
            });

            // Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "TO Brasil API",
                    Description = "API de Desafio para Desenvolvedor .NET da TO Brasil",
                    Version     = "v1"
                });
            });

            services.AddControllers();
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: charlesmendes13/Called
        public void ConfigureServices(IServiceCollection services)
        {
            // Context

            services.AddDbContext <IdentityContext>(option =>
                                                    option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                                    );

            // Identity

            services.AddIdentity <User, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 3;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
            })
            .AddEntityFrameworkStores <IdentityContext>();

            // IoC

            InjectorDependency.Register(services);

            // AutoMapper

            services.AddAutoMapper(x => x.AddProfile(new MappingProfile()));

            // JWT

            services.Configure <AudienceConfiguration>(Configuration.GetSection("Audience"));

            // Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "Microservice Identity",
                    Description = "Microservice of Identity",
                    Version     = "v1"
                });
            });

            // Fluent Validation

            services.AddControllers().AddFluentValidation();
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: charlesmendes13/Called
        public void ConfigureServices(IServiceCollection services)
        {
            // Context

            services.AddDbContext <AttemdanceContext>(option =>
                                                      option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                                      );

            // RabbitMQ

            services.AddOptions();

            services.Configure <RabbitMqConfiguration>(Configuration.GetSection("RabbitMq"));

            // Email

            services.Configure <EmailConfiguration>(Configuration.GetSection("Email"));

            // IoC

            InjectorDependency.Register(services);

            // Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "Microservice Attemdance",
                    Description = "Microservice of Attemdance",
                    Version     = "v1"
                });
            });

            services.AddControllers();
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: charlesmendes13/Triscal
        public void ConfigureServices(IServiceCollection services)
        {
            // ConnectionString

            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Context

            services.AddDbContextPool <TriscalContext>(option =>
                                                       option.UseSqlServer(connectionString)
                                                       );

            // IoC

            InjectorDependency.Register(services);

            // AutoMapper

            services.AddAutoMapper(x => x.AddProfile(new Mapping()));

            // Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "API Clientes",
                    Description = "API de Desafio para Desenvolvedor .NET da Triscal",
                    Version     = "v1"
                });
            });

            // FluentValidation

            services.AddControllers().AddFluentValidation();
        }
コード例 #6
0
ファイル: Startup.cs プロジェクト: charlesmendes13/Called
        public void ConfigureServices(IServiceCollection services)
        {
            // Context

            services.AddDbContext <CalledContext>(option =>
                                                  option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                                                  );

            // RabbitMQ

            services.AddOptions();

            services.Configure <RabbitMqConfiguration>(Configuration.GetSection("RabbitMq"));

            // IoC

            InjectorDependency.Register(services);

            // AutoMapper

            services.AddAutoMapper(x => x.AddProfile(new MappingProfile()));

            // JWT

            var audienceConfig = Configuration.GetSection("Audience");

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = "Token";
            })
            .AddJwtBearer("Token", options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer           = audienceConfig["Iss"],
                    ValidAudience         = audienceConfig["Aud"],
                    IssuerSigningKey      = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(audienceConfig["Secret"])),
                    ClockSkew             = TimeSpan.Zero,
                    RequireExpirationTime = true
                };
            });

            // Cors

            services.AddCors(o => o.AddPolicy("CorsPolicy", builder =>
            {
                builder
                .WithOrigins("https://localhost:12345")
                .AllowAnyHeader()
                .WithMethods("GET", "POST")
                .AllowCredentials();
            }));

            // WebSocket

            services.AddSignalR();

            // Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "Microservice Called",
                    Description = "Microservice of Called",
                    Version     = "v1"
                });
            });

            // Fluent Validation

            services.AddControllers().AddFluentValidation();
        }