簡體   English   中英

在 ASP.net 中,所謂的“公共 IConfiguration 配置”是什么?

[英]In ASP.net what is “public IConfiguration Configuration” called?

我是 ASP.net 的新手,我正在使用 MVC model 制作項目。 在我的 startup.cs 文件中有一個我試圖理解的代碼。 我正在關注微軟官方網站提供的文檔。

public IConfiguration Configuration { get; }

我只想知道這是什么型號的function?

這是一個Propertyhttps://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties

屬性是提供靈活機制來讀取、寫入或計算私有字段值的成員。 屬性可以像公共數據成員一樣使用,但它們實際上是稱為訪問器的特殊方法。 這使得數據可以輕松訪問,並且仍然有助於提高方法的安全性和靈活性。

基本上,以下的語法糖

private IConfiguration configuration;

public IConfiguration GetConfiguration() {
    return this.configuration;
}

Getter 和 setter 通常提供對類成員的更好封裝。 C# 提供了這種方式,可以像直接訪問成員一樣訪問封裝的 state。

IConfiguration接口在此處描述: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration?view=dotnet-plat-ext-5.0

表示一組鍵/值應用程序配置屬性。

它是一個界面,使您能夠選擇所需的任何配置提供程序並以無縫方式訪問它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM