Inject into a static factory class?
Just wondering if it is possible to inject into a factory class for use in a static method. Tonight I had a case where I wanted to use a function in my model in a factory but it was only needed in one place at one time so it didn't seem like it warranted pulling it out into a static function itself or redefining it as a static function in the model. So I was hoping I could inject into the factory class. The result was a null reference error so if it is possible I am just probably missing something very simple. The factory extended Actor (using mvcs) in hopes of being able to do that. I'll look into it again later though I was able to work around it. I'm sure I'm just missing something so any pointers would be most welcome.
And wow this framework rocks.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Jonny Reeves on 23 Mar, 2010 11:06 AM
Hi Michael,
Could you possible paste the Static Factory class in question so we can have a look at it? My initial guess would be "no", however it does beg the question as to why the Factory needs to be static in the first place?
Jonny.
3 Posted by Michael Wills on 23 Mar, 2010 06:53 PM
Ah the class itself isn't static, just the method being called. Unfortunately I can't post the code but it's pretty straightforward similar to this
There is a function in the model which can set the color which would require injecting a model instance accessible from that static method.
Thinking about it now though, that factory class was never instantiated and as such there was never a chance to inject the variable. So if it weren't a static method and the factory was injected as a singleton instead, that would solve the problem. I was just used to thinking of Factory classes exposing static methods which is where the hangup was.
4 Posted by Jonny Reeves on 24 Mar, 2010 10:25 AM
Yep; I used to be the same and make all my Factories static; it's quite liberating to change this point of view ;)
Stray closed this discussion on 11 Feb, 2011 11:36 PM.