DI and Static Methods

Topics: Web Client Software Factory, UIP Application Block discussion, User Forum
Nov 7, 2007 at 6:42 PM
I'm using an AutoCompleteExtender on a page. The extender is setup to call a page method. It appears that the page method must be static. So what I've done is create a static method on my presenter that is called from my view. So my question is how do I get to services I've registered in my initializer classes inside of my static methods or possibly how do I have ObjectBuilder buildup an instance of the presenter in the static method on my view so that I can then call an instance method on my presenter?
Nov 12, 2007 at 7:44 AM

Hi
Have you found any solution to this? I have just the same problem. I want to use AutoCompleteExtender but how do I get an instance of my service to call? The service is, by the way, an WCF service. I also have the AutoCompleteExtender in a User Control so it can be re-used in multiple pages.

I guess this is a problem that will be more and more common as people make use of WCSF, WSSF and AJAX......
Nov 12, 2007 at 4:38 PM
Hi.

Dependency injection works only on instances (objects), so you can’t access injected dependencies from a static method.
A possible solution consists of creating a Web service and having the AutoCompleteExtender invoke it to retrieve the list of suggested words.

You can see the WCSF 2.0 Reference Implementation to get a sample of this.

Thanks.

Sebastian Iacomuzzi
http://staff.southworks.net/blogs/siacomuzzi