.net core to create a database table through code

1.API

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using HYS.BT.AcitivityAppSrv;
using HYS.BT.AcitivityDomains;
using HYS.BT.Utils;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.Swagger;

namespace HYS.BT.AcitivityApi
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            AppSetting.SetAppSetting(Configuration.GetSection("ConfigurationInfo"));
        }

        public IConfiguration Configuration { get; }

        // 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_2);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); ;
            //  services.AddMvcCore().AddApiExplorer();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = "血检消息活动API", Version = "v1", Contact = new Contact() { Name = "好医生 John Lau", Email = "[email protected]" } });

                var basepath = System.AppContext.BaseDirectory;
                string[] arr = new string[] { "HYS.BT.AcitivityAppSrv.xml", "HYS.BT.AcitivityApi.xml" };

                foreach (var item in arr)
                {
                    var xmlpath = Path.Combine(basepath, item);
                    c.IncludeXmlComments(xmlpath);
                }
            });

            string[] urls = Configuration.GetSection("AllowedCors").Value.Split(",");
            services.AddCors(c => c.AddPolicy("AllowAllOrigin", bulid =>
            {
                bulid.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
            }));
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            // Enable middleware to serve generated Swagger as a JSON endpoint.


            app.UseCors("AllowAllOrigin");

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), 
            // specifying the Swagger JSON endpoint.
            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "血检消息活动API V1");
                //c.ShowRequestHeaders();
            });
            //app.UseMvc(routes =>
            //{
            //    routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
            //});
            app.UseMvc();
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/jasonlai2016/p/11069097.html