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

embedded/2024/9/23 2:26:16/

这个框架分三部分,第一部分数据结构层,第二部分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"]));
            }
        }

作者:蒋光洵


http://www.ppmy.cn/embedded/115353.html

相关文章

蓝桥杯【物联网】零基础到国奖之路:八. RTC

蓝桥杯【物联网】零基础到国奖之路:八. RTC 第一节 RTC的基本知识第二节 CubeMX配置第三节 代码 第一节 RTC的基本知识 RTC是实时时钟&#xff0c;指可以想时钟一样输出实际时间的电子设备&#xff0c;一般会是集成电路&#xff0c;也被称为是时钟芯片。总之&#xff0c;RTC只…

深度学习02-pytorch-01-张量形状的改变

在 PyTorch 中&#xff0c;张量的形状&#xff08;或称为形状变换&#xff09;可以通过多种方式进行改变&#xff0c;这有助于数据的重新排列、打平、扩展或压缩。常用的操作包括 view(), reshape(), transpose(), unsqueeze(), squeeze(), 和 permute() 等等。下面将详细介绍这…

【java面经】Redis速记

目录 基本概念 string hash list set zset 常见问题及解决 缓存穿透 缓存击穿 缓存雪崩 Redis内存管理策略 noeviction allkeys-lru allkeys-random volatile-random volatile-ttl Redis持久化机制 RDB快照 AOF追加文件 Redis多线程特性 Redis应用场景 缓…

数据处理与统计分析篇-day08-apply()自定义函数与分组操作

一. 自定义函数 概述 当Pandas自带的API不能满足需求, 例如: 我们需要遍历的对Series中的每一条数据/DataFrame中的一列或一行数据做相同的自定义处理, 就可以使用Apply自定义函数 apply函数可以接收一个自定义函数, 可以将Series对象的逐个值或DataFrame的行/列数据传递给自…

用Python提取PowerPoint演示文稿中的音频和视频

将多种格式的媒体内容进行重新利用&#xff08;如PowerPoint演示中的音频和视频&#xff09;是非常有价值的。无论是创建独立的音频文件、提取视频以便在线分发&#xff0c;还是为了未来的使用需求进行资料归档&#xff0c;从演示文稿中提取这些媒体文件可以为多媒体内容的多次…

API 接入前的安全防线:注意事项全梳理

在当今数字化的商业环境中&#xff0c;API&#xff08;Application Programming Interface&#xff09;的广泛应用为企业带来了诸多便利&#xff0c;但同时也伴随着潜在的安全风险。在接入 API 之前&#xff0c;构建坚实的安全防线至关重要。以下是对 API 接入前安全注意事项的…

达梦disql支持上翻历史命令-安装rlwrap

time:2024/09/18 Author:skatexg 一、背景 DM安装完成后使用disql命令行&#xff0c;无法使用上下键引用历史命令&#xff0c;会出现“[[A[[A”的现象。这样的操作包括使用退格Backspace键&#xff0c;上下键&#xff0c;左右键等。解决这个问题&#xff0c;可以使用rlwrap工…

Python练习宝典:Day 1 - 选择题 - 基础知识

目录 一、踏上Python之旅二、Python语言基础三、流程控制语句四、序列的应用 一、踏上Python之旅 1.想要输出 I Love Python,应该使用()函数。 A.printf() B.print() C.println() D.Print()2.Python安装成功的标志是在控制台(终端)输入python/python3后,命令提示符变为: A.&…