Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "HRM API V1");
                c.RoutePrefix = string.Empty;
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseMiddleware(typeof(GlobalExceptionHandler));
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                endpoints.MapControllers();
                endpoints.MapODataRoute("odata", "odata", ServicesInjections.GetEdmModel());
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Response data as XML or JSON based on request url.
            services.AddControllers().AddXmlDataContractSerializerFormatters();


            services.AddControllers().SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });
            //sqlserver database register
            services.AddDbContext <HRMDbContext>(a => a.UseSqlServer(Configuration.GetConnectionString("HRMDbConnection_2")));

            //registering all repositories
            RepositoryInjections.InjectRepositories(services);

            //registering all Services
            ServicesInjections.InjectServices(services);

            //registering Mapper
            services.AddAutoMapper(Assembly.GetAssembly(typeof(MappingProfiles)));

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "HRM API", Version = "v1"
                });
            });

            services.AddOData();
        }