设置类架构

发布于 2024-07-25 22:09:28 字数 293 浏览 5 评论 0原文

只是想知道关于设置类的架构的最佳实践建议是什么。 我们有许多表将用于填充类,我猜哈希表是最好的方法? 如果能在 Intellisense 中的应用程序范围内提供强类型集合,那就太好了。

例如

Settings.Car.Colour

我也想知道.NET 中的SQL 依赖类 - 我想实现这个观察者模式 - 只是想知道是否有人对它是否是最佳选择有任何想法 - 或者我应该自己推出解决方案。 SQL Server 中为此功能添加的表和设置似乎将其限制为托管服务器。

我应该查看框架内的其他类吗?

Just wondering what the best practise advice would be on the architecture for a settings class. We've a number of tables which will be used to populate the class, I'm guessing a Hashtable is the best way to go? It also would be nice to have a strongly typed collection available through the scope of the app in Intellisense.

e.g.

Settings.Car.Colour

I'm also wondering about the SQL dependancy classes in .NET - I'd like to implement this observer pattern- just wondering if anyone has any thoughts on whether its the best option - or should I roll my own solution. The added tables and settings within SQL server for this to work seem to limit this to a managed server.

Any other classes within the framework that I should look at?

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

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

发布评论

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

评论(1

皇甫轩 2024-08-01 22:09:28

我不会使用 SQL 依赖项类来确定数据库中的设置何时发生更改。 它将您与特定数据库联系得太紧密(尽管如果您愿意,您可以将其抽象出来)。

相反,我会在数据库发生更改时向感兴趣的侦听器发送某种消息通知,然后让侦听器使其缓存失效。

此外,始终建议添加强类型集合。 它可以仅将调用转发到哈希表/字典,但您需要可以在编译时(而不是运行时)绑定到的东西。

I wouldn't use the SQL Dependency classes to determine when something changes in the settings in your database. It ties you too much to the specific database (although you could abstract it out, if you wanted).

Rather, I would have some sort of message notification sent to listeners that are interested when the changes to the database occur, and then have the listeners invalidate their cache.

Also, adding a strongly-typed collection is always advised. It could just forward calls to the hashtable/dictionary, but you want something you can bind to at compile time, as opposed to run time.

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