Autofac - 注册插件
我有一个定义了一些方法的接口,并且有 N 个实现它的类。如何使用 autofac 注册所有加载的程序集中找到的所有类?
i have an interface that defines some methods and i have N classes that implement it. How can i register all the classes found in all the loaded assemblies with autofac?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须“了解”包含类的程序集,您也许可以使用
Assembly.Load(..)
自己加载它们。从那里,很容易注册类:
更新:要获取注册的实例,您可以使用 Autofac 对集合的内置支持:
You will have to "know about" the assemblies containing the classes, you could perhaps load them yourself with
Assembly.Load(..)
.From there, it is easy to register the classes:
Update: to get to the registered instances, you can use Autofac builtin support for collections: