2020年12月21日星期一

ASP.NET Core妙用分支路由MapWhen集成项目模型类赋值代码生成中间件

一、使用场景

  1.属性赋值

 

  2.对象初始化

 像以上两种情况,当属性字段较多,赋值就显得繁琐,这里可以使用app.MapWhen()方法创建路由分支构建独立无侵入式赋值代码生成。

二、项目/演示

  >public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } 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.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); // 开发环境下启用 app.UseCodeIntelligencing(typeof(UserEntity).Assembly, typeof(UserDTO).Assembly, typeof(UserModel).Assembly); //// 自定义路由分支 //app.UseCodeIntelligencing("/custom_path", options => //{ // options.Assemblies.Add(typeof(UserEntity).Assembly); // options.Assemblies.Add(typeof(UserDTO).Assembly); // options.Assemblies.Add(typeof(UserModel).Assembly); //}); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } }

  

 三、源码下载

 

CodeIntelligencing

 









原文转载:http://www.shaoqun.com/a/502466.html

跨境电商:https://www.ikjzd.com/

西集网:https://www.ikjzd.com/w/1353

mail.ru:https://www.ikjzd.com/w/2232


一、使用场景  1.属性赋值  2.对象初始化像以上两种情况,当属性字段较多,赋值就显得繁琐,这里可以使用app.MapWhen()方法创建路由分支构建独立无侵入式赋值代码生成。二、项目/演示 >publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIC
google趋势:google趋势
心怡:心怡
青岛世园会游览线路?青岛世界园艺博览会有索道吗?:青岛世园会游览线路?青岛世界园艺博览会有索道吗?
日本公布销量最高十款相机 索尼微单博得头筹:日本公布销量最高十款相机 索尼微单博得头筹
重庆丰都鬼城门票_丰都鬼城门票 :重庆丰都鬼城门票_丰都鬼城门票