locked
Services not available during OnInitialized RRS feed

  • Question

  • Hi,

     

    I have some code in the OnInitialized method of a part where I populate the part's initial data, so it's available when the part first gets displayed. Initially I faked the data directly within the method, and it worked fine. But now I want to use method within an Acropolis service to get the work done. The simple problem seems to be that during the OnInitialized method, the actual service hasn't been created yet, so when I use the service dependency within the part, it fails ("the requested service could not be found").

     

    If I make use of the service but only from say a command on the part (which executes via the part chrome when the user selects it), all works fine - the service has been created and the service dependency gets resolved OK.

     

    So I guess it just comes down to timing - I'm trying to use the service too soon in the lifetime of the part. Therefore my question is: should this in fact work, or should I be using some other mechanism to trigger the code at the start of the part's lifetime?

     

    [The only other solution I've been able to think of and which kind of works is to wire my data loading code (that calls the service method) in a command handler, then use BeginExecute on the command from within OnInitialized to get the command code to run asynchronously, but then I also have to add in a one second sleep into the command handler code before calling the service to give time for it to have been added to the available services. It works, but it doesn't feel right! Any other suggestions for better approaches would be appreciated!]

     

    Regards,

     

    Andy Burgess. 

    Tuesday, October 2, 2007 10:20 PM

Answers

  • I use OnFactoryCreationComplete, you should have access to all of your Services at that point.

     

    Monday, October 15, 2007 11:18 PM

All replies

  • Hi Andrew,

     

    I ran into the same problem. I just hope the final version of Acropolis will have a solution that makes sense.

     

    Many times a part or an application has to call a service during its initialization and having to use hack to accomplish that is not in the spirit of Acroplis.

     

     

     

     

     

    Saturday, October 6, 2007 2:01 PM
  • Andrew,

     

    Have you tried to use the OnPartAttached() method to do this work?  You should have services available when its called.

     

    Mike

    Tuesday, October 9, 2007 8:25 PM
  •  

    OnPartAttached is a method of the PartView class.

    I need to call the service from the Part and and not from the View.

     

    Tuesday, October 9, 2007 11:14 PM
  • I use OnFactoryCreationComplete, you should have access to all of your Services at that point.

     

    Monday, October 15, 2007 11:18 PM