Controller private constructor

Topics: CAB & Smart Client Software Factory
Feb 9, 2006 at 4:19 AM
originally posted by: caldarola

If I provide a controller private constructor I get the following exception:

Message: "Could not find an appropriately matching constructor."

Source: "Microsoft.Practices.ObjectBuilder"

TargetSite: {Void InitializeObject(Microsoft.Practices.ObjectBuilder.IBuilderContext, System.Object, System.String, Microsoft.Practices.ObjectBuilder.ICreationPolicy)}
Feb 9, 2006 at 4:59 AM
originally posted by: RossNeilson

If you want a member of your class, be it a constructor, property, event or anything else, to be visible to CAB's infrastructure then it must be declared Public.

Although CAB uses reflection to access these members it can still only work with those that are Public. I guess the CAB team could have used reflection to get at all the members but this would violate encapsulation. I think it is also possible for assemblies to prevent Reflection accessing non-Public members anyway.

So just switch your constructor over to be Public and it should work.
Feb 9, 2006 at 8:42 AM
originally posted by: BradWilsonMSFT

That is correct. CAB can only find public things.
Dec 1, 2009 at 12:49 PM

I have a cab module that uses a singleton.  The constructor for the singleton HAS to be private.  If it is not, I get the above error as well.  How do we deal with singletons. (The singleton is a WCF Service Agent, that manages channel re-use.. it has to be a singleton)

Thanks

Jess

Coordinator
Dec 1, 2009 at 8:07 PM

Hi Jess,

To address singletons with the SCSF, you can use the concept of Services. As this article about Service Location from the SCSF documentation explains: “Any WorkItem can contain only a single instance of a service type, but instances of the same service type can be placed in multiple WorkItems.

A possible approach that takes advantage of this could be adding your class to the application’s RootWorkItem Service’s collection. Each time you get the service from the RootWorkItem you will be getting the same instance. You can check how SCSF follows this approach in the BankBranch Workbench RI, in the AddServices method of the SmartClientApplication class.

You can read more about this topic in the following article:

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman