Exemple #1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            config.Routes.MapHttpRoute(
                name: "swagger_root",
                routeTemplate: "",
                defaults: null,
                constraints: null,
                handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            // Injetor de dependências
            InjectorDependency.Iniciar();
            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(InjectorDependency.Container);
        }
Exemple #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.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);
        }
Exemple #3
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();
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // IoC
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(InjectorDependency.RegisterDependencies()));

            // AutoMapper
            AutoMapperConfig.RegisterMappings();
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        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();
        }