tags:

views:

356

answers:

2

Hi, I have a WCF service and use Spring.ServiceModel.Activation.ServiceHostFactory as a factory in my *.svc. What I need is to load some data into cache when service is called first time or restarted. Could you please suggest a best way to do so? Right now I inherited from the Spring.ServiceModel.Activation.ServiceHostFactory and put my code there but probably should be a better way? Tnx in advance.

A: 

You can use AOP to intercept the call (since you're using Spring already) to get the 'first call' but the most straightforward thing to do would be to call your cache provider in the constructor of your service or some initialization method.

BennyM
I've tried to use constructor but I get exception saying that I should not invoke container in the constructor of the singleton object (caching class is also a Spring object). It would be nice if an event existed like aftercontextloaded. Regarding interceptors - how to track 1st call?
Alex
Could you show me the code you're using in the constructor, most of the time you can get around calling the Spring API directly by injection the stuff you're trying to retrieve from your context.
BennyM
A: 

We currently have this kind of startup code in the static constructor of our custom ServiceHostFactory. Depending on your settings with regards to the IIS' Application Pool of your service(s) this should be fine.

You need to have a look at the recycling settings of the Application Pool. Once it gets recycled, the static constructor will be called again.

flq
This is similar to what I did - anyway have to use custom ServiceHostFactory but tnx anyway I will take a look.
Alex