Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "WebApi_eProcure", Version = "v1"
                });
                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                c.OperationFilter <AddRequiredHeaderParameter>();
            });

            var configOptions = Configuration.GetSection("ConfigOptions").Get <ConfigOptions>();

            // This services add application setting services
            services.AddSingleton(configOptions);

            // This services add Database Context services
            services.AddDbContext <EProcurementContext>(options => options.UseSqlServer(configOptions.DefaultConnectionString));

            // This services add services from Application Core Project.
            AddCoreServices(services);

            // This services add ActionFilterAttribute services.
            AddActionFilterAttributeServices(services);

            // This services add AutoMapper services.
            ConfigureMapper.Init(services, Assembly.GetAssembly(typeof(Startup)));

            // This services add health and check url point
            services.AddHealthChecks();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureService.ConfigureDependenciesService(services);
            ConfigureRepository.ConfigureDependenciesRepository(services);
            ConfigureDataBase.ConfigureDependenciesDataBase(services, Configuration.GetConnectionString("aplicacoesDistribuidas"));

            // Configuration Mapper
            ConfigureMapper.ConfigureDependencieMapper(services);

            // Configuration JTW
            ConfigureJwt.ConfigureDependenciesJwt(services, Configuration);

            services.AddControllers();

            // Configuration Swagger
            services.AddSwaggerGen(swaggerGen =>
            {
                swaggerGen.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version        = "v1",
                    Title          = "API - Aplicação distribuídas",
                    Description    = "API para gerenciamento de CRUD de produto e usuários",
                    TermsOfService = new Uri("https://github.com/Maarkis/AplicacoesDistribuidasAPI"),
                    Contact        = new OpenApiContact
                    {
                        Name  = "Jean Markis",
                        Email = "*****@*****.**",
                        Url   = new Uri("https://github.com/Maarkis/AplicacoesDistribuidasAPI"),
                    }
                });

                swaggerGen.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "Token JWT",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey
                });

                swaggerGen.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme {
                            Reference = new OpenApiReference
                            {
                                Id   = "Bearer",
                                Type = ReferenceType.SecurityScheme
                            }
                        }, new List <string>()
                    }
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                swaggerGen.IncludeXmlComments(xmlPath);
            });

            // End Configuration Swagger
        }
Esempio n. 3
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     ConfigureMapper.Register();
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
Esempio n. 4
0
        private void MapInterfacesAndClasses(IServiceCollection services)
        {
            var mapper = ConfigureMapper.CreateMapper(new Mapper.WebApplication1Profile());

            services.AddSingleton(mapper);

            services.AddScoped <IEmployeeService, EmployeeService>();

            services.AddScoped <IUnitOfWork>(s => new UnitOfWork(s.GetService <SomeDbContext>()));
        }
Esempio n. 5
0
        protected void Application_Start()
        {
            CofigureDI.Configure();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var resourceConfig = new ResourceConfig();

            resourceConfig.PopulateResources().Wait();

            ConfigureMapper.Configure();
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            AddMvcWithDynamicCaseResolvers(services);
            LoadSecurity(services);
            LoadEventBus(services);
            LoadCommonServices(services);
            LoadAuditClient(services, GetAuditConfiguration());
            LoadContentService(services);
            services.AddAuthorizationServices();
            EnvironmentUtils.Configuration = Configuration;
            services.AddHostedService <CollateralMessageListener>();
            services.AddHostedService <ContentMessageListener>();
            services.AddHostedService <FinancialStatementsMessageListener>();
            DatabaseConfiguration <OfferDBContext>(services);
            var runningMode = Environment.GetEnvironmentVariable(EnvConst.RunningMode) ?? "normal";

            if (runningMode.ToLower().Equals("organization-unit-sync"))
            {
                using (var context = services.BuildServiceProvider().GetService <OfferDBContext>())
                {
                    for (int i = 0; i < 50; i++)
                    {
                        // Wait for DB to be ready to run OU Sync
                        if (DatabaseInitializer.IsReady(context))
                        {
                            services.AddHostedService <OrganizationUnitSync>();
                            break;
                        }
                        _logger.LogInformation("Database is still not ready. Waiting 5s to Load OU sync");
                        Thread.Sleep(5000);
                    }
                }
            }
            services.AddScoped <Calculator>();
            services.AddSingleton <OrganizationUnitSync>();
            services.AddScoped <CalculationServiceCalculator>();
            services.AddScoped <CalculatorProvider>();
            services.AddDmnRequestExtenderResolver();
            services.AddSwaggerGen();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "Offer API",
                    Description = "Offer API lets you initiate, track and execute offers for loans, deposits, credit facilities and current accounts. It provides simulation of conditions for potential products and services. The offer process it defined primarily by the nature of the product or  service being considered, but can include actions such as document checks, collateral allocation, credit assessments, underwriting decisions, regulatory and procedural checks, eligibility checks, the use of internal and external specialist services (such as evaluations and legal advice).",
                    Contact     = new OpenApiContact
                    {
                        Name  = "Slobodan Amidzic",
                        Email = "*****@*****.**",
                        Url   = new Uri("https://bankapi.net/docs/public/offerv2-getstarted.html")
                    }
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description =
                        "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.",
                    Name   = "Authorization",
                    In     = ParameterLocation.Header,
                    Type   = SecuritySchemeType.ApiKey,
                    Scheme = "Bearer"
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header,
                        },
                        new List <string>()
                    }
                });
                // c.DescribeAllEnumsAsStrings();
                c.CustomSchemaIds(x => x.FullName);
            });
            // services.UseAspNetCoreAuditLogServices(Configuration);
            services.AddSwaggerGenNewtonsoftSupport();

            AddCalculationService(services);
            AddHealthChecks <OfferDBContext>(services);
            var container = new ContainerBuilder();

            container.Populate(services);
            container.RegisterModule(new MediatorModule());
            container.RegisterModule(new ApplicationModule());
            ConfigureMapper.Configure(services.BuildServiceProvider());
            var result = new AutofacServiceProvider(container.Build());

            return(result);
        }