
netcore
IT杂人
有其功必有其效
展开
-
dotnet使用自定义模板创建开发脚手架
dotnet使用自定义模板创建开发脚手架原创 2023-02-17 01:02:28 · 489 阅读 · 0 评论 -
nuget发布非正式版本/预览版本
1.我们的类库,可能随着分支的不同,有不同的版本,有些版本处于测试,有些处于正式使用时,如果还只是使用之前的高版本是不合适的,容易误升级所以可使用预览版本2.在定义版本时,除了数字和点号以外,后面有其他字符,会默认选择为非正式版本3.nuget 推送到服务端nuget push %1 -src http://xxx.xxx.cn 123456 XXX.DTO.1.0.7-pre.nupkghttp://xxx.xxx.cn:为指定的nuget服务端123456 :密码4原创 2021-04-12 18:35:20 · 760 阅读 · 0 评论 -
记一次webapi使用Cache特性被缓存击穿的问题
记一次webapi使用Cache特性被缓存击穿的问题原创 2022-10-28 21:14:10 · 843 阅读 · 0 评论 -
docker容器资源限制与容器内的dotnet应用线程限制
docker容器资源限制使用docker-compose管理容器所以yml文件配置可以 增加 deploy: resources: limits: cpus: "8" memory: 4096M reservations: cpus: "0.05" memory: 500Mlimits=> cpus: “8” //cpu利用率最大限制:建议设置成实际cpu核数的一原创 2022-04-02 22:07:47 · 3951 阅读 · 0 评论 -
netcore使用ActionFilter过滤器,实现模型验证的国际化多语言提示信息
1.模型验证类库:DataAnnotations,我们使用常用基本的模型验证类库2.定义验证的时候如下://ErrorMessage 不再返回具体的提示信息,只返回具体的对应的codepublic class RequestDTO { /// <summary> /// 用户ID /// </summary> [Required(ErrorMessage = "MsgCode_UserIDisNull")]原创 2021-11-24 12:36:11 · 760 阅读 · 0 评论 -
netcore的依赖注入,在BackgroundService中使用Scope注入的服务
1.BackgroundService注入的服务默认为Singleton范围: services.AddHostedService<SyncDataJob>(); 或者 services.AddSingleton<IHostedService,SyncDataJob>();2.运行时,会报错:Cannot consume scoped service from singleton3.解决办法:a:使用IServiceScopeFactory 工厂 pu原创 2021-11-21 01:56:26 · 2970 阅读 · 0 评论 -
vs无法产生pdb文件,也就无法断点调试
1.按网上各种配置以后,发现还是不行这个是很苦恼的一件事,为什么别人的都行,偏偏自己的不对。2.最后想到可能是csproj文件配置问题,因为生成和发布的文件都不存在pdb文件。仔细过了一遍csproj文件,发现:<DebugType>none</DebugType><DebugSymbols>false</DebugSymbols>修改为none为fullfalse为true后,调试断点正常3.最后去开源仓库的issue中查找是否有同样问题,原创 2021-07-04 23:38:20 · 1690 阅读 · 0 评论 -
dotnet 命令行发布与启动
我们常常只需要测试目标代码是否可用,而不需要打开繁重的IDE,虽然是最好用的IDE.1.获取源码git clone https://git.xxx.com/test.git2.进入代码目录cd test\src3.添加自定义nuget,如果不使用,则不需要;已经存在可略过dotnet nuget add source http://nuget.mynuget.cn/nuget --name=mynuget4.还原库文件dotnet restore . #有点号5.生成测试,没问题原创 2021-05-26 12:55:16 · 2518 阅读 · 0 评论 -
dotnet多进程启动时,附加进程如何精准找到对应的进程
问题描述:启动多个dotnet程序时,通过Ctrl+Alt+P附加时,不能分辨哪一条是对应的进程解决方案:方案一:通过进程ID,程序启动时展示进程ID /// <summary> /// application扩展 /// </summary> public static class ApplicationExtension { /// <summary> /// 显示进程ID原创 2021-05-19 16:00:51 · 590 阅读 · 0 评论 -
使用sqlsugar的事务时,提示Enlisting in Ambient transactions is not supported
原因竟然是它默认的System.Data.SqlClient版本太低。遇到同样问题的解答:https://stackoverflow.com/questions/47974837/enlisting-in-ambient-transactions-is-not-supported-using-transactionscope-in-asp升级Confirmed, I'm using .Net Core 2.2, and installing the latest NuGet package原创 2021-04-20 19:30:22 · 350 阅读 · 0 评论 -
c#的方法体建议的注释格式
1.通过注释能减少很多不必要的沟通和失误,建议的方法体注释,如下【较多】: /// <summary> /// 获取xxx分页列表 /// author:zelun /// date:2021-04-14 /// log:实现xxx分页列表 /// <example> /// <code> /// var result=new xxxB.原创 2021-04-14 10:09:13 · 349 阅读 · 0 评论 -
使用sqlsugar时,select赋值不支持的格式处理方法
1.不支持枚举转换,使用匿名对象,转换完后,使用linq转为list实体 .OrderBy((pr, prd, prc) => pr.ModifyTime, OrderByType.Desc).Select((pr, prd, prc) => new //匿名对象 { RecordID = pr.RecordID, TradeNo = pr.TradeNo, .原创 2021-04-13 19:46:47 · 2223 阅读 · 0 评论 -
netcore使用过滤器特性,限定方法在指定环境(Development,Staging,Production)是否运行
1.特性 /// <summary> /// 运行环境:Development,Staging,Production /// </summary> public class EnableHostEnvionmentAttribute : ActionFilterAttribute { private string hostEnvNames; /// <summary> ///原创 2021-03-11 18:00:07 · 301 阅读 · 0 评论 -
netcore检测启动模式是否调试模式的两种实现模式
1.使用条件编译符#if Debug,当代码被此标签包含时,换到Release调试模式,代码不会被编译,且访问Controller/Action 会返回404#if DEBUG /// <summary> /// 测试 /// </summary> [AllowAnonymous] public class TestController : BaseController { /// <summary>原创 2021-03-11 17:53:24 · 1282 阅读 · 0 评论 -
c#中 async/await 什么时间产生新线程?
听说:“在遇到await时,将产生一个新线程”。根据代码的多层框架,await关键字会嵌套调用会有多层,最终会在哪一层哪一段代码时产生新线程。上代码:Controller层: [HttpGet("UserID")] public async Task<long> GetUserID() { Console.WriteLine(HttpContext.TraceIdentifier+"-"+ System.Th原创 2021-03-06 17:51:17 · 1214 阅读 · 0 评论 -
AddSingleton,AddScoped,AddTransient 三者的差异性测试
服务类型 同一个 HTTP 请求的范围 多个不同 HTTP 请求 Singleton Service 同一个实例 同一个实例 Scoped Service 同一个实例 新实例 Transient Service 新实例 新实例 自己理解的测试代码:...原创 2021-03-02 18:30:56 · 1359 阅读 · 0 评论 -
C#获取时间戳(Unix时间戳)
明确一点:unix时间戳是从1970年1月1日的午夜开始所经过的时间 /// <summary> /// 将c# 本地DateTime时间格式转换为Unix时间戳格式 (毫秒) /// </summary> /// <param name="time">时间</param> /// <returns>long</returns>原创 2021-02-26 16:02:47 · 3326 阅读 · 0 评论 -
netcore mvc 按restful标准定义url时,使用url路径传值时,指定参数默认值
1.指定默认不为空的值:写入具体的值 /// <summary> /// 查询银行卡类型:如CardType /// </summary> /// <param name="typeCode">枚举类型</param> /// <returns></returns> [HttpGet("TypeList/{typeCode=CardTyp原创 2021-02-04 17:13:18 · 499 阅读 · 1 评论 -
netcore使用sqlsugar实现分布式事务(强一制性)
适用于:同实例下的单库:test(sqlserver-localhost)同实例下的不同库:test(sqlserver-localhost),test2(sqlserver-localhost)同类型数据库不同实例:test(sqlserver-localhost),test2(sqlserver-remote)不同类/异构数据库的不同实例:不支持,test(sqlserver-localhost),test2(mysql-remote)1.DbContext.cs文件声明多库..原创 2021-01-26 14:42:21 · 2359 阅读 · 0 评论 -
netcore 模型验证扩展:验证两个字段的大小
参考:https://github.com/dotnet/runtime/blob/master/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/CompareAttribute.cs参考:https://www.cnblogs.com/Cyril-hcj/p/11697871.html1.添加MinFieldAttribute.cs实现ValidationAttribut原创 2021-01-20 16:21:30 · 446 阅读 · 0 评论 -
netcore下T4模板生成中文乱码问题
1.问题:在window下T4模板中有中文说明,生成代码文件后,中文变成乱码: /// <summary> /// ◈◈◈◈: Banks /// ◈◈◈: /// </summary> [Serializable]2.原因:在window下T4自身的模板".tt"文件格式是GB23123.使用notepad++转为utf8-bom4.重新生成 /// <summary> /// 表名: Ban原创 2021-01-06 14:15:29 · 321 阅读 · 0 评论 -
netcore webapi对请求query参数的检查特性封装
netcore webapi对请求Query参数的检查特性对于Model的检查,我们可以使用mvc自带的类库【using System.ComponentModel.DataAnnotations;】但对于Query参数的检查,我们常常放在实现代码里,个人总觉得太多余。于是。。。。。。1.定义特性:QueryRequiredAttribute/// <summary> /// 查询参数检查 /// </summary> public clas原创 2020-12-30 15:00:19 · 634 阅读 · 0 评论 -
netcore 3+中,JsonProperty特性失效
在我们之前常用的JsonProperty特性中,突然不再生效。查阅相关资料后发下:之前版本中,netocre默认使用Newtonsoft.Json作为Json解析器,在3.0不再是默认,而是使用System.Text.Json替换Newtonsoft.Json参考文章:https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/如继续使用Newtonsoft.Json作为Json解析器,在startup.cs里显原创 2020-12-29 19:18:24 · 754 阅读 · 0 评论