Skip to content

Commit 0f03b04

Browse files
committed
Enhance the configuration document
1 parent fed0e97 commit 0f03b04

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

docs/en/framework/architecture/modularity/basics.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Modularity
22

3-
## Introduction
4-
53
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;
64

75
* This document introduces the basics of the module system.
Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
11
# Configuration
22

3-
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.
3+
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.
4+
5+
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.
6+
7+
## Getting the Configuration
8+
9+
You may need to get the `IConfiguration` service in various places in your codebase. The following section shows two common ways.
10+
11+
### In Module Classes
12+
13+
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:
14+
15+
````csharp
16+
public class MyAppModule : AbpModule
17+
{
18+
public override void ConfigureServices(ServiceConfigurationContext context)
19+
{
20+
var connectionString = context.Configuration["ConnectionStrings:Default"];
21+
}
22+
}
23+
````
24+
25+
`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).
26+
27+
### In Your Services
28+
29+
You can directly [inject](dependency-injection.md) the `IConfiguration` service into your services:
30+
31+
````csharp
32+
public class MyService : ITransientDependency
33+
{
34+
private readonly IConfiguration _configuration;
35+
36+
public MyService(IConfiguration configuration)
37+
{
38+
_configuration = configuration;
39+
}
40+
41+
public string? GetConnectionString()
42+
{
43+
return _configuration["ConnectionStrings:Default"];
44+
}
45+
}
46+
````
47+
48+
## See Also
49+
50+
* [Microsoft's Configuration Documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/)
51+
* [The Options Pattern](options.md)
52+

0 commit comments

Comments
 (0)