Coldspring usage question, please help?


Coldspring usage question, please help?

Posted by Luis Majano
Mar 15, 2007 00:00:00 UTC
I have a question concerning setting up a service via coldspring. Let's say I have object A already instantiated in the application scope and I want it to be injected into every service ColdSpring creates for me. However, I don't want object A to be created by ColdSpring.

I want to be able to define in my service definition that for example my UserService will receive this instantiated object as a dependency. How do I define this? Is this possible? Am I totally deranged for trying to do this? Any thoughts? Do you understand my dilema?

I know I can inject it later by hand coding it, but I don't want to do that, I want Coldspring to do this for me. Is this possible?

 


Jaime Metcher

If you're happy to instantiate the object during ColdSpring initialization, you can use the bean-factory attribute:

<bean id="transfer" factory-bean="transferFactory" factory-method="getTransfer" singleton="true" />

In this example the transferFactory bean instantiates the transfer bean. Of course you have to give CS the factory bean first.

Jaime

Rob Gonda

You have two options: either you pass the initialized instance of the component to ColdSpring as a property when you initialize it, or you create a factoryBean that returns the application instance of your object. So you need to create a factoryBean with a getBean method what returns application.bean. Then you create another bean that depends on the factory. From that point on, ColdSpring wont know the difference. Let me know if you need examples or code.

Cheers.

Luis Majano

Thanks!! I kind of like the solutions of passing the instantiated object as a property when initialized.

Then I can just reference it as ${coldbox.controller}

Thanks, much appreciative!!

Rob Gonda

True, the only problem is that you won't be able to use auto-wiring.

Luis Majano

Hmm, Can you expand on that, Rob?

Rob Gonda

For autowiring ColdSpring will need your coldbox.controller to be Bean with a valid Bean ID. Once you have that bean, call it coldboxController, you can define arguments in your init functions or setColdboxController functions in your beans and let ColdSpring figure out the auto-wiring. If you manually wire your components -- which in fact is better for documentation purposes -- then you don't need to care about that.

Luis Majano

Ok, got you. Yea, I think for the purposes I am looking is to joing the model to the framework via the coldboxController. That way I can bridge the framework gap into the model and actually expose the model to the plugin architecture.

I just tried using via the properties reference and it works great. Ohh by the way, you are going to be able to configure the ColdBox cache for your services. That way they can be dynamic. Pretty cool

Site Updates

Entry Comments

Archives

Entries Search