西宁建设公司网站wordpress只有我可以看

news/2025/10/1 6:44:59/文章来源:
西宁建设公司网站,wordpress只有我可以看,百度网站优化 件,wordpress 初始化 数据库连接整个解决方案按照分层思想来划分不同功能模块#xff0c;以提供User服务的Api为需求#xff0c;各个层次的具体实现如下所示#xff1a; 1、新建数据库User表 数据库使用SQLExpress版本#xff0c;表的定义如下所示#xff1a; CREATE TABLE [dbo].[User] ([Id] …整个解决方案按照分层思想来划分不同功能模块以提供User服务的Api为需求各个层次的具体实现如下所示 1、新建数据库User表 数据库使用SQLExpress版本表的定义如下所示 CREATE TABLE [dbo].[User] ([Id] INT IDENTITY (1, 1) NOT NULL,[Name] NVARCHAR (50) NOT NULL,[Password] NVARCHAR (50) NOT NULL,[Age] INT NOT NULL,[Birthdate] DATE NOT NULL,[CreateTime] DATETIME DEFAULT (getdate()) NOT NULL,[CreateUserId] NVARCHAR (50) NOT NULL,[CreateUserName] NVARCHAR (50) NOT NULL,[ModifiedTime] DATETIME NULL,[ModifiedUserId] NVARCHAR (50) NULL,[ModifiedUserName] NVARCHAR (50) NULL,PRIMARY KEY CLUSTERED ([Id] ASC) ); 2、实体层 新建类库类型的项目.net framework框架版本4.5User实体类如下 public class User{public int Id { get; set; }public string Name { get; set; }public string Password { get; set; }public int Age { get; set; }public DateTime Birthdate { get; set; }public DateTime CreateTime { get; set; }public string CreateUserId { get; set; }public string CreateUserName { get; set; }public DateTime? ModifiedTime { get; set; }public string ModifiedUserId { get; set; }public string ModifiedUserName { get; set; }} 3、数据库层 该层提供数据库接口操作采用EntitFramework4.4.0.0作为ORM实体映射框架 定义数据库操作接口IRepository public interface IRepositoryTEntity : IDisposable where TEntity : class{IEnumerableTEntity Get();IEnumerableTEntity Get(ExpressionFuncTEntity, bool filter);IEnumerableTEntity GetTOderKey(ExpressionFuncTEntity, bool filter, int pageIndex, int pageSize, ExpressionFuncTEntity, TOderKey sortKeySelector, bool isAsc true);int Count(ExpressionFuncTEntity, bool predicate);void Update(TEntity instance);void Add(TEntity instance);void Delete(TEntity instance);} 定义数据库上下文类BceDbContext public class BceDbContext:DbContext{public BceDbContext():base(DaLeiDB){Database.SetInitializerAceDbContext(null);}public DbSetUser Users { get; set; }protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.EntityUser().ToTable(User);base.OnModelCreating(modelBuilder);}} 定义数据库通用操作实现类BceRepository public class BceRepositoryTEntity : IRepositoryTEntity where TEntity : class{public BceDbContext DbContext { get; private set; }public DbSetTEntity DbSet { get; private set; }public BceRepository(BceDbContext context){Guard.ArgumentNotNull(context, context);this.DbContext context;this.DbSet this.DbContext.SetTEntity();}public IEnumerableTEntity Get(){return this.DbSet.AsQueryable();}public IEnumerableTEntity Get(ExpressionFuncTEntity, bool filter){return this.DbSet.Where(filter).AsQueryable();}public IEnumerableTEntity GetTKey(ExpressionFuncTEntity, bool filter, int pageIndex, int pageSize, ExpressionFuncTEntity, TKey sortKeySelector, bool isAsc true){Guard.ArgumentNotNull(filter, predicate);Guard.ArgumentNotNull(sortKeySelector, sortKeySelector);if (isAsc){return this.DbSet.Where(filter).OrderBy(sortKeySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).AsQueryable();}else{return this.DbSet.Where(filter).OrderByDescending(sortKeySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).AsQueryable();}}public int Count(ExpressionFuncTEntity, bool predicate){return this.DbSet.Where(predicate).Count();}public void Add(TEntity instance){Guard.ArgumentNotNull(instance, instance);this.DbSet.Attach(instance);this.DbContext.Entry(instance).State EntityState.Added;this.DbContext.SaveChanges();}public void Update(TEntity instance){Guard.ArgumentNotNull(instance, instance);this.DbSet.Attach(instance);this.DbContext.Entry(instance).State EntityState.Modified;this.DbContext.SaveChanges();}public void Delete(TEntity instance){Guard.ArgumentNotNull(instance, instance);this.DbSet.Attach(instance);this.DbContext.Entry(instance).State EntityState.Deleted;this.DbContext.SaveChanges();}public void Dispose(){this.DbContext.Dispose();}} 定义用户表数据库操作额外的接口IUserRepository namespace DaLei.Repository {public interface IUserRepository{User FindByName(string name);ListUser FindByAge(int start, int end);} } 定义用户表数据库操作额外的实现类UserRepository namespace DaLei.Repository {public class UserRepository : BceRepositoryUser, IUserRepository{public UserRepository(BceDbContext bceDbContext):base(bceDbContext){}public ListUser FindByAge(int start, int end){var rst this.DbSet.AsQueryable().Where(uu.Agestart u.Ageend).ToList();return rst;}public User FindByName(string name){var rst this.DbSet.AsQueryable().Where(u u.Name name).FirstOrDefault();return rst;}} } 4、服务接口层 定义了对外提供用户服务的接口契约具体如下 namespace DaLei.IService {public interface IUserService{User FindByName(string name);ListUser FindByAge(int start, int end);ListUser GetList();} } 5、服务具体实现层 服务基类实现 using System; using System.Collections.Generic;namespace DaLei.Service {public abstract class ServiceBase : IDisposable{public IListIDisposable DisposableObjects { get; private set; }public ServiceBase(){this.DisposableObjects new ListIDisposable();}protected void AddDisposableObject(object obj){IDisposable disposable obj as IDisposable;if (null ! disposable){this.DisposableObjects.Add(disposable);}}public void Dispose(){foreach (IDisposable obj in this.DisposableObjects){if (null ! obj){obj.Dispose();}}}} } 用户服务接口具体实现 using DaLei.IService; using DaLei.Model; using DaLei.Repository; using System.Collections.Generic;namespace DaLei.Service {public class UserService : ServiceBase,IUserService{private IUserRepository userRepository;public UserService(IUserRepository userRepository){this.userRepository userRepository;this.AddDisposableObject(userRepository);}public ListUser FindByAge(int start, int end){return this.userRepository.FindByAge(start,end);}public User FindByName(string name){return this.userRepository.FindByName(name);}public ListUser GetList(){return this.userRepository.FindByAge(0, 100);}} }6、应用层 新建Asp.net WebApi项目引用服务接口项目、服务实现项目、实体类项目unity相关程序集EntityFramework程序集。 web.config配置连接字符串和unity相关内容 ?xml version1.0 encodingutf-8? !--有关如何配置 ASP.NET 应用程序的详细信息请访问https://go.microsoft.com/fwlink/?LinkId169433 -- configurationconfigSectionssection nameunity typeMicrosoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration //configSectionsunitysectionExtension typeMicrosoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration /containerscontainerextension typeInterception /register typeDaLei.IService.IUserService, DaLei.IService mapToDaLei.Service.UserService, DaLei.Service /register typeDaLei.Repository.IUserRepository, DaLei.Repository mapToDaLei.Repository.UserRepository, DaLei.Repositoryinterceptor typeInterfaceInterceptor /policyInjection //register/container/containers/unityconnectionStringsadd nameDaLeiDB connectionStringdata source.\SQLEXPRESS;Integrated SecuritySSPI;Initial CatalogDaleiDB;User IDsa;Passwordanpiel0991; providerNameSystem.Data.SqlClient //connectionStringsappSettingsadd keywebpages:Version value3.0.0.0/add keywebpages:Enabled valuefalse/add keyPreserveLoginUrl valuetrue/add keyClientValidationEnabled valuetrue/add keyUnobtrusiveJavaScriptEnabled valuetrue//appSettingssystem.webcompilation debugtrue targetFramework4.5/httpRuntime targetFramework4.5/pagesnamespacesadd namespaceSystem.Web.Helpers/add namespaceSystem.Web.Mvc/add namespaceSystem.Web.Mvc.Ajax/add namespaceSystem.Web.Mvc.Html/add namespaceSystem.Web.Routing/add namespaceSystem.Web.WebPages//namespaces /pages/system.websystem.webServervalidation validateIntegratedModeConfigurationfalse/handlersremove nameExtensionlessUrlHandler-Integrated-4.0/remove nameOPTIONSVerbHandler/remove nameTRACEVerbHandler/add nameExtensionlessUrlHandler-Integrated-4.0 path*. verb* typeSystem.Web.Handlers.TransferRequestHandlerpreConditionintegratedMode,runtimeVersionv4.0//handlers/system.webServerruntimeassemblyBinding xmlnsurn:schemas-microsoft-com:asm.v1dependentAssemblyassemblyIdentity nameNewtonsoft.Json cultureneutral publicKeyToken30ad4fe6b2a6aeed/bindingRedirect oldVersion0.0.0.0-11.0.0.0 newVersion11.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Helpers publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-3.0.0.0 newVersion3.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Mvc publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-5.2.7.0 newVersion5.2.7.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Optimization publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-1.1.0.0 newVersion1.1.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.WebPages publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-3.0.0.0 newVersion3.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameWebGrease publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion0.0.0.0-1.6.5135.21930 newVersion1.6.5135.21930//dependentAssembly/assemblyBinding/runtimesystem.codedomcompilerscompiler languagec#;cs;csharp extension.cstypeMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version2.0.0.0, Cultureneutral, PublicKeyToken31bf3856ad364e35warningLevel4 compilerOptions/langversion:6 /nowarn:1659;1699;1701/compiler languagevb;vbs;visualbasic;vbscript extension.vbtypeMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version2.0.0.0, Cultureneutral, PublicKeyToken31bf3856ad364e35warningLevel4 compilerOptions/langversion:14 /nowarn:41008 /define:_MYTYPE\quot;Web\quot; /optionInfer//compilers/system.codedom /configuration Controller实例化由Unity负责处理需要实现控制器工厂类 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration; using System.Configuration;namespace WebApi.Extensions {public class UnityControllerFactory : DefaultControllerFactory{static object syncHelper new object();static Dictionarystring, IUnityContainer containers new Dictionarystring, IUnityContainer();public IUnityContainer UnityContainer { get; private set; }public UnityControllerFactory(string containerName ){if (containers.ContainsKey(containerName)){this.UnityContainer containers[containerName];return;}lock (syncHelper){if (containers.ContainsKey(containerName)){this.UnityContainer containers[containerName];return;}IUnityContainer container new UnityContainer();//配置UnityContainerUnityConfigurationSection configSection ConfigurationManager.GetSection(UnityConfigurationSection.SectionName) as UnityConfigurationSection;if (null configSection !string.IsNullOrEmpty(containerName)){throw new ConfigurationErrorsException(The unity configuration section does not exist.);}if (null ! configSection){if (string.IsNullOrEmpty(containerName)){configSection.Configure(container);}else{configSection.Configure(container, containerName);}}containers.Add(containerName, container);this.UnityContainer containers[containerName];}}protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType){if (null controllerType){return null;}return (IController)this.UnityContainer.Resolve(controllerType);} //public override void ReleaseController(IController controller) //{ // this.UnityContainer.Teardown(controller); //}} } 设置MVC框架的控制器工厂为自定义类型 using webApi.Extensions; using System; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing;namespace WebApp {public class Global : HttpApplication{void Application_Start(object sender, EventArgs e){// 在应用程序启动时运行的代码AreaRegistration.RegisterAllAreas();GlobalConfiguration.Configure(WebApiConfig.Register);RouteConfig.RegisterRoutes(RouteTable.Routes);ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory());}} } 新建Controller基类所有的自定义Controller均继承此类 using WebApi.Extensions; using System.Web.Mvc; using System; using System.Collections.Generic;namespace WebApp.Controllers {public class BaseController:Controller{public IListIDisposable DisposableObjects { get; private set; }public BaseController(){this.DisposableObjects new ListIDisposable();}protected void AddDisposableObject(object obj){IDisposable disposable obj as IDisposable;if (null ! disposable){this.DisposableObjects.Add(disposable);}}protected override void Dispose(bool disposing){if (disposing){foreach (IDisposable obj in this.DisposableObjects){if (null ! obj){obj.Dispose();}}}base.Dispose(disposing);}} } 新建测试Controller using DaLei.IService; using System.Web.Mvc;namespace WebApp.Controllers {public class TestController : BaseController{private IUserService userService;public TestController(IUserService userService){this.userService userService;this.AddDisposableObject(userService);}// GET: Testpublic ActionResult Index(){var users this.userService.GetList();return View();}} } 浏览器输入地址测试TestController

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923558.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站开发 保证书绵阳网站建设优化

