diff --git a/docs/en/Connection-Strings.md b/docs/en/Connection-Strings.md index a080e10dea..57a156ff7b 100644 --- a/docs/en/Connection-Strings.md +++ b/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. \ No newline at end of file +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. \ No newline at end of file diff --git a/docs/en/Dependency-Injection.md b/docs/en/Dependency-Injection.md index eb0da4a0e4..73cd8095ea 100644 --- a/docs/en/Dependency-Injection.md +++ b/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()); + } +} +```` + + + ## Injecting Dependencies There are three common ways of using a service that has already been registered.