开发者

Creating repositories with spring.net

I'm creating my repositories with spring.net. However, I'm wondering what the lifetime is of these objects. In my repositories, objects that are retrieved from the database are cached in a registry. But this should only happen for a single server call. Can you specify in spring.net configuration that the objects should be created for each call to the serv开发者_如何学JAVAer.

I guess singleton=false doesn't do it for me, as this will create a new Repository everytime, even in the same thread.


From your previous posts I see you put all your repositories in a registry class to retrieve them.

I'd step away from that approach and inject the repositories directly into the classes that need them. Then it becomes a lot clearer what the lifetime of your objects is.

You should look at the other scopes Spring.NET has to offer as well.


This is a complicated question, because the design of the cache and registry comes into play. It sounds like the lifetime of the persistent objects will be controlled by the registry, since it will be maintaining references.

So there are a few things to ask:

  1. Which object owns the cache? The repository, the service, or something else?
  2. How are you invalidating the cache? Is it keeping track when persistent objects are updated?
  3. What's the timeout value for the session in which the objects are created? How would an invalidated session be communicated to the cache?
  4. When you say "registry", do you mean "Windows registry"? (god forbid, please so "no".)

In Spring for Java EE, one usually gets configurable caching with Hibernate and EhCache. If you use the Spring JDBC template you have to write it yourself. What implementation are you using for your repositories?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