一种全新的webapi框架C#webmvc初步介绍

这个框架分三部分,第一部分数据结构层,第二部分http和业务管理以及sql层,第三部分加密层和工具类。

数据结构层分key和数据长度定义

public class Auth

{

Key

public string Id { get; set; }

MaxLength(50)

public string Username { get; set; }

MaxLength(50)

public string Authtest { get; set; }

}

http和业务管理以及sql层

url定义

Route("api/\[controller\]")

ApiController

public class AuthController : ControllerBase

{

HttpPost

sql使用linq方式

List<Hack> hacklist = _coreDbContext.Set<Hack>().Where(i => i.Username ==userid).ToList();

中间还有日志定义

logger.Warn

startup.cs

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();

services.AddMemoryCache();

services.AddSingleton<IQRCode, RaffQRCode>();

services.AddMvc();

services.Configure<PictureOptions>(Configuration.GetSection("PictureOptions"));

services.AddTransient<Microsoft.Extensions.Hosting.IHostedService, Job>();

}

// 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.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>

{

endpoints.MapControllers();

});

}

数据库连接选择以及实体类构建

public virtual DbSet<Auth> Auth { get; set; } //创建实体类添加Context中

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

{

if (!optionsBuilder.IsConfigured)

{

var builder = new ConfigurationBuilder()

.SetBasePath(Directory.GetCurrentDirectory())

.AddJsonFile("appsettings.json");

var config = builder.Build();

string database = config["database"];

if (database.Equals("mysql"))

optionsBuilder.UseMySQL(RSADecrypt("", config["source"]));

if(database.Equals("sqlserver"))

optionsBuilder.UseSqlServer(RSADecrypt("", config["source"]));

}

}

作者:蒋光洵

相关推荐
王伯安呢2 分钟前
Java开发环境配置入门指南
java·开发语言·jvm·eclipse·环境搭建·新手
·前路漫漫亦灿灿4 分钟前
C++-类型转换
开发语言·c++
Kyln.Wu20 分钟前
【python实用小脚本-205】[HR揭秘]手工党逐行查Bug的终结者|Python版代码质量“CT机”加速器(建议收藏)
开发语言·python·bug
计算机毕业设计木哥22 分钟前
Python毕业设计推荐:基于Django的饮食计划推荐与交流分享平台 饮食健康系统 健康食谱计划系统
开发语言·hadoop·spring boot·后端·python·django·课程设计
rockmelodies29 分钟前
Java安全体系深度研究:技术演进与攻防实践
java·开发语言·安全
OEC小胖胖31 分钟前
Next.js 介绍:为什么选择它来构建你的下一个 Web 应用?
开发语言·前端·web·next.js
代码栈上的思考39 分钟前
深入解析 Java 内存可见性问题:从现象到 volatile 解决方案
java·开发语言
坐吃山猪6 小时前
SpringBoot01-配置文件
java·开发语言
晚风(●•σ )6 小时前
C++语言程序设计——06 字符串
开发语言·c++
我叫汪枫7 小时前
《Java餐厅的待客之道:BIO, NIO, AIO三种服务模式的进化》
java·开发语言·nio