RESOLVE CLASS WITH PROPERTIES SET

Feb 11, 2011 at 8:25 PM

I am developing a WPF shell application with VS2010 that implements the MVVM pattern. I’m using the Prism 4.0 framework with the Unity 2.0 container. I cannot instantiate a class and set its properties during bootstrapper processing and resolve the class with the properties set during the instantiation of another class library implementing the Prism IModule interface. That is my goal. Am I on the right track with the process I describe below? If so am I missing a step? If I’m on the wrong track is there a better way to make application wide values available to all modules?

Authentication takes place in the application startup event where I store session information in a module reference type for later access. This occurs before the bootstrapper is run. I add a module class library I call ‘Maintenance’ in the bootstrapper ConfigureModuleCatalog() overrides setting the InitializeMode to OnDemand. In the ConfigureContainer() overrides of the bootstrapper I instantiate a session class named ‘SessionData’ that implements interface ISessionData, set its properties from the previously stored authentication information and register the instance as follows:

Dim SD As New SessionData
With SD
    .LocalSessionID = LocalSessionID
   .LocalCNS = LocalCNS
End With
Me.Container.RegisterInstance(Of ISessionData)("SessionData", SD)

 

In the InitializeShell() override of the boostrapper I can resolve the instance with no problem using the following statement:

Dim aSD As ISessionData = Container.Resolve(Of ISessionData)("SessionData")

 

When I launch the Maintenance module with button click processing and attempt to obtain a reference in the Maintenance module constructor with the same statement:

Dim sd As ISessionData = Me.container.Resolve(Of ISessionData)("SessionData")

 

it throws an error:

The current type, ISessionData, is an interface and cannot be constructed. Are you missing a type mapping?

I do not get an error with the following statement but the property values are not set:

Dim sd As Object = Me.container.Resolve(Of SessionData)("SessionData") 

In debug mode I can see that the container has the type registered.

I’ve also tried the RegisterInstance method in the bootstrapper using SessionData instead of ISessionData with similar results.