Unity容器配置问题
我正在使用 Unity DI 容器。在配置文件中,我将以下类型指定为:
<type type="Interfaces.ILogger,Interfaces"
mapTo = "ConcreateClasses.ConsoleLogger,ConcreateClasses" />
我的理解是,应该在我的项目中引用 Interfaces dll 和 ConcreteClasses dll 才能使其正常工作。
但我想做的并不是在设计时引用具体的实现类。我希望通过指定 ConcreteClasses dll 的路径在运行时加载它们。
有办法做到这一点吗?
谢谢
I am using Unity DI container. In the config file I specify the following type as :
<type type="Interfaces.ILogger,Interfaces"
mapTo = "ConcreateClasses.ConsoleLogger,ConcreateClasses" />
My understanding is that both the Interfaces dll and ConcreteClasses dll should be referenced in my project in order for this to work.
But What I want to do is not to reference the concrete implementation Classes at design time. I would like them to be loaded at runtime by specifying the path of the ConcreteClasses dll.
Is there a way to do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要在项目中引用具体的实现程序集,只需将其放在与配置文件相同的文件夹中,或者从 GAC 中获取即可。
使用具体实现引用其他程序集是方便的,这样 Visual Studio 就会将 DLL 的副本放置在项目的生成的 BIN 文件夹中,从而使查找变得简单。
You don't need to reference the concrete implementation assembly in your project, you only need to have it in the same folder as your config file, or available from the GAC.
It's CONVENIENT to reference the other assembly with the concrete implementation, so that Visual Studio will place a copy of the DLL in the resultant BIN folder of your project, thus making the lookup trivial.
你可以通过反思来做到这一点:
You could do it through reflection: