Browse Source

Added new sections to the Connection-Strings and Dependency-Injection documents.

pull/2599/head
Halil İbrahim Kalkan 6 years ago
parent
commit
1a449829db
  1. 11
      docs/en/Connection-Strings.md
  2. 20
      docs/en/Dependency-Injection.md

11
docs/en/Connection-Strings.md

@ -61,4 +61,13 @@ Once you want to separate a module's database, you typically will need to create
## Multi-Tenancy
See [the multi-tenancy document](Multi-Tenancy.md) to learn how to use separate databases for tenants.
See [the multi-tenancy document](Multi-Tenancy.md) to learn how to use separate databases for tenants.
## Replace the Connection String Resolver
ABP defines the `IConnectionStringResolver` and uses it whenever it needs a connection string. It has two pre-built implementations:
* `DefaultConnectionStringResolver` uses the `AbpDbConnectionOptions` to select the connection string based on the rules defined in the "Configure the Connection Strings" section above.
* `MultiTenantConnectionStringResolver` used for multi-tenant applications and tries to get the configured connection string for the current tenant if available. It uses the `ITenantStore` to find the connection strings. It inherits from the `DefaultConnectionStringResolver` and fallbacks to the base logic if no connection string specified for the current tenant.
If you need a custom logic to determine the connection string, implement the `IConnectionStringResolver` interface (optionally derive from the existing implementations) and replace the existing implementation using the [dependency injection](Dependency-Injection.md) system.

20
docs/en/Dependency-Injection.md

@ -166,6 +166,26 @@ public class BlogModule : AbpModule
}
````
### Replace a Service
If you need to replace an existing service (defined by the ABP framework or another module dependency), you have two options;
1. Use the `Dependency` attribute of the ABP framework as explained above.
2. Use the `IServiceCollection.Replace` method of the Microsoft Dependency Injection library. Example:
````csharp
public class MyModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
//Replacing the IConnectionStringResolver service
context.Services.Replace(ServiceDescriptor.Transient<IConnectionStringResolver, MyConnectionStringResolver>());
}
}
````
## Injecting Dependencies
There are three common ways of using a service that has already been registered.

Loading…
Cancel
Save