简体   繁体   中英

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.

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.

可以使用Activatorutilities.CreateInstance修复此问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM