コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Injetar dependência
            InjencaoDependencia.InjetarDependencia(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.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)
        {
            // Injetar dependência
            InjencaoDependencia.InjetarDependencia(services);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSwaggerGen(opt =>
            {
                opt.SwaggerDoc("v1", new Info
                {
                    Title       = "TodoAPI",
                    Version     = "v1",
                    Description = "Um exemplo de aplicação ASP.NET Core Web API"
                });

                // Gera documentação, ou seja, quando criar um Summary na API aparecerá no Swagger
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                opt.IncludeXmlComments(xmlPath);

                // Autorização de acesso para as APIs no Swagger
                var security = new Dictionary <string, IEnumerable <string> >
                {
                    { "Bearer", new string[] { } },
                };

                opt.AddSecurityDefinition(
                    "Bearer",
                    new ApiKeyScheme
                {
                    In          = "header",
                    Description = "Copie 'Bearer ' + token'",
                    Name        = "Authorization",
                    Type        = "apiKey"
                });

                opt.AddSecurityRequirement(security);
            });
        }