Windsor w/ BackgroundFactoryMethod

38 views
Skip to first unread message

Henrik

unread,
May 8, 2012, 6:47:24 PM5/8/12
to castle-pro...@googlegroups.com
I'm looking to initialize a component on a background thread, so I hacked something together. It looks like this:

https://gist.github.com/2640092

It works really nice, except that of course the component isn't being disposed unless something else that depends on it is resolved, meaning there's a live component needing disposing which isn't being disposed.

Where would I jack into Windsor 3 to provide a piece of logic stating, that for this type of handler/component/burden (?) when the container/kernel is being disposed, also perform a resolve and then release call, for this component?

Henrik Feldt

unread,
May 12, 2012, 8:24:18 PM5/12/12
to castle-pro...@googlegroups.com

bump

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/GZa5mIdsbKgJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Krzysztof Koźmic

unread,
May 15, 2012, 6:02:09 AM5/15/12
to castle-pro...@googlegroups.com
if it's IDisposable it will get disposed

Henrik Feldt

unread,
May 15, 2012, 4:06:03 PM5/15/12
to castle-pro...@googlegroups.com

If it is resolved once, yes, but not otherwise.

 

The problem is the otherwise. How do I do then?

Krzysztof Koźmic

unread,
May 15, 2012, 4:27:42 PM5/15/12
to castle-pro...@googlegroups.com
I'm not sure I understand.

Do you have a failing test to demonstrate it?

Henrik

unread,
May 16, 2012, 8:34:49 AM5/16/12
to castle-pro...@googlegroups.com
Here: https://gist.github.com/2710007


On Tuesday, 15 May 2012 22:27:42 UTC+2, Krzysztof Koźmic wrote:
I'm not sure I understand.

Do you have a failing test to demonstrate it?

On 16/05/2012 6:06 AM, Henrik Feldt wrote:

If it is resolved once, yes, but not otherwise.

 

The problem is the otherwise. How do I do then?

 

From: castle-project-users@googlegroups.com [mailto:castle-project-users@googlegroups.com] On Behalf Of Krzysztof Kozmic
Sent: den 15 maj 2012 12:02
To: castle-project-users@googlegroups.com
Subject: Re: Windsor w/ BackgroundFactoryMethod

 

if it's IDisposable it will get disposed

On 13/05/2012 10:24 AM, Henrik Feldt wrote:

bump

 

From: castle-project-users@googlegroups.com [mailto:castle-project-users@googlegroups.com] On Behalf Of Henrik
Sent: den 9 maj 2012 00:47
To: castle-project-users@googlegroups.com
Subject: Windsor w/ BackgroundFactoryMethod

 

I'm looking to initialize a component on a background thread, so I hacked something together. It looks like this:

https://gist.github.com/2640092

It works really nice, except that of course the component isn't being disposed unless something else that depends on it is resolved, meaning there's a live component needing disposing which isn't being disposed.

Where would I jack into Windsor 3 to provide a piece of logic stating, that for this type of handler/component/burden (?) when the container/kernel is being disposed, also perform a resolve and then release call, for this component?

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/GZa5mIdsbKgJ.

To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.

To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.

To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.

Patrick Steele

unread,
May 16, 2012, 8:55:54 AM5/16/12
to castle-pro...@googlegroups.com
I'm not sure that's an accurate test. I'm not saying the issue you're
seeing isn't real, but your test directly references an idisposable
object in the Assert. That alone will probably keep it from being
garbage collected. Or even if it has been marked for collection, it
may be resurrected due to your Assert.

I think a better test would be to use a WeakReference to your instance.

---
Patrick Steele
http://weblogs.asp.net/psteele
>> castle-pro...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-u...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-pro...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-u...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-pro...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-u...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-pro...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-u...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/castle-project-users/-/cjyCuX8UGfgJ.
> To post to this group, send email to castle-pro...@googlegroups.com.
> To unsubscribe from this group, send email to
> castle-project-u...@googlegroups.com.

Henrik

unread,
May 17, 2012, 4:56:37 AM5/17/12
to castle-pro...@googlegroups.com
But that it's IDisposable has no bearing on the GC algorithm - it will be called through the finalizer in GC if it's not deterministically disposed through the interface before the GC run.

