[英]How do I inject an instance of an objct into the “create” function of .NET Core DI Container
When instantiating a class from the IServiceProvider.GetService
I want to inject an instance that I created earlier in the request into the create function. 当从
IServiceProvider.GetService
实例化一个类时,我想将在请求中先前创建的实例注入到create函数中。
var transintObject = new SomeObjec();
var other = serviceProvider.GetService<RegisterdService>(transientObject)
I know RegisterdService
is dependent on SomeObject
but right now I'm not able to register the construction of the SomeObject
in the DIContainer. 我知道
RegisterdService
依赖于SomeObject
但是现在我无法在SomeObject
中注册SomeObject
的构造。
可以使用Activatorutilities.CreateInstance
修复此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.