DependencyInjection post-registration support

Copper Contributor












另外,我在Simple Injector的文档中找到了关于类似满足的方法,不知道DependencyInjection是否有同样的支持。








I now have a need for such:
During the use of universal hosting, IHostBuilder extensions and hosted services (HostedService) are used, and a plugin registration mechanism is used.


First, some necessary services, etc., will be registered through the normal HostBuilder behavior; then in a separate module, an IHostBuilder extension will be implemented and a HostedService service will be injected.


In this HostedService service, it will read all the plug-in information, and after passing the series verification, it will reflect the plug-in operation.

The reflection operation of this plug-in is not expected to affect the whole generic host startup process or block the startup process; so it should start working only after the main work of the generic host part is finished, and by this time the creation and startup of services such as dependency injection are finished, and the plug-in starts working.


Plugin contains three (InitializeAsync, StartAsync, StopAsync) basic interface definitions, I want to be able to InitializeAsync method again in the service container for service registration and other operations, I checked the known about Microsoft. DependencyInjection documentation, and also read some of the source code, but still could not find a way or method to achieve this requirement? Maybe my mind has been tied to understanding the right way to do it, so I'm here for help! I hope that the great gods, experts or doyens who know will give answers and guidance, thank you very much.


The purpose of this requirement is that throughout the project structure, some public interfaces will be defined, but no specific interface implementation will be done, but a specific implementation by a plugin, or multiple plugins, and then in the process of reflection, registration with the container service by calling InitializeAsync. And then, in the need to use this interface services in the plug-in, you can get through the service container and normal use.


Also, I found in Simple Injector's documentation about a similar method of satisfaction, and I wonder if DependencyInjection has the same support.



Translated with (free version)


Thanks a lot!

0 Replies