Autocomplete And Injection

Topics: Web Client Software Factory
Mar 11, 2008 at 10:32 PM
Edited Mar 11, 2008 at 10:35 PM
Is there anyway to use dependency injection in the webservice used by the ContextSensitiveAutoCompleteExtender? Or maybe get a reference to the CompositionContainer?
Mar 13, 2008 at 1:33 AM
Edited Mar 13, 2008 at 1: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.

Michael Puleio - patterns & practices
Mar 13, 2008 at 2:48 PM
Nice. Thanks for that. I should have known it would be something so simple.
Mar 14, 2008 at 6:02 PM
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()

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