Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = services.AddDbContext <ApplicationDbContext>(options =>
                                                                                options.UseSqlServer(Configuration.GetConnectionString("Development")));

            DataAccessRegistry.RegisterRepository(connectionString);

            // Add framework services. !!important to use mvc
            services.AddMvc();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Cors
            services.AddCors();


            services.AddLogging();

            services.AddDbContext <MilkManagementDbContext>(options =>
            {
                options.UseNpgsql(_hostingEnvironment.IsDevelopment()
                    ? Configuration.GetConnectionString("Development")
                    : Configuration.GetConnectionString("Production"));
                options.EnableSensitiveDataLogging();

                options.ConfigureWarnings(builder => builder.Throw());
            });
            DataAccessRegistry.RegisterRepository(services);
            ComponentAccessRegistry.RegisterServices(services);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "Milk Management Api",
                    Description    = "To Care of Financial situations of Milk Business",
                    TermsOfService = "None",
                    Contact        = new Contact {
                        Name = "Uzair Iqbal", Email = "*****@*****.**"
                    },
                    License = new License {
                        Name = "Under The Terms And Agreements Of IQBAL DAIRY FARM"
                    }
                });
            });
            services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.RequireHttpsMetadata = false;
                options.Authority            = "http://localhost:5003/";
                options.ApiName = "milkmanagement";
            });

            services.AddAutoMapper();

            services.AddMvc();
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <HahnDbContext>(opt =>
                                                  opt.UseInMemoryDatabase("Hahn"));

            services.AddLogging();

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version        = "v1",
                    Title          = "Hahn API",
                    Description    = "Hahn Test Api For Applicants Entry",
                    TermsOfService = new Uri("https://example.com/terms"),
                    Contact        = new OpenApiContact
                    {
                        Name  = "Abc Xyz",
                        Email = "*****@*****.**",
                        Url   = new Uri("https://twitter.com/AbcXyz"),
                    },
                    License = new OpenApiLicense
                    {
                        Name = "Use under LICX",
                        Url  = new Uri("https://example.com/license"),
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            ComponentAccessRegistry.RegisterServices(services);
            DataAccessRegistry.RegisterRepository(services);

            services.AddControllers();


            services.AddScoped <IValidator <ApplicantDto>, ApplicantValidator>();
            services.AddMvc()
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <ApplicantValidator>());
        }