Filter by title

Configuration

ASP.NET Core has an flexible and extensible key-value based configuration system. The configuration system is a part of Microsoft.Extensions libraries and it is independent from ASP.NET Core. That means it can be used in any type of application.

See Microsoft's documentation to learn the configuration infrastructure. ABP is 100% compatible with the configuration system.

Getting the Configuration

You may need to get the IConfiguration service in various places in your codebase. The following section shows two common ways.

In Module Classes

You typically need to get configuration while initializing your application. You can get the IConfiguration service using the ServiceConfigurationContext.Configuration property inside your module class as the following example:

public class MyAppModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var connectionString = context.Configuration["ConnectionStrings:Default"];
    }
}

context.Configuration is a shortcut property for the context.Services.GetConfiguration() method. In general, prefer using context.Configuration for simplicity and readability when working within module classes. Use context.Services.GetConfiguration() in other contexts where you have an IServiceCollection object but do not have access to the context.Configuration property. (IServiceCollection.GetConfiguration is an extension method that can be used whenever you have an IServiceCollection object).

In Your Services

You can directly inject the IConfiguration service into your services:

public class MyService : ITransientDependency
{
    private readonly IConfiguration _configuration;

    public MyService(IConfiguration configuration)
    {
        _configuration = configuration;
    }
    
    public string? GetConnectionString()
    {
        return _configuration["ConnectionStrings:Default"];
    }
}

See Also

Contributors


Last updated: May 01, 2025 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document

ABP Framework ve .NET ile Canlı Modular Monolith Uygulama Geliştiriyoruz

03 Jul, 17:00
Online
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book