Windows 服务 DbResource 提供者
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,
DbResourceProvider
基于接口IImplicitResourceProvider
和IResourceProvider
- 这两个接口都驻留在命名空间System.Web
中,用于原因:它们是特定于 ASP.NET 的。它们不适用于非 ASP.NET 场景(如 Windows Service、WinForms 等)!对于非 ASP.NET 场景执行类似操作的方法是实现您自己的
IResourceReader
并在从ResourceManager
派生的类中使用它 - 带有源代码的示例可以是找到此处。Basically
DbResourceProvider
is based on the interfacesIImplicitResourceProvider
andIResourceProvider
- both interfaces reside in the namespaceSystem.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 fromResourceManager
- an example with source code can be found here.