I updated the test to reflect this. https://gist.github.com/2710007
>> castle-project-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-users+unsub...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-project-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-users+unsub...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-project-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-users+unsub...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Castle Project Users" group.
>> To post to this group, send email to
>> castle-project-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> castle-project-users+unsub...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/castle-project-users?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/castle-project-users/-/cjyCuX8UGfgJ.
> To post to this group, send email to castle-project-users@googlegroups.com.
> To unsubscribe from this group, send email to
> castle-project-users+unsub...@googlegroups.com.

Krzysztof Koźmic

unread,
May 17, 2012, 4:56:40 AM5/17/12
to castle-pro...@googlegroups.com
It works as expected.

Windsor never touches your object.

@K
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/cjyCuX8UGfgJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Henrik

unread,
May 17, 2012, 5:00:05 AM5/17/12
to castle-pro...@googlegroups.com
Yeah, I know, it's grand that it doesn't if you don't initialize them like I do.

But how do I make it touch my object, is the question? :)

Henrik

unread,
May 17, 2012, 5:36:16 AM5/17/12
to castle-pro...@googlegroups.com
I hacked one idea together, but it's failing; probably because the kernel is already on its way out the window.

Updated gist: https://gist.github.com/2710007

Krzysztof Koźmic

unread,
May 17, 2012, 5:43:28 AM5/17/12
to castle-pro...@googlegroups.com
You're still not resolving it.

@K
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/OWZzvQz4ulcJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Henrik

unread,
May 17, 2012, 6:21:59 AM5/17/12
to castle-pro...@googlegroups.com
I know, and I might be barking up the wrong tree, but here's what I want:
I want to have the instance initialized by the time that I resolve it. If I never resolve it, it needs to be disposed somehow, when the container is disposed. How do I go about coding that? The initialization must happen on a different thread from where the container is initialized, because the initialization takes too long to wait for, but by the time I need the component there would have passed time and it would have had time to initialize completely.

Krzysztof Koźmic

unread,
May 17, 2012, 6:31:50 AM5/17/12
to castle-pro...@googlegroups.com
If you resolve it, Windsor will release it as normal.

If you don't resolve it, you'll have to take care of disposing the object yourself. For that I think you'll need some custom infrastructure outside of the container.

@K
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/1cGxiGW_4GEJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Henrik

unread,
May 17, 2012, 6:38:06 AM5/17/12
to castle-pro...@googlegroups.com
How would I know if it was resolved or not?

Krzysztof Koźmic

unread,
May 17, 2012, 4:44:26 PM5/17/12
to castle-pro...@googlegroups.com
set a flag in your lazy? I don't know. There's plenty of ways
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/UHZtRHTWnBwJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Krzysztof Koźmic

unread,
May 17, 2012, 5:00:42 AM5/17/12
to castle-pro...@googlegroups.com
Resolve it
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/FFDorfSwwI8J.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Mariusz Izydorek

unread,
May 18, 2012, 2:57:53 AM5/18/12
to castle-pro...@googlegroups.com

Hi guys,

I am using windsor to resolve object in differen thread all the time and as lond as it is not UI component it works fine. I do not have a problem with that.

Now disposing it is a different story as from my experience it very much depends on configuration and your solution.

Krzysztof please correct me if i am wrong but if your container track references than if you want to dispose your object you should use relese method in container. Than container will have a chance to dispose your object and all dependencies with in a scope of your object. If you do not release it will keep reference to your object and gc will not be able to collect it.

Mariusz

Henrik

unread,
May 21, 2012, 8:22:31 AM5/21/12
to castle-pro...@googlegroups.com
Couldn't that flag be coded into a kernel subsystem or something? How would you do it?

Krzysztof Koźmic

unread,
May 21, 2012, 4:49:37 PM5/21/12
to castle-pro...@googlegroups.com
I'd probably inherit from DefaultKernel, raise an even on Dispose and keep all the rest in your registration nested delegate.

@K
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/THyMuObKtuwJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages