Ejemplo n.º 1
0
        internal IDbConnection GetIDbConnection(string name)
        {
            //ConnectionStringSettings configuration = ConfigurationManager.ConnectionStrings[name];//.get_Item(name); -> Maneira Antiga de se Obter a Connection String em .net Framework
            ConnectionStringSettings configuration = ConnectionStringSettingsSingleton.Obter().connectionStringSettings;

            if (configuration == null)
            {
                throw new Exception($"Não foi possível criar uma conexão para a connectionstring ( {name} )");
            }
            if (GetKey(configuration) != "SYBASE")
            {
                return(CreateConnection(configuration));
            }
            return(this.GetConnectionSybase(configuration));
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IAuthorizationHandler, ValidJWTHandler>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddControllers();

            Mapeador.Mapeador.Obter().RegistrarMapeamentos();

            string connectionStringName         = Configuration.GetSection("ConnectionStringOptions:Name").Value;
            string connectionStringProviderName = Configuration.GetSection("ConnectionStringOptions:ProviderName").Value;
            string connectionString             = Configuration.GetSection("ConnectionStringOptions:ConnectionString").Value;

            ConnectionStringSettingsSingleton.Obter().setConnectionStringSettings(connectionStringName, connectionString, connectionStringProviderName);

            services.AddAuthorization(options =>
            {
                options.AddPolicy("JWT", policy =>
                                  policy.Requirements.Add(new ValidJWTRequirement()));
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "CSharpUsersAPI",
                    Version = "v1"
                });
                c.OrderActionsBy((apiDesc) => $"{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.HttpMethod}_{apiDesc.RelativePath}");
                c.AddSecurityDefinition("Bearer",
                                        new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme.",
                    Type        = SecuritySchemeType.Http,
                    Scheme      = "bearer"
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement {
                    {
                        new OpenApiSecurityScheme {
                            Reference = new OpenApiReference {
                                Id   = "Bearer",
                                Type = ReferenceType.SecurityScheme
                            }
                        }, new List <string>()
                    }
                });
            });

            services.AddHttpContextAccessor();

            services.AddCors();

            services.AddControllers()
            .AddJsonOptions(opts => opts.JsonSerializerOptions.PropertyNamingPolicy = null);

            services.AddHttpsRedirection(options =>
            {
                options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect;
                options.HttpsPort          = 443;
            });
        }