Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext <DoenerOrderContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"));
            });
            services.AddDbContext <AppIdentityDbContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString("IdentityConnection"));
            });

            IdentitySetup.ConfigureService(services);
            JwtSetup.ConfigureService(services, Configuration);
            SwaggerSetup.ConfigureService(services);

            services.AddMediatR(typeof(CreateSupplierCommand).Assembly);
            services.AddValidatorsFromAssembly(typeof(CreateSupplierCommand).Assembly);
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>));

            ServiceSetup.ConfigureService(services);

            services.AddCors(options =>
                             options.AddPolicy("AllowAll", builder => { builder.WithOrigins("*").AllowAnyMethod(); })
                             );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            DatabaseSetup.AddDatabaseSetup(services, Configuration);
            IdentitySetup.AddIdentitySetup(services, Configuration);
            AuthenticationJwtSetup.AddAuthenticationJwtSetup(services, Configuration);
            AutoMapperSetup.AddAutoMapperSetup(services);
            DependencyInjectionSetup.AddDependencyInjectionSetup(services);
            SwaggerSetup.AddSwaggerSetup(services);

            // Determinar que a api vai chamar uma determinada controller
            services.AddMvc(options =>
            {
                // configuração que obrigar que seja informado uma autenticação
                // garante que todas as requests sejam autenticadas
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();

                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            // Configuração para não retorna referencia cicular no json
            .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddCors();
        }
Ejemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            //Set up database
            var databaseSetup = new DatabaseSetup(Configuration, services);

            databaseSetup.Configure();

            //Confirgure services (DI)
            var serviceSetup = new ServiceSetup(Configuration, services);

            serviceSetup.ConfigureBasic();
            serviceSetup.ConfigureAuthentication();
            serviceSetup.ConfigureServices();
            serviceSetup.ConfigureLogging();

            var identitySetup = new IdentitySetup(Configuration, services);

            identitySetup.Configure();

            var emailSetup = new EmailSetup(Configuration, services);

            emailSetup.Configure();

            services.AddApplicationInsightsTelemetry();
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            Console.WriteLine("Configure Start");

            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
                app.UseStatusCodePagesWithReExecute("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
                IdentityModelEventSource.ShowPII = true;
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            //START =-=-= DO NOT MODIFY UNLESS DISCUSSED USER AUTH IS HERE =-=-= START

            IdentitySetup.InitializeDatabase(app, Configuration);

            app.UseCors();

            app.UseIdentityServer();

            app.UseAuthentication();

            //END =-=-= DO NOT MODIFY UNLESS DISCUSSED USER AUTH IS HERE =-=-= END

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "CoEuS V1");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            Console.WriteLine("Configure End");
        }