Windows 服务 DbResource 提供者

发布于 2025-01-02 20:48:10 字数 194 浏览 4 评论 0原文

我正在使用 c# 3.5 开发 Windows 服务,并希望在 SQL Server 中存储特定于语言的资源字符串并通过 DbResourceProvider 访问它们。然而,我见过的所有示例都没有显示如何在 Windows 服务中设置资源提供程序(它们都显示在 web.config 文件中指定提供程序)。

如何在 Windows 服务中设置资源提供程序?

I am developing a Windows Service with c# 3.5 and want to store language specific resource strings within SQL Server and access them via a DbResourceProvider. All the examples I have seen however do not show how to set the resource provider within a Windows service (they all show specifing the provider within a web.config file).

How can I set the resource provider within my Windows service ?

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

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

发布评论

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

评论(1

护你周全 2025-01-09 20:48:10

基本上,DbResourceProvider 基于接口 IImplicitResourceProviderIResourceProvider - 这两个接口都驻留在命名空间 System.Web 中,用于原因:它们是特定于 ASP.NET 的。它们不适用于非 ASP.NET 场景(如 Windows Service、WinForms 等)!

对于非 ASP.NET 场景执行类似操作的方法是实现您自己的 IResourceReader 并在从 ResourceManager 派生的类中使用它 - 带有源代码的示例可以是找到此处

Basically DbResourceProvider is based on the interfaces IImplicitResourceProvider and IResourceProvider - both interfaces reside in the namespace System.Web for a reason: they are specific for ASP.NET. They are NOT intended for use in non-ASP.NET scenarios (like Windows Service, WinForms etc.) !

The way to do something similar for non-ASP.NET scenarios is to implement your own IResourceReader and use it in a class derived from ResourceManager - an example with source code can be found here.

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