Browse Source

Update `Dependency-Injection.md`.

pull/18259/head
maliming 2 years ago
parent
commit
3bfdcb2eb3
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 18
      docs/en/Dependency-Injection.md
  2. 18
      docs/zh-Hans/Dependency-Injection.md

18
docs/en/Dependency-Injection.md

@ -480,6 +480,24 @@ This example simply checks if the service class has `MyLogAttribute` attribute a
> Notice that `OnRegistered` callback might be called multiple times for the same service class if it exposes more than one service/interface. So, it's safe to use `Interceptors.TryAdd` method instead of `Interceptors.Add` method. See [the documentation](Dynamic-Proxying-Interceptors.md) of dynamic proxying / interceptors.
### IServiceCollection.OnActivated Event
The `OnActivated` event is raised once a service is fully constructed. Here you can perform application-level tasks that depend on the service being fully constructed - these should be rare.
````csharp
var serviceDescriptor = ServiceDescriptor.Transient<MyServer, MyServer>();
services.Add(serviceDescriptor);
if (setIsReadOnly)
{
services.OnActivated(serviceDescriptor, x =>
{
x.Instance.As<MyServer>().IsReadOnly = true;
});
}
````
> Notice that `OnActivated` event can be registered multiple times for the same `ServiceDescriptor`.
## 3rd-Party Providers
While ABP has no core dependency to any 3rd-party DI provider, it's required to use a provider that supports dynamic proxying and some other advanced features to make some ABP features properly work.

18
docs/zh-Hans/Dependency-Injection.md

@ -310,6 +310,24 @@ public class AppModule : AbpModule
> 注意, 如果服务类公开了多于一个服务或接口, `OnRegistered` 回调(callback)可能被同一服务类多次调用. 因此, 较安全的方法是使用 `Interceptors.TryAdd` 方法而不是 `Interceptors.Add` 方法. 请参阅动态代理(dynamic proxying)/拦截器 [文档](Dynamic-Proxying-Interceptors.md).
### IServiceCollection.OnActivated 事件
一旦服务完全构建完成`OnActivated`事件就会触发. 你可以执行依赖于服务已完全构建的的一些任务, 虽然这种情况可能很少见.
````csharp
var serviceDescriptor = ServiceDescriptor.Transient<MyServer, MyServer>();
services.Add(serviceDescriptor);
if (setIsReadOnly)
{
services.OnActivated(serviceDescriptor, x =>
{
x.Instance.As<MyServer>().IsReadOnly = true;
});
}
````
> 注意,`OnActivated`事件可以为一个`ServiceDescriptor`注册多次.
## 第三方提供程序
虽然ABP框架没有对任何第三方DI提供程序的核心依赖, 但它必须使用一个提供程序来支持动态代理(dynamic proxying)和一些高级特性以便ABP特性能正常工作.

Loading…
Cancel
Save