From 0f03b04992014eda30fcec9c2c645660b3c7503f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 1 May 2025 18:16:30 +0300 Subject: [PATCH] Enhance the configuration document --- .../architecture/modularity/basics.md | 2 - .../framework/fundamentals/configuration.md | 51 ++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/docs/en/framework/architecture/modularity/basics.md b/docs/en/framework/architecture/modularity/basics.md index f92e6edc3b..2b3aaad214 100644 --- a/docs/en/framework/architecture/modularity/basics.md +++ b/docs/en/framework/architecture/modularity/basics.md @@ -1,7 +1,5 @@ # Modularity -## Introduction - ABP was designed to support to build fully modular applications and systems where every module may have entities, services, database integration, APIs, UI components and so on; * This document introduces the basics of the module system. diff --git a/docs/en/framework/fundamentals/configuration.md b/docs/en/framework/fundamentals/configuration.md index 7611017b7e..94476f25ab 100644 --- a/docs/en/framework/fundamentals/configuration.md +++ b/docs/en/framework/fundamentals/configuration.md @@ -1,3 +1,52 @@ # Configuration -ASP.NET Core has an flexible and extensible key-value based configuration system. In fact, 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](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) to learn the configuration infrastructure. ABP is 100% compatible with the configuration system. \ No newline at end of file +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](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) 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](../architecture/modularity/basics.md) as the following example: + +````csharp +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. You can use any of them (`IServiceCollection.GetConfiguration` is an extension method that can be used whenever you have an `IServiceCollection` object). + +### In Your Services + +You can directly [inject](dependency-injection.md) the `IConfiguration` service into your services: + +````csharp +public class MyService : ITransientDependency +{ + private readonly IConfiguration _configuration; + + public MyService(IConfiguration configuration) + { + _configuration = configuration; + } + + public string? GetConnectionString() + { + return _configuration["ConnectionStrings:Default"]; + } +} +```` + +## See Also + +* [Microsoft's Configuration Documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) +* [The Options Pattern](options.md) +