使用 Spring.Net 进行动态属性更新
我有一个 work-space 对象,其中包含 target 对象及其属性的列表。
使用 Spring.Net 进行配置非常简单。但问题是,目标对象可能会被用户更改(在 GUI 上):可以添加、删除某些对象,并且它们的属性可能会更改。
我需要即时序列化新的工作空间配置,以便在我的应用程序出现故障时使其保持不变。
是否有任何自动方法可以使用 Spring.Net 来执行此操作,而无需处理 XML 序列化?或者,在这种情况下有没有办法简化 XML 序列化? 在这种情况下使用 Spring.Net 是否符合逻辑?
谢谢!
I have a work-space object containing a list of target objects with their properties.
This is very simple to configure using Spring.Net. But the thing is that the target objects may be changed by the user (on the GUI): some can be added, removed and their properties may change.
I need to serialize the new work-space configuration on the fly to have it persistent when my app goes down.
Is there's any automatic way to do that using Spring.Net, without having to deal with XML serialization? Or, is there's a way to simplify the XML serialization in this case?
Is it logical to use Spring.Net in this case at all?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用依赖配置作为持久存储的手段;它不是为此目的而建造的。将依赖项配置视为随应用程序附带的静态配置。
如果应用程序的用户可以更改对象,那么这通常不是您应该使用依赖项注入框架配置的对象。您应该考虑使用数据库、文件(xml、纯文本)或其他持久存储来保存和检索这些对象。
考虑在管理
Target
对象的WorkSpace
上注入一个对象(我们称之为TargetManager
)。TargetManager
可以访问持久存储,而WorkSpace
不知道TargetManager
是如何工作的;只是它会给他目标
。因此,对于应用程序的静态配置部分,您绝对可以使用 Spring.NET,但对于目标的保存和检索,您不应该使用 Spring.NET 依赖注入功能。
在 .net 中,Xml 序列化可能非常简单,但这实际上取决于您要序列化的对象的类型。我们需要有关您想要保留的对象的更多详细信息以提供帮助。
You should not use your dependency configuration as a means of persistent storage; it wasn't built for that purpose. Think of the dependency configuration as a static configuration that you ship with your application.
If users of your application can change an object, then this generally isn't an object you should configure using a dependency injection framework. You should consider saving and retrieving those objects using a database, a file (xml, plain text) or some other persistent store.
Consider injecting an object (let's call it
TargetManager
) on yourWorkSpace
that manages theTarget
objects. TheTargetManager
can access the persistent store and theWorkSpace
wouldn't know how theTargetManager
works; only that it'll give himTarget
s.So for the static configuration part of your application you can definitely use Spring.NET, but for the saving and retrieving of targets you shouldn't use Spring.NET dependency injection features.
Xml serialization can be very simple in .net, but that really depends on the type of object you want to serialize. We'd need some more details on the objects you want to persist to help out there.