ServiceDependency using WCF Proxy

Topics: Web Client Software Factory, User Forum
Mar 11, 2008 at 8:49 PM
Edited Mar 11, 2008 at 8:51 PM
I have an issue with using ServiceDependency attribute when the object being built by ObjectBuilder is a WCF proxy class. ObjectBuilder will create the proxy object then give the presenter the same object every time. I need a new instance of the proxy each web request. I tried using CreateNew but then ObjectBuilder fails as it cannot create an instance of an Interface.

Am I missing something fundamental here or does WCSF not play nice with WCF. It also seems that if you use the Module Services concept then the object that is created becomes a singleton. If this is the case, then WCF services with PerSession instancecontexts and WCSF are mutually exclusive

// Controller
protected virtual void AddModuleServices( IServiceCollection moduleServices )
moduleServices.AddNew<ProxyReadSavedJobs, IReadSavedJobs>();

// Presenter
public SavedJobsPresenter( CreateNew IMyAccountController controller, ServiceDependency IReadSavedJobs readSavedJobs )
this.controller = controller;
this.readSavedJobs = readSavedJobs;

// Proxy
public class ProxyReadSavedJobs : ClientBase<IReadSavedJobs>, IReadSavedJobs
Mar 12, 2008 at 1:20 AM
Edited Mar 12, 2008 at 1:59 AM

I think you can use the CreateNew attribute if you specified a type mapping so it knows which concrete class to create. (notice your IMyAccountController is doing this)
In your module init:
container.RegisterTypeMapping<IReadSavedJobs , ProxyReadSavedJobs>();

This is new for CWAB 2.0.

Jarod Ferguson

Mar 13, 2008 at 12:20 AM
Yep. A type mapping should help you create an instance of that interface. Without the type mapping, there is no way to know which concrete type to use.

One neat feature we don't highlight very much in the docs is the ability to have a type mapping in ModuleA for IMyAccountController that points to MySimpleAccountController. Over in ModuleB, the same interface can be mapped to MyReallyCoolAccountController. With things like Loggers, this can allow debugging or instrumentation of one module at a time. I remember talking about the ability to do this via config as well, but I can't remember if it made it in or not...

Michael Puleio - patterns & practices