Where to put a call to data initialization to initialize data required for a service

May 23, 2013 at 8:46 AM
Hi Guys,
          My services have initialisation functions that I need to call to retrieve the data required to setup the database with the current data. 
This is not data that would be populated when the database is created or when the model changes.
I have put calls to initialise these services when the objects that use these services are created.
I tried to find where else to put the calls but the repositories were not all initialized yet so they were injected as null values.
Where should I put these calls so that I know that all the services and repositories have been created and injected in their required locations.
e.g I have put a call to initialise one of my services when the object that uses it is created..
The service then does nothing if it has already been initialised.
public virtual void Created() 
        {
            PractitionerService.Initialise();
        }
   NO has the NakedObjectsStart class maybe I can put these calls there somewhere?
PS. Sorry about the formatting it looks like the formatting doesn't work
Regards,
         Alistair        
Editor
May 23, 2013 at 9:03 AM
In Apache Isis we had a similar requirement (to initialize services), so we added a couple of callback methods: @PostInit and @PreDestroy.

Sounds like a useful addition to NOF if there isn't something already.


Coordinator
May 23, 2013 at 10:08 AM
it looks like the formatting doesn't work
The CodePlex forum is used by many thousands of developers: I don't think the problem lies in the technology - I find that the formatting it offers works very well. Please spend some time to figure out what it is that you are doing wrong with your formatting. Bad formatting just imposes a burden on the reader. I suggest you always select Preview before saving any post.

You can do initialisation in the NakedObjectsStart PreStart and PostStart methods, or you could do it in the constructor for the services.

But bear in mind that in either case you are operating outside of Naked Objects. But that may not be an issue for you. You may have to do some experimentation.
May 23, 2013 at 11:31 AM
Thanks mate, I guess my solution will do for now. I will put a TODO on it.

Sorry about the formatting. I will try and find out what I am doing wrong.
Regards,
           Alistair