简体   繁体   中英

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

I am new to ASP.net and I am making project using MVC model. In my startup.cs file there is a code which i am trying to understand. 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?

This is a Property : https://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. C# offers this way, to access encapsulated state as you would access a member directly.

The IConfiguration interface is described here: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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