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

news/2024/9/19 0:09:12 标签: c#, 开发语言

这个框架分三部分,第一部分数据结构层,第二部分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.niftyadmin.cn/n/5664746.html

相关文章

Ai+若依(智能售货机运营管理系统---帝可得)--货道关联商品【08篇---0004:关联商品】

货道关联商品 需求 对智能售货机内部的货道进行商品摆放的管理 此功能涉及四个后端接口 查询设备类型&#xff08;已完成&#xff09; 查询货道列表&#xff08;待完成&#xff09; 查询商品列表&#xff08;已完成&#xff09; 货道关联商品&#xff08;待完成&#xff0…

迈入IT世界:技术趋势、职业选择与未来展望

迈入IT世界&#xff1a;技术趋势、职业选择与未来展望 1. 引言 随着科技的飞速发展&#xff0c;信息技术&#xff08;IT&#xff09;已经成为当今社会的中坚力量。无论是智能设备、互联网服务&#xff0c;还是数据分析与人工智能&#xff0c;IT技术驱动着各行各业的创新与进步…

基于node.js koa2模拟快递柜存储取出快递微信小程序

本文介绍了一个基于Node.js Koa2框架的快递柜存储和取出快递的微信小程序。首先&#xff0c;我们使用Koa2框架搭建了一个简单的后端服务器&#xff0c;用于处理微信小程序发送的请求。然后&#xff0c;我们实现了快递柜的存储和取出功能&#xff0c;用户可以通过微信小程序扫描…

AttributeError: ‘ComfyUIManagerLogger‘ object has no attribute ‘isatty‘

使用comfyui时可能会出现错误&#xff1a; /pretty_errors/init.py", line 4, in terminal_is_interactive sys.stderr.isatty() AttributeError: ComfyUIManagerLogger object has no attribute isatty 可能跟管理器的更新有关 解决方法&#xff1a; 改一下site-pac…

LCR 023

题目&#xff1a;LCR 023 解法一&#xff1a;哈希表 将链表A所有元素放入Set中&#xff0c;遍历链表B元素&#xff0c;若某一元素在Set中存在&#xff0c;则该元素便是重复元素 public ListNode getIntersectionNode(ListNode headA, ListNode headB) {Set<Object> set …

Spring Boot-Bean注入问题

在Spring Boot开发中&#xff0c;Bean的注入是核心概念之一&#xff0c;它确保了组件之间的依赖关系得以维护并方便管理。然而&#xff0c;在实际开发过程中&#xff0c;Bean的注入有时会出现问题 1. Spring Boot中的Bean注入 首先&#xff0c;了解Spring Boot中的Bean注入机…

CentOS详细解析及其配置方法

CentOS&#xff0c;作为一款基于Red Hat Enterprise Linux&#xff08;RHEL&#xff09;源代码构建的开源类服务器操作系统&#xff0c;自发布以来&#xff0c;凭借其卓越的稳定性、安全性和易用性&#xff0c;在企业级Linux发行版中占据了重要地位。以下是对CentOS的详细解析及…

linux-网络管理-网络抓包

Linux 网络管理&#xff1a;网络抓包 网络抓包是网络管理和分析中非常重要的技术。在 Linux 系统中&#xff0c;网络抓包可以帮助管理员和开发人员监控、分析和排查网络问题。抓包的过程指的是通过捕获网络接口上的数据包&#xff0c;查看其内容&#xff0c;从而帮助理解网络通…