You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
138 KiB
XML

1 year ago
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Furion Blog</title>
<link>http://furion.baiqian.ltd/blog</link>
<description>Furion Blog</description>
<lastBuildDate>Tue, 31 May 2022 00:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>en</language>
<item>
<title><![CDATA[7. GlobalUsings 的使用]]></title>
<link>http://furion.baiqian.ltd/blog/global-usings</link>
<guid>http://furion.baiqian.ltd/blog/global-usings</guid>
<pubDate>Tue, 31 May 2022 00:00:00 GMT</pubDate>
<description><![CDATA[简介]]></description>
<content:encoded><![CDATA[<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="简介">简介<a href="http://furion.baiqian.ltd/blog/global-usings#%E7%AE%80%E4%BB%8B" class="hash-link" aria-label="Direct link to 简介" title="Direct link to 简介"></a></h3>
<p><code>.NET6/C#10</code> 之后,微软新增了 <code>GlobalUsings</code> 机制,可以在项目的根目录下创建一个 <code>GlobalUsings.cs</code> 文件,把常用的 <code>using</code> 放置其中。</p>
<p>这样 <code>GlobalUsings.cs</code> 所在的项目 <code>.cs</code> 文件就无需重复 <code>using</code> 了,大大的提高开发效率,也让代码变的更加简洁。</p>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="必要配置">必要配置<a href="http://furion.baiqian.ltd/blog/global-usings#%E5%BF%85%E8%A6%81%E9%85%8D%E7%BD%AE" class="hash-link" aria-label="Direct link to 必要配置" title="Direct link to 必要配置"></a></h3>
<p><strong>启用 <code>GlobalUsings</code> 机制需要以下两个步骤:</strong></p>
<ol>
<li>在你需要全局 <code>using</code> 的项目层根目录创建 <code>GlobalUsings.cs</code> 文件,如果多个项目层需要,则每个层都应该有一个 <code>GlobalUsings.cs</code></li>
<li>编辑项目的 <code>.csproj</code> 文件,添加 <code>&lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;</code>,注意是在 <code>&lt;PropertyGroup&gt;</code> 中添加,通常和 <code>&lt;TargetFramework&gt;</code> 同父同级</li>
</ol>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="基本使用">基本使用<a href="http://furion.baiqian.ltd/blog/global-usings#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8" class="hash-link" aria-label="Direct link to 基本使用" title="Direct link to 基本使用"></a></h3>
<p>配置之后,现在就可以把常用的 <code>using</code> 放到 <code>GlobalUsings.cs</code> 中了,写法如下:</p>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockTitle_Ktv7">Furion 推荐的全局命名空间</div><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DatabaseAccessor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DataEncryption</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DataValidation</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DependencyInjection</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></spa
<p><strong>注意必须以 <code>global</code> 开头!</strong></p>
<div class="theme-admonition theme-admonition-tip admonition_xJq3 alert alert--success"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 12 16"><path fill-rule="evenodd" d="M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"></path></svg></span>小知识</div><div class="admonitionContent_BuS1"><p>一般推荐把实体类的命名空间也放进去,因为仓储 <code>IRepository&lt;T&gt;</code> 使用的频率非常高。</p><p>另外推荐大家在 <code>Visual Studio</code> 中安装 <code>CodeMaid</code> 插件哦,自动清理解决方案所有无用的 <code>using</code>,结合 <code>GlobalUsings.cs</code> 非常棒!</p></div></div>
<div class="theme-admonition theme-admonition-important admonition_xJq3 alert alert--info"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>个别情况</div><div class="admonitionContent_BuS1"><p>可能由于 <code>Visual Studio</code> 版本的问题,导致 <code>GlobalUsings.cs</code> 定义出错,这时候需要在 <code>using</code> 后面加 <code>global::</code>,如:</p><div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">global</span><span class="token punctuation" style="color:rgb(199, 146, 234)">::</span><span class="token plain">Furion</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div></div></div>
<p>接下来在代码中使用:</p>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// 无需 using Furion 的命名空间了哦,清爽了不少</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">namespace</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Your</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">class</span><span class="token plain"> </span><span class="token class-name" style="color:rgb(255, 203, 107)">DefaultAppService</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">:</span><span class="token plain"> </span><span class="token type-list class-name" style="color:rgb(255, 203, 107)">IDynamicApiController</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">private</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">readonly</span><span class="token plain"> </span><span class="token class-name" style="color:rgb(255, 203, 107)">IRepository</span><span class="token class-name punctuation" style="color:rgb(199, 146, 234)">&lt;</span><span class="token class-name" style="color:rgb(255, 203, 107)">BoardCard</span><span class="token class-name punctuation" style="color:rgb(199, 146, 234)">&gt;</span><span class="token plain"> _boardCardRepository</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">private</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">readonly</span><span class="
<img src="http://furion.baiqian.ltd/img/cd2223.png">
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="默认全局-using">默认全局 <code>using</code><a href="http://furion.baiqian.ltd/blog/global-usings#%E9%BB%98%E8%AE%A4%E5%85%A8%E5%B1%80-using" class="hash-link" aria-label="Direct link to 默认全局-using" title="Direct link to 默认全局-using"></a></h3>
<p><strong>实际上微软已经自动把一些常用的 <code>using</code> 在编译后的代码中自动补上了</strong>,路径在 <code>项目/obj/Debug/net6.0/项目.GlobalUsings.cs</code> 文件中,文件内容如下:</p>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// &lt;auto-generated/&gt;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">global</span><span class="token punctuation" style="color:rgb(199, 146, 234)">::</span><span class="token plain">System</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">global</span><span class="token punctuation" style="color:rgb(199, 146, 234)">::</span><span class="token plain">System</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Collections</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Generic</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">global</span><span class="token punctuation" style="color:rgb(199, 146, 234)">::</span><span class="token plain">System</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">IO</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">global</span><span class="token punctuation" style="color:rgb(199, 146, 234)">::</span><span class="token plain">System</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Linq</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">global</span><span class="token plain"> </span><span class="token
<p><strong>也就是以上的 <code>using</code> 无需写在你创建的 <code>GlobalUsings.cs</code> 中了,微软会在编译时自动合并。</strong></p>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>.net6</category>
</item>
<item>
<title><![CDATA[6. .NET 6 Preview 7 尝鲜]]></title>
<link>http://furion.baiqian.ltd/blog/net6-preview7</link>
<guid>http://furion.baiqian.ltd/blog/net6-preview7</guid>
<pubDate>Wed, 11 Aug 2021 00:00:00 GMT</pubDate>
<description><![CDATA[2021 年 08 月 11 日,微软发布了 .NET 6 Preview 7 版本Furion 在当天第一时间适配了该版本,并发布 Furion v3.0.0-rc.2 版本。]]></description>
<content:encoded><![CDATA[<p><strong>2021 年 08 月 11 日,微软发布了 <code>.NET 6 Preview 7</code> 版本,<code>Furion</code> 在当天第一时间适配了该版本,并发布 <code>Furion v3.0.0-rc.2</code> 版本。</strong></p>
<p><a href="https://gitee.com/dotnetchina/Furion/tree/3.0.0-rc.2/" target="_blank" rel="noopener noreferrer">Furion .NET 6 Preview 7 源码地址</a></p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="安装-net-6-preview-6-sdk">安装 <code>.NET 6 Preview 6 SDK</code><a href="http://furion.baiqian.ltd/blog/net6-preview7#%E5%AE%89%E8%A3%85-net-6-preview-6-sdk" class="hash-link" aria-label="Direct link to 安装-net-6-preview-6-sdk" title="Direct link to 安装-net-6-preview-6-sdk"></a></h2>
<p>尝鲜之前,首先先安装 <code>.NET 6 Preview 7 SDK</code>,下载地址:<a href="https://dotnet.microsoft.com/download/dotnet/6.0" target="_blank" rel="noopener noreferrer">https://dotnet.microsoft.com/download/dotnet/6.0</a></p>
<p>下载对应系统和处理器版本即可。</p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="旧项目升级">旧项目升级<a href="http://furion.baiqian.ltd/blog/net6-preview7#%E6%97%A7%E9%A1%B9%E7%9B%AE%E5%8D%87%E7%BA%A7" class="hash-link" aria-label="Direct link to 旧项目升级" title="Direct link to 旧项目升级"></a></h2>
<p>编辑所有 <code>.csproj</code> 项目,修改 <code>&lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt;</code><code>&lt;TargetFramework&gt;net6.0&lt;/TargetFramework&gt;</code></p>
<p>同时升级所有 <code>Microsoft</code><code>Furion</code> 包为最新版本,<code>Furion</code> 最新版本为:<code>v3.0.0-rc.1</code></p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="新项目使用">新项目使用<a href="http://furion.baiqian.ltd/blog/net6-preview7#%E6%96%B0%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8" class="hash-link" aria-label="Direct link to 新项目使用" title="Direct link to 新项目使用"></a></h2>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="升级-visual-studio-2019">升级 <code>Visual Studio 2019</code><a href="http://furion.baiqian.ltd/blog/net6-preview7#%E5%8D%87%E7%BA%A7-visual-studio-2019" class="hash-link" aria-label="Direct link to 升级-visual-studio-2019" title="Direct link to 升级-visual-studio-2019"></a></h3>
<p>目前 <code>.NET 6 Preview 7</code> 支持使用 <code>Visual Studio 2019 Preview 16.11.0 Preview 4.0</code> 版本,<strong>注意是 <code>Preview</code> 最新版本</strong>。下载地址:<a href="https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16" target="_blank" rel="noopener noreferrer">https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16</a></p>
<p>已经安装了 <code>Visual Studio 2019 Preview</code> 版本的朋友直接升级到最新版即可。</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>特别说明</div><div class="admonitionContent_BuS1"><p>如果使用 <code>Visual Studio Code</code> 开发,可忽略此选项。</p></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="第一个例子">第一个例子<a href="http://furion.baiqian.ltd/blog/net6-preview7#%E7%AC%AC%E4%B8%80%E4%B8%AA%E4%BE%8B%E5%AD%90" class="hash-link" aria-label="Direct link to 第一个例子" title="Direct link to 第一个例子"></a></h3>
<p><code>Furion v3.0.0-rc.2</code> 目前提供了所有类型的脚手架,版本号统一 <code>3.0.0-rc.2</code></p>
<p>安装脚手架,打开 <code>CMD/Powershell</code> 执行以下命令:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new --install Furion.Template.Api::3.0.0-rc.2</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>创建项目</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new furionapi -n FurionNET6</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="打开并启动项目">打开并启动项目<a href="http://furion.baiqian.ltd/blog/net6-preview7#%E6%89%93%E5%BC%80%E5%B9%B6%E5%90%AF%E5%8A%A8%E9%A1%B9%E7%9B%AE" class="hash-link" aria-label="Direct link to 打开并启动项目" title="Direct link to 打开并启动项目"></a></h3>
<p>打开浏览器查看效果即可。</p>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>.net6</category>
</item>
<item>
<title><![CDATA[5. 在控制台中使用]]></title>
<link>http://furion.baiqian.ltd/blog/console</link>
<guid>http://furion.baiqian.ltd/blog/console</guid>
<pubDate>Sat, 24 Jul 2021 00:00:00 GMT</pubDate>
<description><![CDATA[当前内容已过时,请查看 2.1 入门指南 - 2.1.10.3 Console 初始化]]></description>
<content:encoded><![CDATA[<div class="theme-admonition theme-admonition-warning admonition_xJq3 alert alert--warning"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>内容过时</div><div class="admonitionContent_BuS1"><p>当前内容已过时,请查看 <a href="http://furion.baiqian.ltd/docs/serverun#21103-console-%E5%88%9D%E5%A7%8B%E5%8C%96">2.1 入门指南 - 2.1.10.3 <code>Console</code> 初始化</a></p></div></div>
<p><code>Furion</code><code>v2.15.3+</code> 版本开始,支持全平台应用程序开发,包括 <code>Web</code><code>控制台</code><code>WinForm</code><code>WPF</code><code>Xamarin/MAUI</code> 等。</p>
<p>在控制台中使用示例:</p>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DependencyInjection</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Furion</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">RemoteRequest</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">Extensions</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">Microsoft</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">Extensions</span><span class="token namespace punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token namespace" style="color:rgb(178, 204, 214)">DependencyInjection</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">using</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">System</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">namespace</span><span class="token plain"> </span><span class="token namespace" style="color:rgb(178, 204, 214)">ConsoleApp1</span><span clas
<p>以上代码通过 <code>var services = Inject.Create();</code> 创建一个服务集合,最后通过 <code>services.Build()</code> 即可完成初始化。</p>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>.net6</category>
</item>
<item>
<title><![CDATA[4. .NET 6 Preview 6 尝鲜]]></title>
<link>http://furion.baiqian.ltd/blog/net6-preview6</link>
<guid>http://furion.baiqian.ltd/blog/net6-preview6</guid>
<pubDate>Thu, 15 Jul 2021 00:00:00 GMT</pubDate>
<description><![CDATA[2021 年 07 月 15 日,微软发布了 .NET 6 Preview 6 版本Furion 在当天第一时间适配了该版本,并发布 Furion v3.0.0-rc.1 版本。]]></description>
<content:encoded><![CDATA[<p><strong>2021 年 07 月 15 日,微软发布了 <code>.NET 6 Preview 6</code> 版本,<code>Furion</code> 在当天第一时间适配了该版本,并发布 <code>Furion v3.0.0-rc.1</code> 版本。</strong></p>
<p><a href="https://gitee.com/dotnetchina/Furion/tree/3.0.0-rc.1/" target="_blank" rel="noopener noreferrer">Furion .NET 6 Preview 6 源码地址</a></p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="安装-net-6-preview-6-sdk">安装 <code>.NET 6 Preview 6 SDK</code><a href="http://furion.baiqian.ltd/blog/net6-preview6#%E5%AE%89%E8%A3%85-net-6-preview-6-sdk" class="hash-link" aria-label="Direct link to 安装-net-6-preview-6-sdk" title="Direct link to 安装-net-6-preview-6-sdk"></a></h2>
<p>尝鲜之前,首先先安装 <code>.NET 6 Preview 6 SDK</code>,下载地址:<a href="https://dotnet.microsoft.com/download/dotnet/6.0" target="_blank" rel="noopener noreferrer">https://dotnet.microsoft.com/download/dotnet/6.0</a></p>
<p>下载对应系统和处理器版本即可。</p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="旧项目升级">旧项目升级<a href="http://furion.baiqian.ltd/blog/net6-preview6#%E6%97%A7%E9%A1%B9%E7%9B%AE%E5%8D%87%E7%BA%A7" class="hash-link" aria-label="Direct link to 旧项目升级" title="Direct link to 旧项目升级"></a></h2>
<p>编辑所有 <code>.csproj</code> 项目,修改 <code>&lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt;</code><code>&lt;TargetFramework&gt;net6.0&lt;/TargetFramework&gt;</code></p>
<p>同时升级所有 <code>Microsoft</code><code>Furion</code> 包为最新版本,<code>Furion</code> 最新版本为:<code>v3.0.0-rc.1</code></p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="新项目使用">新项目使用<a href="http://furion.baiqian.ltd/blog/net6-preview6#%E6%96%B0%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8" class="hash-link" aria-label="Direct link to 新项目使用" title="Direct link to 新项目使用"></a></h2>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="升级-visual-studio-2019">升级 <code>Visual Studio 2019</code><a href="http://furion.baiqian.ltd/blog/net6-preview6#%E5%8D%87%E7%BA%A7-visual-studio-2019" class="hash-link" aria-label="Direct link to 升级-visual-studio-2019" title="Direct link to 升级-visual-studio-2019"></a></h3>
<p>目前 <code>.NET 6 Preview 6</code> 支持使用 <code>Visual Studio 2019 Preview 16.11.0 Preview 3.0</code> 版本,<strong>注意是 <code>Preview</code> 最新版本</strong>。下载地址:<a href="https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16" target="_blank" rel="noopener noreferrer">https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16</a></p>
<p>已经安装了 <code>Visual Studio 2019 Preview</code> 版本的朋友直接升级到最新版即可。</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>特别说明</div><div class="admonitionContent_BuS1"><p>如果使用 <code>Visual Studio Code</code> 开发,可忽略此选项。</p></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="第一个例子">第一个例子<a href="http://furion.baiqian.ltd/blog/net6-preview6#%E7%AC%AC%E4%B8%80%E4%B8%AA%E4%BE%8B%E5%AD%90" class="hash-link" aria-label="Direct link to 第一个例子" title="Direct link to 第一个例子"></a></h3>
<p><code>Furion v3.0.0-rc.1</code> 目前提供了所有类型的脚手架,版本号统一 <code>3.0.0-rc.1</code></p>
<p>安装脚手架,打开 <code>CMD/Powershell</code> 执行以下命令:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new --install Furion.Template.Api::3.0.0-rc.1</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>创建项目</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new furionapi -n FurionNET6</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="打开并启动项目">打开并启动项目<a href="http://furion.baiqian.ltd/blog/net6-preview6#%E6%89%93%E5%BC%80%E5%B9%B6%E5%90%AF%E5%8A%A8%E9%A1%B9%E7%9B%AE" class="hash-link" aria-label="Direct link to 打开并启动项目" title="Direct link to 打开并启动项目"></a></h3>
<p>打开浏览器查看效果即可。</p>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>.net6</category>
</item>
<item>
<title><![CDATA[3. .NET 6 Preview 5 尝鲜]]></title>
<link>http://furion.baiqian.ltd/blog/net6-preview5</link>
<guid>http://furion.baiqian.ltd/blog/net6-preview5</guid>
<pubDate>Fri, 18 Jun 2021 00:00:00 GMT</pubDate>
<description><![CDATA[2021 年 06 月 18 日,微软发布了 .NET 6 Preview 5 版本Furion 在当天第一时间适配了该版本,并发布 Furion v3.0.0-preview.5.21301.9 版本。]]></description>
<content:encoded><![CDATA[<p><strong>2021 年 06 月 18 日,微软发布了 <code>.NET 6 Preview 5</code> 版本,<code>Furion</code> 在当天第一时间适配了该版本,并发布 <code>Furion v3.0.0-preview.5.21301.9</code> 版本。</strong></p>
<p><a href="https://gitee.com/dotnetchina/Furion/tree/net6.0-preview5/" target="_blank" rel="noopener noreferrer">Furion .NET 6 Preview 5 源码地址</a></p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="等不及尝鲜了">等不及尝鲜了<a href="http://furion.baiqian.ltd/blog/net6-preview5#%E7%AD%89%E4%B8%8D%E5%8F%8A%E5%B0%9D%E9%B2%9C%E4%BA%86" class="hash-link" aria-label="Direct link to 等不及尝鲜了" title="Direct link to 等不及尝鲜了"></a></h2>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="安装-net-6-preview-5-sdk">安装 <code>.NET 6 Preview 5 SDK</code><a href="http://furion.baiqian.ltd/blog/net6-preview5#%E5%AE%89%E8%A3%85-net-6-preview-5-sdk" class="hash-link" aria-label="Direct link to 安装-net-6-preview-5-sdk" title="Direct link to 安装-net-6-preview-5-sdk"></a></h3>
<p>尝鲜之前,首先先安装 <code>.NET 6 Preview 5 SDK</code>,下载地址:<a href="https://dotnet.microsoft.com/download/dotnet/6.0" target="_blank" rel="noopener noreferrer">https://dotnet.microsoft.com/download/dotnet/6.0</a></p>
<p>下载对应系统和处理器版本即可。</p>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="升级-visual-studio-2019">升级 <code>Visual Studio 2019</code><a href="http://furion.baiqian.ltd/blog/net6-preview5#%E5%8D%87%E7%BA%A7-visual-studio-2019" class="hash-link" aria-label="Direct link to 升级-visual-studio-2019" title="Direct link to 升级-visual-studio-2019"></a></h3>
<p>目前 <code>.NET 6 Preview 5</code> 支持使用 <code>Visual Studio 2019 Preview 16.11.0 Preview 2.0</code> 版本,<strong>注意是 <code>Preview</code> 最新版本</strong>。下载地址:<a href="https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16" target="_blank" rel="noopener noreferrer">https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=enterprise&amp;ch=pre&amp;rel=16</a></p>
<p>已经安装了 <code>Visual Studio 2019 Preview</code> 版本的朋友直接升级到最新版即可。</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>特别说明</div><div class="admonitionContent_BuS1"><p>如果使用 <code>Visual Studio Code</code> 开发,可忽略此选项。</p></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="第一个例子">第一个例子<a href="http://furion.baiqian.ltd/blog/net6-preview5#%E7%AC%AC%E4%B8%80%E4%B8%AA%E4%BE%8B%E5%AD%90" class="hash-link" aria-label="Direct link to 第一个例子" title="Direct link to 第一个例子"></a></h3>
<p><code>Furion v3.0.0-preview.5.21301.9</code> 目前提供了所有类型的脚手架,版本号统一 <code>3.0.0-preview.5.21301.9</code></p>
<p>安装脚手架,打开 <code>CMD/Powershell</code> 执行以下命令:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new --install Furion.Template.Api::3.0.0-preview.5.21301.9</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>创建项目</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">dotnet new furionapi -n FurionNET6</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="打开并启动项目">打开并启动项目<a href="http://furion.baiqian.ltd/blog/net6-preview5#%E6%89%93%E5%BC%80%E5%B9%B6%E5%90%AF%E5%8A%A8%E9%A1%B9%E7%9B%AE" class="hash-link" aria-label="Direct link to 打开并启动项目" title="Direct link to 打开并启动项目"></a></h3>
<p>打开浏览器查看效果即可。</p>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>.net6</category>
</item>
<item>
<title><![CDATA[2. 文件上传下载]]></title>
<link>http://furion.baiqian.ltd/blog/fileupload-download</link>
<guid>http://furion.baiqian.ltd/blog/fileupload-download</guid>
<pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
<description><![CDATA[文件下载]]></description>
<content:encoded><![CDATA[<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="文件下载">文件下载<a href="http://furion.baiqian.ltd/blog/fileupload-download#%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD" class="hash-link" aria-label="Direct link to 文件下载" title="Direct link to 文件下载"></a></h2>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token attribute class-name" style="color:rgb(255, 203, 107)">HttpGet</span><span class="token attribute punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token attribute"> </span><span class="token attribute class-name" style="color:rgb(255, 203, 107)">NonUnify</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token return-type class-name" style="color:rgb(255, 203, 107)">IActionResult</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">FileDownload</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">string</span><span class="token plain"> path</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">string</span><span class="token plain"> fileName</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">string</span><span class="token plain"> filePath </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">"这里获取完整的文件下载路径"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">return</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">new</span><span class="token plain"> </span><span class="token constructor-invocation class-name" style="color:rgb(255, 203, 107)">FileStreamResult</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">new</span><span class="token plain"> </span><span class="token constructor-invocation class-name" style="color:rgb(255, 203, 107)">FileStream</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">filePath</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> FileMode</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>关于前端获取文件名</div><div class="admonitionContent_BuS1"><p>如果前端获取不到文件夹,可添加以下配置:</p><div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">_httpContextAccessor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">HttpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">Add</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">"Content-Disposition"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token interpolation-string string" style="color:rgb(195, 232, 141)">$"attachment; filename=</span><span class="token interpolation-string interpolation punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token interpolation-string interpolation expression language-csharp">文件名</span><span class="token interpolation-string interpolation punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token interpolation-string string" style="color:rgb(195, 232, 141)">"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">_httpContextAccessor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">HttpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">Add</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">"Access-Control-Expose-Headers"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">"Content-Disposition"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></spa
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="文件上传">文件上传<a href="http://furion.baiqian.ltd/blog/fileupload-download#%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0" class="hash-link" aria-label="Direct link to 文件上传" title="Direct link to 文件上传"></a></h2>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token attribute class-name" style="color:rgb(255, 203, 107)">HttpPost</span><span class="token attribute punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token attribute"> </span><span class="token attribute class-name" style="color:rgb(255, 203, 107)">NonUnify</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">async</span><span class="token plain"> </span><span class="token return-type class-name" style="color:rgb(255, 203, 107)">Task</span><span class="token return-type class-name punctuation" style="color:rgb(199, 146, 234)">&lt;</span><span class="token return-type class-name" style="color:rgb(255, 203, 107)">IActionResult</span><span class="token return-type class-name punctuation" style="color:rgb(199, 146, 234)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">UploadFileAsync</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token class-name" style="color:rgb(255, 203, 107)">List</span><span class="token class-name punctuation" style="color:rgb(199, 146, 234)">&lt;</span><span class="token class-name" style="color:rgb(255, 203, 107)">IFormFile</span><span class="token class-name punctuation" style="color:rgb(199, 146, 234)">&gt;</span><span class="token plain"> files</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// 保存到网站根目录下的 uploads 目录</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> savePath </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Path</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">Combine</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">App</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">HostEnvironment</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">ContentRootPath</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>关于使用axios上传文件,方法获取到参数files.Count=0</div><div class="admonitionContent_BuS1"><p>axios请求配置</p><div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">let</span><span class="token plain"> formData </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">new</span><span class="token plain"> </span><span class="token constructor-invocation class-name" style="color:rgb(255, 203, 107)">FormData</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> formData</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">append</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">"files"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">file</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">//files需与方法里的参数files名称一样</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">let</span><span class="token plain"> config </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>upload</category>
<category>download</category>
</item>
<item>
<title><![CDATA[1. HttpContext 应用]]></title>
<link>http://furion.baiqian.ltd/blog/httpcontext</link>
<guid>http://furion.baiqian.ltd/blog/httpcontext</guid>
<pubDate>Mon, 01 Feb 2021 00:00:00 GMT</pubDate>
<description><![CDATA[HttpContext 重大调整]]></description>
<content:encoded><![CDATA[<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="httpcontext-重大调整">HttpContext 重大调整<a href="http://furion.baiqian.ltd/blog/httpcontext#httpcontext-%E9%87%8D%E5%A4%A7%E8%B0%83%E6%95%B4" class="hash-link" aria-label="Direct link to HttpContext 重大调整" title="Direct link to HttpContext 重大调整"></a></h2>
<p><code>ASP.NET</code> 的时代,我们通常通过 <code>HttpContext</code> 全局静态类获取请求上下文,但在 <code>ASP.NET Core</code> 中,<code>HttpContext</code> 是一个非静态的抽象类,无法手动创建,也无法通过静态获取。</p>
<p>虽然在 <code>ASP.NET Core</code> 中无法直接获取 <code>HttpContext</code> 对象。但是微软也提供了注入 <code>IHttpContextAccessor</code> 方式获取。</p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="httpcontext-多种获取方式">HttpContext 多种获取方式<a href="http://furion.baiqian.ltd/blog/httpcontext#httpcontext-%E5%A4%9A%E7%A7%8D%E8%8E%B7%E5%8F%96%E6%96%B9%E5%BC%8F" class="hash-link" aria-label="Direct link to HttpContext 多种获取方式" title="Direct link to HttpContext 多种获取方式"></a></h2>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="在-controllerbase-派生类中"><code>ControllerBase</code> 派生类中<a href="http://furion.baiqian.ltd/blog/httpcontext#%E5%9C%A8-controllerbase-%E6%B4%BE%E7%94%9F%E7%B1%BB%E4%B8%AD" class="hash-link" aria-label="Direct link to 在-controllerbase-派生类中" title="Direct link to 在-controllerbase-派生类中"></a></h3>
<p><code>ControllerBase</code> 派生类中,我们可以直接通过 <code>HttpContext</code> 属性获取 <code>HttpContext</code> 对象。</p>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="通过注入-ihttpcontextaccessor">通过注入 <code>IHttpContextAccessor</code><a href="http://furion.baiqian.ltd/blog/httpcontext#%E9%80%9A%E8%BF%87%E6%B3%A8%E5%85%A5-ihttpcontextaccessor" class="hash-link" aria-label="Direct link to 通过注入-ihttpcontextaccessor" title="Direct link to 通过注入-ihttpcontextaccessor"></a></h3>
<p><code>Furion</code> 框架中,默认已经注册了 <code>IHttpContextAccessor</code> 服务,所以我们可以通过构造函数注入该对象获取。</p>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">class</span><span class="token plain"> </span><span class="token class-name" style="color:rgb(255, 203, 107)">AppService</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">AppService</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token class-name" style="color:rgb(255, 203, 107)">IHttpContextAccessor</span><span class="token plain"> httpContextAccessor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> httpContext </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContextAccessor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">HttpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="通过-apphttpcontext">通过 <code>App.HttpContext</code><a href="http://furion.baiqian.ltd/blog/httpcontext#%E9%80%9A%E8%BF%87-apphttpcontext" class="hash-link" aria-label="Direct link to 通过-apphttpcontext" title="Direct link to 通过-apphttpcontext"></a></h3>
<p><code>App</code> 静态类也提供了 <code>App.HttpContext</code> 获取 <code>HttpContext</code> 对象。</p>
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="httpcontext-拓展方法"><code>HttpContext</code> 拓展方法<a href="http://furion.baiqian.ltd/blog/httpcontext#httpcontext-%E6%8B%93%E5%B1%95%E6%96%B9%E6%B3%95" class="hash-link" aria-label="Direct link to httpcontext-拓展方法" title="Direct link to httpcontext-拓展方法"></a></h2>
<p><code>Furion</code> 框架也提供了一些常用的 <code>HttpContext</code> 拓展方法</p>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="获取当前请求的特性">获取当前请求的特性<a href="http://furion.baiqian.ltd/blog/httpcontext#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E8%AF%B7%E6%B1%82%E7%9A%84%E7%89%B9%E6%80%A7" class="hash-link" aria-label="Direct link to 获取当前请求的特性" title="Direct link to 获取当前请求的特性"></a></h3>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> attribute </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token generic-method function" style="color:rgb(130, 170, 255)">GetMetadata</span><span class="token generic-method generic class-name punctuation" style="color:rgb(199, 146, 234)">&lt;</span><span class="token generic-method generic class-name" style="color:rgb(255, 203, 107)">SomeAttribute</span><span class="token generic-method generic class-name punctuation" style="color:rgb(199, 146, 234)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="设置-swagger-自动授权">设置 <code>Swagger</code> 自动授权<a href="http://furion.baiqian.ltd/blog/httpcontext#%E8%AE%BE%E7%BD%AE-swagger-%E8%87%AA%E5%8A%A8%E6%8E%88%E6%9D%83" class="hash-link" aria-label="Direct link to 设置-swagger-自动授权" title="Direct link to 设置-swagger-自动授权"></a></h3>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">SigninToSwagger</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">"你的token"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="退出-swagger-授权">退出 <code>Swagger</code> 授权<a href="http://furion.baiqian.ltd/blog/httpcontext#%E9%80%80%E5%87%BA-swagger-%E6%8E%88%E6%9D%83" class="hash-link" aria-label="Direct link to 退出-swagger-授权" title="Direct link to 退出-swagger-授权"></a></h3>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">SignoutToSwagger</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="获取本地-ip-地址">获取本地 IP 地址<a href="http://furion.baiqian.ltd/blog/httpcontext#%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%9C%B0-ip-%E5%9C%B0%E5%9D%80" class="hash-link" aria-label="Direct link to 获取本地 IP 地址" title="Direct link to 获取本地 IP 地址"></a></h3>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> ipv4 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">GetLocalIpAddressToIPv4</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> ipv6 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">GetLocalIpAddressToIPv6</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="获取客户端-ip-地址">获取客户端 IP 地址<a href="http://furion.baiqian.ltd/blog/httpcontext#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E7%AB%AF-ip-%E5%9C%B0%E5%9D%80" class="hash-link" aria-label="Direct link to 获取客户端 IP 地址" title="Direct link to 获取客户端 IP 地址"></a></h3>
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> ipv4 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">GetRemoteIpAddressToIPv4</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> ipv6 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> httpContext</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">GetRemoteIpAddressToIPv6</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>]]></content:encoded>
<category>furion</category>
<category>furos</category>
<category>.net</category>
<category>.netcore</category>
<category>.net5</category>
<category>httpcontext</category>
</item>
</channel>
</rss>