为了规范财务行为,加强财务管理,提高代管经费使用效益,提高项目建设质量,根据上级和学校有关财务规定,结合我校实际情况,特制定本办法。一、教务处代管的项目经费品牌特色专业建设经费、精品课程建设经费、…

30天网站建设实录视频素材羊设计师服务平台

首先连通块,所以点分治肯定是 Trick1 钦定选根的连通块dp 对于钦定选根的连通块dp,有一种常见思路 先对原树求其dfn序,按dfn序倒序求解 具体的,对于当前点 i i i(注意这里都是指dfn序),我们…

词(持续更新)语言的边界就是

“语言的界限,就是我的世界的界限。 ”(Die Grenzen meiner Sprache bedeuten die Grenzen meiner Welt.)实际我认为并不是这样的,语言是智能在实际生产中产生的可进行传播的工具,但实际智能或者说意识在语言这个…

Group Theory (I)

1 Groups 1.1 Definition and Basic Terms Given a set with a binary operation $ (G,\cdot) $, if it satisfies:Closure: for all $ a,b\in G $, $ a\cdot b\in G $; Associativity: for all $ a,b,c\in G $, $ (a\…

财务分析怎么做 - 智慧园区

我前段时间跟做财务的朋友聊了聊,发现他们都遇上了这种情况:公司业务看起来一直在增长,但年底一算账,实际利润却少得可怜;还有报表上利润虽然可观,但现金流总是紧张,钱都不知道去哪了? 这背后,往往是三个最让…

dz论坛做分类网站南庄顺德网站建设

问题:使用 Canvas.DrawPath 绘制时,最后一点无法画到终点位置。(这个问题要在粗线才能察觉) 适用:Delphi 10 Seattle (或更早的版本) for Android & iOS 修复方法: 请将源码 FMX…

技术内容思路构建Promot

技术内容思路构建PromotPosted on 2025-10-01 06:07 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:技术内容思路构建Promot技术内容思路构建Promot历史第一:结合历史发展,用时间线的方式突出迭代演进变化,帮…

Group Theory

1 Groups 1.1 Definition and Basic Terms Given a set with a binary operation $ (G,\cdot) $, if it satisfies:Closure: for all $ a,b\in G $, $ a\cdot b\in G $; Associativity: for all $ a,b,c\in G $, $ (a\…

一站式网站建设平台制作网站的要素

1.触发器概述 触发器是一种特殊的存储过程,它与特定的表或列作特定类型的数据修改操作(如INSERT、UPDATE、DELETE等)相关联,并在这些操作发生时自动执行。触发器的主要作用是确保对数据的处理必须符合由触发器所定义的规则&#…

定制网站和模板建站网站建设中遇到的问题

文章目录 AI 甘安捏【入门介绍,形象生动】3D 重建技術 (一): 什麼是 3D 重建 (3D Reconstruction)?為什麼需要 3D 重建?【NeRF,3D Gaussian Splatting简介】3D 重建技術 (二): NeRF,AI技術革命 -- 用神經網路把場景「背…

摩尔定律的历史与AI统计学:从命名误导到本质洞察

摩尔定律的历史与AI统计学:从命名误导到本质洞察Posted on 2025-10-01 06:06 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:摩尔定律的历史与AI统计学:从命名误导到本质洞察摩尔定律的历史与AI统计学:从命名…

立场客观性警告Prompt

立场客观性警告PromptPosted on 2025-10-01 06:06 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:立场客观性警告Prompt立场客观性警告Prompt 核心目标 多角度验证 > 单一立场 - 在信息爆炸的时代,我们需要…

# SICP学习笔记:计算机程序的构造与解释

# SICP学习笔记:计算机程序的构造与解释Posted on 2025-10-01 06:06 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:# SICP学习笔记:计算机程序的构造与解释SICP学习笔记:计算机程序的构造与解释 Wikipedi…

3.劝学

3.劝学Posted on 2025-10-01 06:06 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:3.劝学 劝学 劝学 荀子〔先秦〕 君子曰:学不可以已。 青,取之于蓝,而青于蓝;冰,水为之,而寒于水。木直中绳,輮以为轮,…

服装网站建设平台12306网站多少钱做的

动机(Motivaton) 在软件构建过程中,集合对象内部结构常常变化各异。但对于这些集合对象,我们呢希望在不暴露其内部结构的同时,可以让外部客户代码透明地访问其中包含的元素;同时这种“透明遍历”也为“同一…

电商网站开发设计文档百事通微信推广平台

access数据库破解工具很多,密码能不用费多大功夫就能破解出来,但是对于包含特殊字符包括中文字符的密码,就算破解出来后想通过数据库工具查看,复制粘贴到密码输入框实际都起不了作用 已迁移到:分享最前沿的安全信息-a…

网站开发 入门教程网站建设人员配置

云原生学习路线导航页(持续更新中) 本文是 Kubernetes operator学习 系列的前置知识篇,帮助大家对 Operator 进行初步了解Kubernetes operator学习系列 快捷链接 Kubernetes operator 前置知识篇Kubernetes operator(一&#xff0…

网站上怎么做返回主页链接哪个云服务器便宜又好

下标:数组中的识别名称 也就是字符串或整数在数组中的代号数组中有几个索引值就被称为几维数组。索引值:索引是对数据库表中一列或多列的值进行排序的一种结构。数组分类在PHP数组被分为两种:索引数组:索引(indexed)索引值是整数&…

中时讯通信建设有限公司网站营销网站的建造步骤

文章目录 注意两点:一、设置原始模式二、设置收到数据的最小字节数返回代码 注意两点: 一、设置原始模式 newtio.c_lflag & ~(ICANON | ECHO | ECHOE | ISIG); /*Input*/二、设置收到数据的最小字节数返回 tio.c_cc[VMIN] 1; /* 读数据时的最…

龙岩市建设部网站八里河风景区网站建设内容摘要

第1篇:Arduino与ESP32开发板的安装方法 第2篇:ESP32 helloword第一个程序示范点亮板载LED 第3篇:vscode搭建esp32 arduino开发环境 第4篇:vscodeplatformio搭建esp32 arduino开发环境 ​​​​​​第5篇:doit_esp32_devkit_v1使用pmw呼吸灯实验 第6篇:ESP32连接无源喇叭播…