简体   繁体   中英

Can a IOC Container replace CreateInstance reflection code?

我在这个问题中显示了类似的设置,并想知道我是否可以替换所有使用反射的代码来查找某种类型的插件,然后使用IOC容器对其执行CreateInstance ,其中包含:

builder.RegisterAssemblyTypes(typeof(MyType).Assembly)

是的,你可以这样做:

builder.RegisterAssemblyTypes(typeof(MyType).Assembly).AsImplementedInterfaces();

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