<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DotNET Core on 冯威的博客</title><link>https://fwhyy.com/tags/dotnet-core/</link><description>Recent content in DotNET Core on 冯威的博客</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Mon, 25 Jan 2021 09:36:06 +0800</lastBuildDate><atom:link href="https://fwhyy.com/tags/dotnet-core/atom.xml" rel="self" type="application/rss+xml"/><item><title>dotNet Core 3.1 使用 Elasticsearch</title><link>https://fwhyy.com/2021/01/dotnet-core-3-uses-elasticsearch/</link><pubDate>Mon, 25 Jan 2021 09:36:06 +0800</pubDate><guid>https://fwhyy.com/2021/01/dotnet-core-3-uses-elasticsearch/</guid><description>&lt;p&gt;Elasticsearch 是基于 Lucene 的搜索引擎。可以非常方便地实现分布式的全文搜索，本文介绍在 dotNet Core 3.1 中怎样使用 Elasticsearch 。&lt;/p&gt;</description></item><item><title>CentOS7 中使用 Supervisor 部署 dotNET Core 程序</title><link>https://fwhyy.com/2020/12/deploying-dotnet-core-programs-with-supervisor-in-centos7/</link><pubDate>Mon, 28 Dec 2020 09:43:34 +0800</pubDate><guid>https://fwhyy.com/2020/12/deploying-dotnet-core-programs-with-supervisor-in-centos7/</guid><description>&lt;p&gt;在 CentOS 中部署 dotNET Core 程序，我们通常会使用 Docker ，方便快捷，版本更新也非常方便，但有时客户要求直接在服务器上进行 dotNET Core 程序的部署，这时就需要使用守护进程，本文就介绍使用守护进程 Supervisor 进行 dotNET Core 程序的部署。&lt;/p&gt;</description></item><item><title>dotNet Core 3.1 使用 Aspose （部署 Docker）</title><link>https://fwhyy.com/2020/10/dotnet-core-3-1-uses-aspose-deploy-docker/</link><pubDate>Mon, 19 Oct 2020 07:48:55 +0800</pubDate><guid>https://fwhyy.com/2020/10/dotnet-core-3-1-uses-aspose-deploy-docker/</guid><description>&lt;p&gt;在之前的文章《Dotnet Core 中使用Aspose（部署Docker）》中介绍了在 dotNet Core2.1 中使用 Aspose ，并部署到 Docker 中，现在 dotNET Core 升级到了 3.1 ，Docker 镜像发生了变化，一些依赖的安装也有些变化。&lt;/p&gt;</description></item><item><title>dotNET Core：编码规范</title><link>https://fwhyy.com/2020/09/dotnet-core-coding-specification/</link><pubDate>Mon, 14 Sep 2020 09:44:15 +0800</pubDate><guid>https://fwhyy.com/2020/09/dotnet-core-coding-specification/</guid><description>&lt;p&gt;在项目开发过程中，由于时间紧、任务重，很容易导致面向功能编程。实现相同的功能，代码可以写的很优雅，也可以写的很晦涩和复杂。现在的工作，都需要进行团队协作，代码就需要有一定的规范进行指引，因为我们需要写出让人可以轻易读懂的代码，而不仅仅是机器。&lt;/p&gt;</description></item><item><title>dotNET：怎样处理程序中的异常（实战篇）？</title><link>https://fwhyy.com/2020/08/dotnet-how-to-handle-exceptions-in-programs-practical/</link><pubDate>Mon, 03 Aug 2020 17:38:52 +0800</pubDate><guid>https://fwhyy.com/2020/08/dotnet-how-to-handle-exceptions-in-programs-practical/</guid><description>&lt;p&gt;在上篇 《dotNET：怎样处理程序中的异常（理论篇）》 中讲了一些程序中出现异常怎样处理的理论知识，本文将以代码的方式来进行实践。&lt;/p&gt;</description></item><item><title>dotNET：怎样处理程序中的异常（理论篇）？</title><link>https://fwhyy.com/2020/07/dotnet-how-to-handle-exceptions-in-programs/</link><pubDate>Mon, 20 Jul 2020 17:36:05 +0800</pubDate><guid>https://fwhyy.com/2020/07/dotnet-how-to-handle-exceptions-in-programs/</guid><description>&lt;p&gt;平时在软件开发的过程中，首先是要保证功能可以正常运行，满足业务需求，除此之外，还需要考虑代码在异常的时候怎么处理，让程序能够健壮地运行。正确合理地处理异常可以减少程序的 Bug、保证代码质量，当然也不是一件很容易的事。&lt;/p&gt;</description></item><item><title>dotNET Core 3.X 使用 Autofac 来增强依赖注入</title><link>https://fwhyy.com/2020/06/dotnet-core-3-uses-autofac-to-enhance-dependency-injection/</link><pubDate>Mon, 08 Jun 2020 12:02:56 +0800</pubDate><guid>https://fwhyy.com/2020/06/dotnet-core-3-uses-autofac-to-enhance-dependency-injection/</guid><description>&lt;p&gt;在上一篇《dotNET Core 3.X 依赖注入》中简单介绍了 dotNET Core 框架本身的依赖注入功能，大部分情况下使用框架的依赖注入功能就可以满足了，在一些特殊场景下，我们就需要引入第三方的注入框架。&lt;/p&gt;</description></item><item><title>dotNET Core 3.X 依赖注入</title><link>https://fwhyy.com/2020/06/dotnet-core-3-dependency-injection/</link><pubDate>Mon, 01 Jun 2020 11:57:32 +0800</pubDate><guid>https://fwhyy.com/2020/06/dotnet-core-3-dependency-injection/</guid><description>&lt;p&gt;如果说在之前的 dotNET 版本中，依赖注入还是个比较新鲜的东西，那么在 dotNET Core 中已经是随处可见了，可以说整个 dotNET Core 的框架是构建在依赖注入框架之上。本文讲解下对 dotNET Core 中依赖注入的理解。&lt;/p&gt;</description></item><item><title>dotNET Core 中怎样操作AD（续1）</title><link>https://fwhyy.com/2020/01/how-to-operate-ad-in-dotnet-core-continued/</link><pubDate>Mon, 20 Jan 2020 07:40:14 +0800</pubDate><guid>https://fwhyy.com/2020/01/how-to-operate-ad-in-dotnet-core-continued/</guid><description>&lt;p&gt;在之前的文章《&lt;a href="http://fwhyy.com/2019/09/how-to-operate-ad-in-dotnet-core/"&gt;dotNET Core 中怎样操作 AD？&lt;/a&gt;》中主要以将AD的数据同步到数据库的场景来描述了在 dotNetCore 中怎样操作AD，本文将继续介绍一些在 dotNetCore 中操作 AD 的其他常用操作。&lt;/p&gt;</description></item><item><title>dotNET Core 中怎样操作 AD？</title><link>https://fwhyy.com/2019/09/how-to-operate-ad-in-dotnet-core/</link><pubDate>Mon, 30 Sep 2019 22:18:21 +0800</pubDate><guid>https://fwhyy.com/2019/09/how-to-operate-ad-in-dotnet-core/</guid><description>&lt;p&gt;做企业应用开发难免会跟 AD 打交道，在之前的 dotNET FrameWork 时代，通常使用 System.DirectoryServices 的相关类来操作 AD ，在 dotNET Core 中没有这个命名空间，在张善友大佬的推荐下，知道了 Novell.Directory.Ldap。&lt;/p&gt;</description></item><item><title>dotNET Core实现分布式环境下的流水号唯一</title><link>https://fwhyy.com/2019/09/implementation-of-unique-pipeline-number-in-distributed-environment-by-dotnet-core/</link><pubDate>Sat, 14 Sep 2019 23:30:19 +0800</pubDate><guid>https://fwhyy.com/2019/09/implementation-of-unique-pipeline-number-in-distributed-environment-by-dotnet-core/</guid><description>&lt;h2 id="业务背景"&gt;业务背景&lt;/h2&gt;
&lt;p&gt;在管理系统中，很多功能模块都会涉及到各种类型的编号，例如：流程编号、订单号、合同编号等等。编号各有各自的规则，但通常有一个流水号来确定编号的唯一性，保证流水号的唯一，在不同的环境中实现方式有所不同。本文将介绍在单机和分布式环境中保证流水号唯一的方式。&lt;/p&gt;</description></item><item><title>.NET 程序员如何学习Vue</title><link>https://fwhyy.com/2019/08/net-programmer-how-to-learn-vue/</link><pubDate>Sat, 31 Aug 2019 16:32:05 +0800</pubDate><guid>https://fwhyy.com/2019/08/net-programmer-how-to-learn-vue/</guid><description>&lt;p&gt;之所以取这个标题，是因为本文来自内部培训的整理，培训的对象是公司的 .NET 程序员，.NET 程序员学习 Vue 是为了在项目中做二次开发时能够更好地跟产品对接。&lt;/p&gt;</description></item><item><title>dotNET Core WebAPI 统一处理（返回值、参数验证、异常）</title><link>https://fwhyy.com/2019/08/unified-processing-of-dotnet-core-web-api-return-value-parameter-validation-exception/</link><pubDate>Wed, 21 Aug 2019 06:28:27 +0800</pubDate><guid>https://fwhyy.com/2019/08/unified-processing-of-dotnet-core-web-api-return-value-parameter-validation-exception/</guid><description>&lt;p&gt;现在 Web 开发比较流行前后端分离，我们的产品也是一样，前端使用Vue，后端使用 dotNet Core WebAPI ，在写 API 的过程中有很多地方需要统一处理：&lt;/p&gt;</description></item><item><title>Office转PDF，Aspose太贵，怎么办</title><link>https://fwhyy.com/2019/01/office-to-pdf-aspose-is-too-expensive-how-to-do/</link><pubDate>Sun, 13 Jan 2019 13:48:21 +0800</pubDate><guid>https://fwhyy.com/2019/01/office-to-pdf-aspose-is-too-expensive-how-to-do/</guid><description>&lt;p&gt;在程序开发中经常需要将&lt;code&gt;Office&lt;/code&gt;文件转换成&lt;code&gt;PDF&lt;/code&gt;，著名的&lt;code&gt;Aspose&lt;/code&gt;的三大组件可以很容易完成这个功能，但是&lt;code&gt;Aspose&lt;/code&gt;的每个组件都单独收费，而且每个都卖的不便宜。在老大的提示下，换了一种思路来解决这个问题。&lt;/p&gt;</description></item><item><title>dotNET Core中使用Aspose（部署Docker）</title><link>https://fwhyy.com/2018/11/using-aspose-in-dotnet-core/</link><pubDate>Thu, 22 Nov 2018 23:07:45 +0800</pubDate><guid>https://fwhyy.com/2018/11/using-aspose-in-dotnet-core/</guid><description>&lt;p&gt;在&lt;code&gt;dotnet&lt;/code&gt;下处理过&lt;code&gt;Office&lt;/code&gt;文档的相信对&lt;code&gt;Aspose&lt;/code&gt;都不陌生，&lt;code&gt;Aspose&lt;/code&gt;下面的三大组件：&lt;code&gt;Aspose.Cells&lt;/code&gt;、&lt;code&gt;Aspose.Slides&lt;/code&gt;、&lt;code&gt;Aspose.Words&lt;/code&gt;可以让我们很方便的操作&lt;code&gt;Office&lt;/code&gt;文档，或者将&lt;code&gt;Office&lt;/code&gt;导出为&lt;code&gt;PDF&lt;/code&gt;。&lt;/p&gt;</description></item><item><title>dotNET Core：配置</title><link>https://fwhyy.com/2018/08/dotnet-core-configure/</link><pubDate>Sun, 12 Aug 2018 22:13:39 +0800</pubDate><guid>https://fwhyy.com/2018/08/dotnet-core-configure/</guid><description>&lt;p&gt;在&lt;code&gt;dotNET Core&lt;/code&gt;中默认情况下没有了之前版本的&lt;code&gt;App.config&lt;/code&gt;和&lt;code&gt;Web.Config&lt;/code&gt;文件，换成了新的&lt;code&gt;json&lt;/code&gt;格式的配置文件。当然，如果想使用之前的方式也是可以的。下面说说在&lt;code&gt;dotNET Core&lt;/code&gt;中各种使用配置的方法。&lt;/p&gt;
&lt;h2 id="环境"&gt;环境&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;操作系统：macOS 10.13.5&lt;/li&gt;
&lt;li&gt;dotNET Core：2.1&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="使用原来的config文件"&gt;使用原来的config文件&lt;/h2&gt;
&lt;p&gt;如果你还念旧，想使用之前的&lt;code&gt;App.config&lt;/code&gt;或&lt;code&gt;Web.config&lt;/code&gt;，可以导入&lt;code&gt;System.Configuration.ConfigurationManager&lt;/code&gt;包，使用方式和之前一样。&lt;/p&gt;
&lt;p&gt;&lt;img src="https://img.fwhyy.com/2022/202201270825835.webp" alt="-w788" loading="lazy" decoding="async"&gt;
&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;using System.Configuration;
...
static void Main(string[] args)
{
 var connection = ConfigurationManager.ConnectionStrings[&amp;#34;ConnectionStr&amp;#34;].ConnectionString;
 var mqHostName = ConfigurationManager.AppSettings[&amp;#34;MQHostName&amp;#34;];
 Console.WriteLine($&amp;#34;connection:{connection}&amp;#34;);
 Console.WriteLine($&amp;#34;mqHostName:{mqHostName}&amp;#34;);
 Console.ReadLine();
}
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="命令行配置"&gt;命令行配置&lt;/h2&gt;
&lt;p&gt;1、创建一个控制台的应用程序&lt;code&gt;NetCoreConfigDemo&lt;/code&gt;；
2、导入依赖包，可以按需导入，也可以直接导入&lt;code&gt;Microsoft.AspNetCore&lt;/code&gt;的包，里面包含所有依赖的项；&lt;/p&gt;
&lt;p&gt;&lt;img src="https://img.fwhyy.com/2022/202201270825585.webp" alt="-w1001" loading="lazy" decoding="async"&gt;
&lt;/p&gt;
&lt;p&gt;3、添加&lt;code&gt;using Microsoft.Extensions.Configuration;&lt;/code&gt;引用；
4、代码如下：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;using System;
using Microsoft.Extensions.Configuration;
namespace NetCoreConfigDemo
{
 class Program
 {
 static void Main(string[] args)
 {
 var builder = new ConfigurationBuilder()
 .AddCommandLine(args);
 var configration = builder.Build();
 Console.WriteLine($&amp;#34;name:{configration[&amp;#34;name&amp;#34;]}&amp;#34;);
 Console.ReadLine();
 }
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;5、运行时指定&lt;code&gt;name&lt;/code&gt;参数，在命令行中可以正常打印出来&lt;/p&gt;
&lt;p&gt;&lt;img src="https://img.fwhyy.com/2022/202201270827596.webp" alt="-w676" loading="lazy" decoding="async"&gt;
&lt;/p&gt;
&lt;p&gt;上面例子中的参数&lt;code&gt;name&lt;/code&gt;是在启动程序是指定的，如果想要程序有一个默认的参数值，可以在程序中初始化一个字典类&lt;code&gt;Dictionary&lt;/code&gt;，代码如下：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;using System;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
namespace NetCoreConfigDemo
{
 class Program
 {
 static void Main(string[] args)
 {
 var dic = new Dictionary&amp;lt;string, string&amp;gt;() { { &amp;#34;name&amp;#34;, &amp;#34;oec2003&amp;#34; } };
 var builder = new ConfigurationBuilder()
 .AddInMemoryCollection(dic)
 .AddCommandLine(args);
 var configration = builder.Build();
 Console.WriteLine($&amp;#34;name:{configration[&amp;#34;name&amp;#34;]}&amp;#34;);
 Console.ReadLine();
 }
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;
&lt;p&gt;注意：&lt;code&gt;AddInMemoryCollection&lt;/code&gt;必须放在&lt;code&gt;AddCommandLine&lt;/code&gt;的前面，否则默认值会覆盖掉在外部指定的参数值。&lt;/p&gt;</description></item><item><title>调用API修改Ocelot的配置文件</title><link>https://fwhyy.com/2018/05/call-api-to-modify-the-configuration-file-of-the-ocelot/</link><pubDate>Wed, 16 May 2018 00:19:38 +0800</pubDate><guid>https://fwhyy.com/2018/05/call-api-to-modify-the-configuration-file-of-the-ocelot/</guid><description>&lt;p&gt;Ocelot是一个基于.net core的开源webapi服务网关开源项目，功能比较强大，Github项目地址为：&lt;a href="https://github.com/ThreeMammals/Ocelot"&gt;https://github.com/ThreeMammals/Ocelot&lt;/a&gt;，关于Ocelot的学习资料可以看看张善友的网站：&lt;a href="http://www.csharpkit.com/apigateway.html"&gt;http://www.csharpkit.com/apigateway.html&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;Ocelot的路由设置是基于配置文件的，同样在Ocelot中使用Consul做服务发现时，也是基于配置文件，当我们修改路由或者需要往Consul中添加ServiceName的时候，需要修改配置文件，网关服务也需要重启，这当然不是我们想要的。&lt;/p&gt;</description></item></channel></rss>