开发者

how to have windsor container disposing instance w/ Lifestyle=Thread

I'm using windsor container into a win service. I'm using Linq2sql for persistence purpose. An instance of Linq2Sql DC has been injected into 2 component UnitOfWork and Repository I might set Lifestyle to Singleton for DC+UoW+Repository, but I'm concern in a long-term my Dc will hold to many enitites affecting memory without any reason for my app: after I'm done with an entity I won't use it anymore, but there's no public method on DC to clear cache.

Due my DC will injected into 2 components, I cannot use Lifestyle.Transient othe开发者_Python百科rwise 2 instances will be created(one per each injection)

So I decided to set Lifestyle to Thread: my app has timer to execute a job every n minutes, on each ticking I kick a new thread. In that case a new DC will be create on each thread and that injected into 2 cmps as above. Since disposing policy for Lifestyle=Thread are same as singleton(on container disposing/end of my app/on stop), I'm concern about amount of object hold into container until winservice will be stopped.

Since I call Join() on my thread, I exaclty now when it will be over. I was thinking to extract from the container my 3 objs and call dispose, but I don't like this approach: I prefer have the container dealing with his own objects...

Any comments/suggestion?

I was also thinking to create my own Lifestyle to accomplish my disposing at the end of the thread, basically simulating what happend into a web scenario with PerWebRequest(at the end of the request all cmps will be disposed). Is there any sample how to create custom Lifestyle?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