随笔分类 -  DotNet

FindFirstNonLoopbackAddress
摘要:public class InetUtils { public static IPAddress FindFirstNonLoopbackAddress() { IPAddress iPAddress = null; try { int num = int.MaxValue; NetworkInte 阅读全文

posted @ 2023-09-15 15:57 jonney_wang 阅读(109) 评论(0) 推荐(0)

aspnetcore 注册中心 consul
摘要:consul启动 . http://192.168.1.6:8500/ #以server方式启动,UI可以访问,boot引导自己选为leader,网段内PC可访问 consul agent -server -ui -bootstrap -data-dir=data -client=0.0.0.0 建 阅读全文

posted @ 2023-08-16 09:58 jonney_wang 阅读(137) 评论(0) 推荐(0)

阿拉伯数字转罗马
摘要:private string convertRoman(int num) { var ans = ""; var k = (int)Math.Floor(Convert.ToDecimal(num / 1000)); var h = (int)Math.Floor(Convert.ToDecimal 阅读全文

posted @ 2023-04-12 13:13 jonney_wang 阅读(34) 评论(0) 推荐(0)

netcore MongoDB
摘要:NuGet MongoDB.Driver using MongoDB.Bson; using MongoDB.Driver; using System; namespace MongoTest { public class MongoHp { static MongoHp() { MongoDB.B 阅读全文

posted @ 2022-08-21 09:02 jonney_wang 阅读(109) 评论(0) 推荐(0)

netcore centos unit服务文件
摘要:[Unit] Description=coreApiService [Service] Type=simple WorkingDirectory=/usr/local/app/netcore ExecStart=/usr/bin/dotnet CoreApi.dll #Restart=on-fail 阅读全文

posted @ 2022-04-19 09:16 jonney_wang 阅读(37) 评论(0) 推荐(0)

aspnetcore 认证和授权
摘要:public class EAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions> { private readonly IHttpContextAccessor _httpContextAccessor; 阅读全文

posted @ 2022-04-02 09:08 jonney_wang 阅读(191) 评论(0) 推荐(0)

ExpressionMapper
摘要:/// <summary> /// 利用表达式目录树进行实体映射 /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TTarget"></typeparam> public static cl 阅读全文

posted @ 2022-03-30 10:03 jonney_wang 阅读(60) 评论(0) 推荐(1)

aspnetcore 基本功能
摘要:配置: using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Configurati 阅读全文

posted @ 2021-12-12 19:38 jonney_wang 阅读(88) 评论(0) 推荐(0)

Kestrel gRPC
摘要:gRPC走http2协议,到目前我还没找到如何把gRPC server 部署在iis下。 现在只能走Kestrel。 public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(ar 阅读全文

posted @ 2020-11-28 19:54 jonney_wang 阅读(451) 评论(0) 推荐(0)

aspnetcore datetime json格式化
摘要:public class DateTimeConverter : JsonConverter<DateTime> { public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializer 阅读全文

posted @ 2020-11-25 08:53 jonney_wang 阅读(448) 评论(0) 推荐(0)

netcore rabbitMq
摘要:public class RabbitConf { public string HostName { get; set; } public string UserName { get; set; } public string Password { get; set; } public string 阅读全文

posted @ 2020-11-23 17:00 jonney_wang 阅读(153) 评论(0) 推荐(0)

MessagePack 序列化
摘要:public static byte[] ToBin(this object obj) { return MessagePack.MessagePackSerializer.Serialize(obj.GetType(), obj); } public static T FromBin<T>(thi 阅读全文

posted @ 2020-10-24 12:24 jonney_wang 阅读(444) 评论(0) 推荐(0)

aspnetcore 取消默认Json首字母小写
摘要:public void ConfigureServices(IServiceCollection services) { // 根据类是否添加注解[IsService]来自动注入 var assm = new[] { typeof(Program).Assembly, typeof(DbCtxt). 阅读全文

posted @ 2020-10-17 22:06 jonney_wang 阅读(233) 评论(0) 推荐(0)

Autofac MagicOnion Grpc
摘要:1、定义Dto 和 Grpc协议 namespace MagicProtocal.Dto { public class Usr { public int Id { get; set; } public string Code { get; set; } public string Name { ge 阅读全文

posted @ 2020-09-24 16:37 jonney_wang 阅读(214) 评论(0) 推荐(0)

netcore 依据注解自动注入
摘要:DbCtxt.ConnStr = Configuration.GetSection("ConnectionString").Value; // 根据类是否添加注解[IsService]来自动注入 var assm = new[] { typeof(Program).Assembly, typeof( 阅读全文

posted @ 2020-09-23 07:44 jonney_wang 阅读(610) 评论(0) 推荐(0)

NLog
摘要:public static class LogUtil { static LogUtil() { NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(Path.Combine(Path.GetDirector 阅读全文

posted @ 2020-09-17 17:51 jonney_wang 阅读(241) 评论(0) 推荐(0)

aspnetcore IExceptionFilter
摘要:public class GlobalExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext context) { context.Result = new ObjectResult(new { St 阅读全文

posted @ 2020-09-16 22:21 jonney_wang 阅读(252) 评论(0) 推荐(0)

WebApi IExceptionFilter
摘要:public class ExceptionFilter : System.Web.Http.Filters.IExceptionFilter { bool IFilter.AllowMultiple => true; Task IExceptionFilter.ExecuteExceptionFi 阅读全文

posted @ 2020-09-16 07:24 jonney_wang 阅读(248) 评论(0) 推荐(0)

MagicOnion Grpc ContractlessStandard
摘要:前言: MessagePack 序列化默认是标准的 StandardResolver ,如果希望DTO模型不再添加 [MessagePackObject(true)] 这样的注解(这样更普遍一些),那么需要在 Server端和 Client 端都要设置一下序列化的 Resolver,把默认的标准Re 阅读全文

posted @ 2020-09-13 08:14 jonney_wang 阅读(281) 评论(0) 推荐(0)

Extend
摘要:public static class Extend { public static DateTime Local(this DateTime now) { return DateTime.Parse(now.ToString("yyyy-MM-dd HH:mm:ss")); } public st 阅读全文

posted @ 2020-09-11 22:15 jonney_wang 阅读(209) 评论(0) 推荐(0)

导航