有没有办法在 .NET 中添加引用而无需重新编译?

发布于 2024-08-17 22:01:11 字数 178 浏览 5 评论 0原文

我正在使用 IoC 容器(温莎城堡)根据配置文件实例化类。如果我想从编译项目时不存在的新 dll 中添加类,有什么方法可以在不重新编译的情况下做到这一点?

编辑:由于该项目是 WCF 服务的服务主机,并且我想要在编译后包含的类是 WCF 服务,所以我还想知道是否可以包含有关新服务的端点信息而无需重新编译。

I am using a IoC Container (Castle Windsor) to instantiate classes accordingly to the configuration file. If I want to add classes from a new dll that didn't exist when I compiled the project, there is any way to do that without recompiling?

Edit: As this project is a Service Host for WCF service, and the classes that I want to include after compilation are WCF Services I would like also to know if I can include endpoint information about new services without recompiling.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路弥 2024-08-24 22:01:11

我不太了解 Windsor,但我希望它是可能的 - 只需指定完整的类型名称,包括程序集名称:

<component id="foo"
           service="Namespace.IInterfaceName, InterfaceAssembly"
           type="Namespace.ImplementationName, ImplementationAssembly" />

I don't know about Windsor in particular, but I'd expect it to be possible - just specify the full type name including the assembly name:

<component id="foo"
           service="Namespace.IInterfaceName, InterfaceAssembly"
           type="Namespace.ImplementationName, ImplementationAssembly" />
岁月静好 2024-08-24 22:01:11

是的 - 这正是温莎城堡的用途。我在家里的一个项目中使用 Castle,并使用它从程序集中动态加载类,而这些程序集在我创建类时可能不存在。

诀窍在于您加载的类必须实现应用程序已知的接口。

这样做的目的是为了让您可以根据需要切换不同的功能。您的项目使用 ISaveMyData 来保存内容,并使用 Castle Windsor 来使用 Oracle 或 MySql,具体取决于客户端站点上安装的内容。

对于 WCF,WCF 组件已经必须指定它们正在使用的接口(它们的契约)。在 WCF 组件的正常配置中,您可以随时更改端点地址和其他信息以指向不同的组件,只要它们使用相同的协定即可。不需要温莎城堡。也不需要重新编译——只需更改配置即可。

Yes - that's exactly what Castle Windsor is for. I'm using Castle in a project at home and I use it to dynamically load classes from assemblies that probably didn't exist when I created the class.

The trick is that the classes you load have to implement an interface known to your application.

The point of doing this is so that you can switch in and out different functionality as needed. Your project uses ISaveMyData to save stuff and uses Castle Windsor to use either Oracle or MySql depending on maybe what's installed at the client site.

As for WCF, WCF components already must specify an interface they're using (their contract). In the normal configuration for WCF components you can change the endpoint address and other information to point to different components whenever you need to as long as they use the same contract. No Castle Windsor is needed for that. No recompiling is needed either - just make the configuration change and go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文