views:

338

answers:

2

I would like to create a window with a progressbar which shows the current status of Spring's object instantiation. From Spring.Net's documentation it seems that IObjectPostProcessors is the right point to start and track whenever an Object has been instanciated. However in order to get "Percentage of instantiated classes" I need to ask ObjectDefinitionCount of spring's factory to get the number of configured object. However this does not work until the contextcreation has been finished (also this problem problem seems to be related).

If it's not possible to use Spring to get the start-up status, how do you display information during application start up to the user?

+1  A: 

I can provide you with a workaround, although it's not perfect it should probably be a good estimate.

  • You use a persistent storage mechanism (properties files, db, whatever) to keep track of the number of created beans.
  • You use IObjectPostProcessors to update the count of initializations
  • On the first run, obviously the value will be 0
  • On the subsequent runs, you use the last count to estimate the number of initializations that are to be done.

Of course, this is not accurate, but it should provide a good estimate most of the times.

Miguel Ping
I am currently using your apporach but will have a look at what Erich Eichinger suggested. Thanks!
tobsen
+1  A: 

Hi,

Spring reads in the configuration in 2 steps - first all object definitions are read from the config and second those definitions are processed, instantiating singletons if necessary.

You should get what you want by implementing an IObjectFactoryPostProcessor. ObjectFactoryPostProcessors are the first objects that get instantiated before anything else. At this time the number of object definitions is already available. Using an IObjectPostProcessor gives you the information about each object being instantiated.

If you are after getting the number of object definitions already at the time the configuration is loaded, I guess it is possible, but Spring reads the configuration in a single pass. You'd need to obtain the total number of objects using a different technique.

hth, Erich

Erich Eichinger
Thanks for pointing out the IObjectFactoryPostProcessor!
tobsen