简体   繁体   English

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

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

I am new to ASP.net and I am making project using MVC model.我是 ASP.net 的新手,我正在使用 MVC model 制作项目。 In my startup.cs file there is a code which i am trying to understand.在我的 startup.cs 文件中有一个我试图理解的代码。 I am following documentation provided by the Microsoft official website.我正在关注微软官方网站提供的文档。

public IConfiguration Configuration { get; }

I just want to know what type of function is this?我只想知道这是什么型号的function?

This is a Property : https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties这是一个Propertyhttps://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties

A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field.属性是提供灵活机制来读取、写入或计算私有字段值的成员。 Properties can be used as if they are public data members, but they are actually special methods called accessors.属性可以像公共数据成员一样使用,但它们实际上是称为访问器的特殊方法。 This enables data to be accessed easily and still helps promote the safety and flexibility of methods.这使得数据可以轻松访问,并且仍然有助于提高方法的安全性和灵活性。

Basically, syntactic sugar for the following基本上,以下的语法糖

private IConfiguration configuration;

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

Getters and setters, provide in general better encapsulation of the classes members. Getter 和 setter 通常提供对类成员的更好封装。 C# offers this way, to access encapsulated state as you would access a member directly. C# 提供了这种方式,可以像直接访问成员一样访问封装的 state。

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

Represents a set of key/value application configuration properties.表示一组键/值应用程序配置属性。

It's an interface that enables you to choose any configuration provider you wish and access it in a seamless way.它是一个界面,使您能够选择所需的任何配置提供程序并以无缝方式访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM