示例#1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.UseSwaggerMiddleware(GetApiVersion(), "CLIENTES", "Api para cadastro e controle dos clientes.");

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .SetIsOriginAllowed((host) => true)
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials()
                                  );
            });

            services
            .AddMvc(opts =>
            {
                opts.Conventions.Add(new CommaSeparatedRouteConvention());
                opts.EnableEndpointRouting = false;
            })
            .SetCompatibilityVersion(CompatibilityVersion.Latest)
            .AddJsonOptions(options => options.JsonSerializerOptions.PropertyNameCaseInsensitive = true);

            var connectionString = Configuration.GetConnectionString("DefaultConnection");
            var domainName       = "Cliente";

            base.BaseConfiguration(services, connectionString, domainName);
            InjectorContainer.Register(services, connectionString, domainName);
        }
示例#2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            InjectorContainer.ServicesRegister(services, connectionString);
            AutoMapperConfiguration.Configure();

            services
            .AddCors()
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver())
            .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            var cultureInfo = new CultureInfo("pt-BR");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Title   = "Aeroporto Api",
                    Version = "v1"
                });
            });
        }
 protected void Application_Start()
 {
     DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(InjectorContainer.Register()));
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
示例#4
0
        public virtual void ConfigureServices(IServiceCollection services)
        {
            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.AddMediatR(typeof(BaseStartup));

            InjectorContainer.Register(services);
        }
示例#5
0
文件: Startup.cs 项目: pagimaxx/wevo
        /// <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)
        {
            //MVC e Fluent Validation
            services
            .AddMvc(options => {
                options.Filters.Add(new ApiExceptionFilter());
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>());

            //Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(Configuration["SwaggerVersion"].ToString(),
                             new Info
                {
                    Title          = Configuration["SwaggerTitle"].ToString(),
                    Version        = Configuration["SwaggerVersion"].ToString(),
                    Description    = Configuration["SwaggerDescription"].ToString(),
                    TermsOfService = "None",
                    Contact        = new Contact {
                        Name = Configuration["SwaggerContactName"].ToString(), Email = Configuration["SwaggerContactEmail"].ToString(), Url = Configuration["SwaggerContactUrl"].ToString()
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlMainPath = Path.Combine(AppContext.BaseDirectory, "Wevo.Api.xml");
                var xmlAppPath  = Path.Combine(AppContext.BaseDirectory, "Wevo.AppService.xml");
                c.IncludeXmlComments(xmlMainPath);
                c.IncludeXmlComments(xmlAppPath);
            });


            //Cors
            services.AddCors();

            //Lendo chaves no arquivo de configuracoes
            services.AddOptions();
            services.Configure <KeysConfig>(Configuration);

            //AutoMapper
            services.AddAutoMapper();

            //Injecao de dependencia nativa
            var ioc = new InjectorContainer();

            services = ioc.ObterScopo(services);

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //Adicionar a compressão ao servico
            services.AddResponseCompression();
        }
示例#6
0
        static void Main(string[] args)
        {
            InjectorContainer.InitIoC();

            Console.WriteLine("Antes do evento!");

            // Cria o usuário e dispara um evento printando o console com os dados do usuário
            var usuario = Usuario.Criar("*****@*****.**");

            Console.WriteLine("Depois do evento!");

            Console.ReadKey();
        }
示例#7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //MVC e Fluent Validation
            services
            .AddMvc(options => {
                options.Filters.Add(new ApiExceptionFilter());    //Tratamento das Exceptions
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>());

            //Swagger
            services.AddSwaggerGen(c => {
                c.SwaggerDoc(Configuration["SwaggerVersion"].ToString(),
                             new Info {
                    Title          = Configuration["SwaggerTitle"].ToString(),
                    Version        = Configuration["SwaggerVersion"].ToString(),
                    Description    = Configuration["SwaggerDescription"].ToString(),
                    TermsOfService = "None",
                    Contact        = new Contact {
                        Name = Configuration["SwaggerContactName"].ToString(), Email = Configuration["SwaggerContactEmail"].ToString(), Url = Configuration["SwaggerContactUrl"].ToString()
                    }
                });

                c.AddSecurityDefinition("Bearer", new ApiKeyScheme {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });

                c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > {
                    { "Bearer", Enumerable.Empty <string>() }
                });
            });

            //Autenticacao JWT - Json Web Token
            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme    = "JwtBearer";
            }).AddJwtBearer("JwtBearer", options => {
                var sec = Encoding.UTF8.GetBytes(Configuration["SecretKey"].ToString());

                options.TokenValidationParameters = new TokenValidationParameters {
                    ValidateAudience = false,
                    ValidAudience    = "The name of audience",
                    ValidateIssuer   = false,
                    ValidIssuer      = "The name of issuer",

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(sec),
                    ValidateLifetime         = true,
                };
            });

            //Cors
            services.AddCors();

            //Lendo chaves no arquivo de configuracoes
            services.AddOptions();
            services.Configure <KeysConfig>(Configuration);

            //AutoMapper
            services.AddAutoMapper();

            //Injecao de dependencia nativa
            var ioc = new InjectorContainer();

            services = ioc.ObterScopo(services);

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //Adicionar a compressão ao servico
            services.AddResponseCompression();
        }
示例#8
0
 public void InjectorContainerTest()
 {
     _kernel = new InjectorContainer();
 }
示例#9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // MVC and Fluent Validation
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>());

            // Swagger
            services.AddSwaggerGen(c => {
                c.SwaggerDoc(configurationRoot["SwaggerVersion"].ToString(),
                             new OpenApiInfo {
                    Title       = configurationRoot["SwaggerTitle"].ToString(),
                    Version     = configurationRoot["SwaggerVersion"].ToString(),
                    Description = configurationRoot["SwaggerDescription"].ToString(),
                    Contact     = new OpenApiContact {
                        Name  = configurationRoot["SwaggerContactName"].ToString(),
                        Email = configurationRoot["SwaggerContactEmail"].ToString(),
                        Url   = new Uri(configurationRoot["SwaggerContactUrl"].ToString())
                    }
                });
            });

            // Authentication JWT - Json Web Token
            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme    = "JwtBearer";
            }).AddJwtBearer("JwtBearer", options => {
                var sec = Encoding.UTF8.GetBytes(configurationRoot["SecretKey"].ToString());

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateAudience = false,
                    ValidAudience    = "The name of audience",
                    ValidateIssuer   = false,
                    ValidIssuer      = "The name of issuer",

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(sec),
                    ValidateLifetime         = true,
                };
            });

            // Cors
            services.AddCors();

            // Keys Configuration
            services.AddOptions();
            services.Configure <KeysConfig>(configurationRoot);

            // AutoMapper
            var     mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); });
            IMapper mapper        = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            // Inject dependency native
            var ioc = new InjectorContainer();

            services = ioc.GetScope(services);

            services.AddSingleton <IConfiguration>(configurationRoot);
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Data compression
            services.AddResponseCompression();
        }