程序集替换和类继承

发布于 2024-10-31 15:40:17 字数 962 浏览 0 评论 0原文

名为 Portal.WebServices.TaskListService 的 WCF 服务使用代码隐藏文件 TaskListService.svc.cs。在此文件中声明一个名为 TaskListService 的类型,该类型继承自 TaskListServiceBase 类型。并实现一个名为ITaskListService的接口。所以:

TaskListService: TaskListServiceBase, ITaskListService

   ^                     ^                  ^   
   |                     |                  |
 application               separate assembly 

我想在网络服务器上部署 TaskListService once 并将 TaskListServiceBase 和接口放入单独的程序集由托管 TaskListService 的应用程序引用。因此,当我想要添加、删除或更新 Web 服务中的功能时,我只需将新程序集复制到应用程序的 bin 文件夹中。

由于这种情况发生在运行时,我想知道这种做法是否有任何惩罚或警告(除了使用编译时常量等),或者这种情况是否可能< /strong>,或者是否有更好的做法。

所以基本上,我的问题是:我想更新 WCF 服务的功能,而无需重新部署整个应用程序,而只需重新部署更新的程序集< /strong>

(是的,我觉得这里有点愚蠢)

A WCF service named Portal.WebServices.TaskListService uses a codebehind file TaskListService.svc.cs. In this file declare a type named TaskListService that inherits from the type TaskListServiceBase. and implements an interface named ITaskListService. So:

TaskListService: TaskListServiceBase, ITaskListService

   ^                     ^                  ^   
   |                     |                  |
 application               separate assembly 

I want to deploy the TaskListService once on the webserver and put TaskListServiceBase and the interface into a separate assembly that is referenced by the application that hosts TaskListService. So when I want to add, remove or update functionality in the web service I only have to copy the new assembly into the application's bin folder.

Since this happens during runtime I wonder if there are any penalties or caveats for this practice (besides of the use of compile time constants etc), or if this scenario is even possible, or if there are better practices for doing this.

So basically, my question is: I want to update functionality to a WCF service without redeploying the whole application, only the assembly that is updated

(yes I feel a bit stupid here)

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

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

发布评论

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

评论(2

凉风有信 2024-11-07 15:40:17

在另一个程序集中分离接口和基类是可能的并且是正确的(分离接口是一种仅针对接口描述这种情况的模式,并且相同的模式适用于基类)。

关于部署,您可以这样做,因为程序集是由 IIS 进行卷影复制的。但是,一旦复制了新程序集,我假设您必须回收应用程序才能加载新程序集。

我为 Windows 服务手动执行此操作,该服务启动了启用卷影复制的独立 AppDomain,因此我可以远程更新程序集并强制重新启动服务。

The separation of interface and base class in another assembly is possible and correct (Separated Interface is a pattern describing this for just interfaces, and the same pattern applies for base classes).

Regarding the deployment, you can do that as the assemblies are shadow-copied by IIS. However, once the new assembly is copied, I assume you have to recycle the application so the new assembly is loaded.

I did this manually for a Windows Service, that launched a separated AppDomain with shadow copy enabled, so I could remotely update an assembly and force a restart of the service.

笨死的猪 2024-11-07 15:40:17

这是我遵循的做法,据我所知没有任何缺点,只有好处。我更进一步,因为我不使用后面的代码。因此,在上面的示例中,TaskListService.cs 将位于 ServiceImplementations 程序集中,与 ServiceContracts 程序集分开。

这允许您根据需要将合同/实现分解为多个程序集(可能按域分隔)并独立更新它们。

This is a practice I follow, there are no downsides that I know of, only benefits. I take it one step further, in that I do not use the code behind. So in your example above, TaskListService.cs would live in a ServiceImplementations assembly, separate from the ServiceContracts assembly.

This allows you to break down your contracts/implementations into multiple assemblies if needed (perhaps separated by domain) and update them independently.

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