Ejemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options => { });

            services.AddApiVersioning(options =>
            {
                options.ApiVersionReader   = new QueryStringApiVersionReader();
                options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
                options.ReportApiVersions  = true;
            });

            string       tokenType    = null;
            ApiKeyScheme apiKeyScheme = null;

            string projectName        = "Vasconcellos Cars WebAPI";
            string projectDescription = "This project has the purpose of performing an exemplification";

            var swaggerConfigurationExtension = new SwaggerStartupConfigureServices(services, tokenType, apiKeyScheme)
                                                .SetProjectNameAndDescriptionn(projectName, projectDescription);
        }
Ejemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options => { });

            services.AddSingleton(typeof(IGeneric <>), typeof(RepositoryGeneric <>));
            services.AddSingleton <IAirPlane, RepositoryAirPlane>();
            services.AddSingleton <IAirPlaneModel, RepositoryAirPlaneModel>();
            services.AddSingleton <IAppAirPlane, AppAirPlane>();
            services.AddSingleton <IAppAirPlaneModel, AppAirPlaneModel>();


            services.AddApiVersioning(options =>
            {
                options.ApiVersionReader   = new QueryStringApiVersionReader();
                options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
                options.ReportApiVersions  = true;
            });

            var swaggerConfigurationExtension = new SwaggerStartupConfigureServices(services, tokenType: null, apiKeyScheme: null)
                                                .SetProjectNameAndDescriptionn(projectName: "Air Plane WebAPI", projectDescription: "This project has the purpose of performing an exemplification");
        }
        /// <summary>
        /// ConfigureServices
        /// </summary>
        /// <remarks>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </remarks>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddControllers();

            services.AddApiVersioning(options =>
            {
                options.ApiVersionReader   = new QueryStringApiVersionReader();
                options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
                options.ReportApiVersions  = true;
            });

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    RequireExpirationTime    = false,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration.IssuerToken,
                    ValidAudience    = Configuration.AudienceToken,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.SymmetricSecurityKey))
                };
            });

            var swaggerConfigurationExtension = new SwaggerStartupConfigureServices(services, true)
                                                .SetProjectNameAndDescriptionn(Configuration.ProjectName, Configuration.ProjectDescription);

            services.Configure <MvcOptions>(options =>
            {
                //options.Filters.Add(new RequireHttpsAttribute()); //Need an SSL certificate to be uncommented
            });
        }