开发者

Windsor: How do you scope your services pr usercontrol?

开发者 https://www.devze.com 2023-02-02 09:47 出处:网络
I am developing a winforms application and I have a scenario where I want to scope the lifetime of some services to the lifetime of a usercontrol (which there can be many of in the application). What

I am developing a winforms application and I have a scenario where I want to scope the lifetime of some services to the lifetime of a usercontrol (which there can be many of in the application). What is the best way of doing this in Castle Windsor?

One approach I was thinking of was to create a child container in the usercontrol, register all the services which i want to scope, as singletons into the child container and then use the child container to resolve the object graph which will be used internally in the usercontrol. I would really like to keep my ioc configuration in my pris开发者_高级运维m modules instead of having them "scattered" (well not very scattered but you get the point) over the code-base.

Are there any other ways of achieving this? I've read that you can use Handle-selectors and SubResolvers to accomplish context scoping of services, but I haven't found a blog describing how.

Edit:

When I say "usercontrol" I mean pr root usercontrol, child controls of the usercontrol should be scoped by their parent. I've solved it by creating a child container pr root usercontrol and register the scoped services into the child container.


Your question is imprecise. What does that mean per-control? What if control has sub-controls? How would you detect the scope you're in?

Implementation-wise you need to implement a custom lifestyle.

0

精彩评论

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

关注公众号