Example #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)
        {
            //string defaultSqlConnectionString = Configuration.GetConnectionString("SqlServerConnection");
            //string defaultMySqlConnectionString = Configuration.GetConnectionString("MySqlConnection");

            RepositoryInjection.ConfigureRepository(services);
            BusinessInjection.ConfigureBusiness(services);
            services.AddMvc();
            services.AddSwaggerGen(m =>
            {
                m.SwaggerDoc("v1", new Info
                {
                    Description = "Light System WebApi",
                    Contact     = new Contact {
                        Email = "*****@*****.**", Name = "王杰光", Url = "http://www.jiqunar.com"
                    },
                    Version = "v1",
                    Title   = "LightAPI"
                });
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;//或者AppContext.BaseDirectory
                var xmlName  = this.GetType().GetTypeInfo().Module.Name.Replace(".dll", ".xml").Replace(".exe", ".xml");
                var xmlPath  = Path.Combine(basePath, xmlName);
                m.IncludeXmlComments(xmlPath);
            });
        }
Example #2
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)
        {
            //string defaultSqlConnectionString = Configuration.GetConnectionString("SqlServerConnection");
            string defaultMySqlConnectionString = Configuration.GetConnectionString("MySqlConnection");

            RepositoryInjection.ConfigureRepository(services);
            BusinessInjection.ConfigureBusiness(services);
            services.AddMvc();
            services.AddSwaggerGen(m =>
            {
                m.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "LightApi", Version = "v1", Description = "Light接口文档"
                });
            });
        }
Example #3
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));
            });
        }