Esempio n. 1
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();
        }
Esempio 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.AddControllers();

            //Setup para configuração do Swagger
            SwaggerSetup.AddSwaggerSetup(services);

            //Setup para configuração do EF
            EntityFrameworkSetup.AddEntityFrameworkSetup(services, Configuration);

            //Setup para o JWT
            JwtBearerSetup.AddJwtBearerSetup(services, Configuration);

            //Setup para MongoDB
            MongoDbSetup.AddMongoDbSetup(services, Configuration);

            //Injecao de dependencia
            DependenxyInjection.Register(services);

            //Setup para MediatR
            MediatRSetup.AddMediatRSetup(services);

            //Setup para AutoMapper
            AutoMapperSetup.AddAutoMapperSetup(services);

            //Setup para o CORS
            CorsSetup.AddCorsSetup(services);
        }
Esempio n. 3
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton(Configuration);
     AutoMapperSetup.AddAutoMapperSetup(services);
     SwaggerSetup.AddSwaggerSetup(services);
     DependencyInjectionSetup.AddDependencyInjectionSetup(services, Configuration);
     ApiSetup.AddApiSetup(services, Configuration);
 }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            EntityFrameworkSetup.AddEntityFrameworkSetup(services, Configuration);

            DependencyInjection.Register(services);

            AutoMapperSetup.AddAutoMapperSetup(services);

            CorsSetup.AddCorsSetup(services);

            SwaggerSetup.AddSwaggerSetup(services);
        }
Esempio n. 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Ativando o uso de cache via Redis
            services.AddDistributedRedisCache(options =>
            {
                options.Configuration =
                    Configuration.GetConnectionString("ConexaoRedis");
                options.InstanceName = "TesteRedisCache";
            });

            services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddDbContext <DataContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("connectionString")));

            services.AddScoped <IAuthorRepository, AuthorRepository>();
            services.AddScoped <IBookRepository, BooksRepository>();
            services.AddScoped <ICacheRepository, CacheRepository>();

            services.AddScoped <AuthorHandler, AuthorHandler>();
            services.AddScoped <BooksHandler, BooksHandler>();

            services.AddScoped <IMediatorHandler, RabbitMQueue>();
            services.AddScoped <IAuthorQueries, AuthorQueries>();
            services.AddScoped <IBookQueries, BookQueries>();

            services.AddScoped <ICacheService, CacheService>();

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


            //  IMapper mapper = mappingConfig.CreateMapper();
            // services.AddSingleton(mapper);

            //Setup para Swagger
            SwaggerSetup.AddSwaggerSetup(services);

            //Setup para AutoMapper
            AutoMapperSetup.AddAutoMapperSetup(services);
        }
Esempio n. 6
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     //setup para configuração Swagger..
     SwaggerSetup.AddSwaggerSetup(services);
     //setup para configuração do EntityFramework..
     EntityFrameworkSetup.AddEntityFrameworkSetup(services, Configuration);
     //setup para configuração de injeção de dependencia..
     InjecaoDependencia.Registrar(services);
     //setup para JWT Bearer..
     JwtBearerSetup.AddJwtBearerSetup(services, Configuration);
     //setup para MongoDB..
     MongoDBSetup.AddMongoDBSetup(services, Configuration);
     //setup para MediatR..
     MediatRSetup.AddMediatRSetup(services);
     //setup para AutoMapper..
     AutoMapperSetup.AddAutoMapperSetup(services);
     //Setup para o Cors
     CorsSetup.AddCorsSetup(services);
 }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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_2);

            // AutoMapper注入
            AutoMapperSetup.AddAutoMapperSetup(services);
            // .NET Core 原生依赖注入
            // 单写一层用来添加依赖项,可以将IoC与展示层 Presentation 隔离
            NativeInjectorBootStrapper.RegisterServices(services);

            // Adding MediatR for Domain Events
            // 领域命令、领域事件等注入
            // 引用包 MediatR.Extensions.Microsoft.DependencyInjection
            services.AddMediatR(typeof(Startup));
        }
Esempio n. 8
0
        public void SetUp()
        {
            serviceCollection = new ServiceCollection();

            AutoMapperSetup.AddAutoMapperSetup(serviceCollection);

            InjectionDependencies.RegisterDependencies(serviceCollection);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var calculoJurosService = serviceProvider.GetService <ICalculoJurosService>();

            _calculaJurosController = new CalculaJurosController(calculoJurosService);

            calculaJurosViewModelMock = Substitute.For <CalculaJurosViewModel>();
            calculaJurosViewModelMock.ValorInicial = 100;
            calculaJurosViewModelMock.TempoEmMeses = 5;

            calculoJuros    = "105,10";
            resultadoOkMock = _calculaJurosController.Ok(new { success = true, data = calculoJuros });

            resultadoErroMock = new ObjectResult($"Erro ao calcular juros: O tempo em meses não pode ser negativo!");
        }