ASP.NET 资源:检测何时在编译时与运行时调用 ResourceProvider
我的 ASP.NET Web 应用程序利用由 SQL Server 数据存储支持的自定义资源提供程序。据我了解,隐式资源在编译时调用资源提供程序来确定是否需要为给定的资源键生成资源表达式。因此,我的构建过程现在依赖于拥有一个包含必要资源密钥的实时、最新的数据库。
这本身不一定是问题。问题是该应用程序连接到由查询字符串参数确定的许多数据库之一(糟糕的设计,但不幸的是我现在坚持使用它)。显然,编译时没有查询字符串,因此资源提供者无法访问数据库。是否可以确定在编译期间已调用资源提供程序(或更具体地说是资源提供程序下游的代码),以便我可以指向预定的数据库?
现在,如果 HttpContext.Current == null,我只是默认使用特定数据库。这工作得很好,但是这个逻辑必须存在于数据访问层中,而且我绝对讨厌数据访问层引用 System.Web 的想法。有更好的解决方案吗?
My ASP.NET web app utilizes a custom resource provider backed by a SQL Server data store. As I understand it, implicit resourcing invokes the resource provider at compile-time to determine whether or not resource expressions need to be generated for the given resourcekey. Consequently, my build process is now dependent upon having a live, up-to-date database containing the necessary resource keys.
That in and of itself is not necessarily a problem. The issue is that the app connects to one of many databases as determined by a querystring parameter (terrible design, but unfortunately I am stuck with it for now). Obviously there is no querystring at compile-time, so the resource provider is unable to reach the database. Is it possible to determine that the resource provider (or more specifically code downstream of the resource provider) has been invoked during compilation so I can point to a predetermined database?
For now I am just defaulting to specific database if HttpContext.Current == null. This works fine, but this logic has to exist in the Data Access layer and I absolutely hate the idea of the Data Access tier referencing System.Web. Is there a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在哪里
where