当前位置: 首页 > article >正文

一种全新的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"]));
            }
        }

作者:蒋光洵


http://www.kler.cn/news/305302.html

相关文章:

  • opencv之傅里叶变换
  • ZYNQ FPGA自学笔记
  • 大屏可视化常用图标效果表达
  • OCR2.0--General OCR Theory
  • 先框架后历元还是先历元后框架?
  • elementui 单元格添加样式的两种方法
  • Web 创建设计
  • RabbitMQ(高阶使用)延时任务
  • 19. 删除链表的倒数第 N 个结点【 力扣(LeetCode) 】
  • 定时任务调用OpenFegin无token认证异常
  • LAMP+WordPress
  • 服务器运维面试题4
  • 【SpringBoot】调度和执行定时任务--Quartz(超详细)
  • Ubuntu 22.04.5 LTS 发布下载 - 现代化的企业与开源 Linux
  • 力扣移除元素(力扣题26)(插空找空位java)
  • Linux上使用touch修改文件时间属性的限制
  • 如何打造智能、高效、安全的智慧实验室
  • 【React源码解析】深入理解react时间切片和fiber架构
  • C++——智能指针
  • CH1-1 引论
  • Rust:Result 和 Error
  • 职场 Death Note
  • Uniapp + Vue3 + Vite +Uview + Pinia 实现提交订单以及支付功能(最新附源码保姆级)
  • MATLAB中who的用法
  • flink增量检查点启动恢复的时间是很久的,业务上不能接受,怎么处理
  • MySQL索引-聚簇索引和非聚簇索引
  • 【Python机器学习】循环神经网络(RNN)——传递数据并训练
  • flask中安全策略简要说明
  • 景联文科技:专业扫地机器人数据采集标注服务
  • C/C++动态库函数导出 windows