Autocomplete And Injection

Topics: Web Client Software Factory
Mar 11, 2008 at 9:32 PM
Edited Mar 11, 2008 at 9:35 PM
Is there anyway to use dependency injection in the webservice used by the ContextSensitiveAutoCompleteExtender? Or maybe get a reference to the CompositionContainer?
Coordinator
Mar 13, 2008 at 12:33 AM
Edited Mar 13, 2008 at 12:35 AM
Yes. Look at PostalCodeAutoCompleteService.asmx.cs in the Order Management Reference Implementation.
In this case, the trick is in the Constructor, call WebClientApplication.BuildItemWithCurrentContext(this); before you do anythign else.
This will do DI over the web service instance, inject dependecies, services, whatever.

If you have not installed the source code, go to Start -> Program Files -> Microsoft patterns & practices -> Web Client Software Factory -> Web Client Software Factory Source Code Install
That MSI will install all the quickstarts and reference implementations, which are a great resource for how things work.

Enjoy,
Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/
Mar 13, 2008 at 1:48 PM
Nice. Thanks for that. I should have known it would be something so simple.
Mar 14, 2008 at 5:02 PM
Hi!,
The new version of WCSF is supporting dependency injection on ASMX Web Services, but if an update is not possible, you can use the Responsive Composite Web Client Reference Implementation and write code similar to the following in your web service constructor:
// Contructor.
public CustomerService()
{
    WebClientApplication.BuildItemWithCurrentContext(this);
}

Another option, if you need to use services in your web service, is to get it using this code:
WebClientApplication webClientApplication = HttpContext.Current.ApplicationInstance as WebClientApplication;
_userService = webClientApplication.RootContainer.Services.Get<IUserService>();

You can also take a look at this related thread: Interfacing Service using WCF which has ServiceDependency. Getting null references.

Please let me know if this helps,

Jonathan Cisneros
http://staff.southworks.net/blogs/jcisneros/default.aspx