Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(option =>
            {
                option.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
            services.AddHttpsRedirection(option =>
            {
                option.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
                option.HttpsPort          = 5001;
            });
            services.AddDbContext <PomeloContext>(options => options.UseMySql(Configuration.GetConnectionString("mysqlConnection")));
            RepositoryInjection.ConfigureRepository(services);
            BusinessInjection.ConfigureBusiness(services);
            services.AddSingleton(Configuration);
            PropertyMappingInjection.MappingInjection(services);

            services.AddSwaggerGen(m =>
            {
                m.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "PomeloButterApi", Version = "v1", Description = "Pomelo接口文档"
                });
            });

            services.AddAutoMapper();

            BaseValidator.ConfigureEntityValidator(services);
            services.AddTransient <ITypeHelperService, TypeHelperService>();
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddScoped <IUrlHelper>(options =>
            {
                var actionContext = options.GetService <IActionContextAccessor>().ActionContext;
                return(new UrlHelper(actionContext));
            });
        }