Click here to Skip to main content
15,918,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made an example solution with an Shell application, two WPF library views, and a Class Library projects. The Class Library is the repository with interface for a string variable. I can access the repository string variable to get the message "Hello World". But I am unable to figure out how to Set or write to the variable to change its value. I want to demonstrate how the repository could be used as a global variable accessible by multiple WPF Library projects. Is this possible or do I have the concept wrong?

Here is my Bootstrapper

Imports Microsoft.Practices.Prism.UnityExtensions
Imports Microsoft.Practices.Unity
Imports Microsoft.Practices.Prism.Modularity
Imports Repository

Namespace HelloWorld
    Friend Class Bootstrapper
        Inherits UnityBootstrapper

        Protected Overrides Function CreateShell() As DependencyObject

            Me.Container.RegisterType(Of ISERepository, SERepository)()
            Return Me.Container.Resolve(Of Shell)()
        End Function

        Protected Overrides Sub InitializeShell()

            Application.Current.MainWindow = CType(Me.Shell, Window)
        End Sub
        Protected Overrides Sub ConfigureModuleCatalog()

            Dim moduleCatalog As ModuleCatalog = CType(Me.ModuleCatalog, ModuleCatalog)

        End Sub
    End Class
End Namespace

Here is the Repository Class Library

Namespace Repository
    Public Class SERepository
        Implements ISERepository

        Private m_message As String = "Hello World"
        Public Function GetMessage() As String Implements ISERepository.GetMessage
            Return m_message
        End Function
        Public Sub SetMessage(ByVal value As String) Implements ISERepository.SetMessage
            m_message = value
        End Sub
    End Class

    Public Interface ISERepository
        Function GetMessage() As String
        Sub SetMessage(ByVal value As String)
    End Interface

Message 1 just displays the repository value, here is the code for the ViewModel
Imports Repository
Imports Microsoft.Practices.Prism.ViewModel

Namespace Message1.ViewModel

    Public Class Message1Model
        Inherits NotificationObject

        Private _messageService As ISERepository
        Public Sub New(ByVal messageData As ISERepository)
            _messageService = messageData

            messageText = messageData.GetMessage()
        End Sub
    Public Property messageText As String
                Return m_messageText
            End Get
            Private Set(ByVal value As String)
                m_messageText = Value
            End Set
    End Property
    Public m_messageText As String

    End Class
End Namespace

Here is the Message 1 View
Imports Message1.ViewModel
Imports Microsoft.Practices.Unity

Namespace Message1.View
    Partial Public Class Message1View
        Inherits UserControl

        <Dependency()> _
        Public WriteOnly Property ViewModel() As Message1Model
            Set(ByVal value As Message1Model)
                DataContext = value
            End Set
        End Property

        Public Sub New()
        End Sub

    End Class
End Namespace

Message 2 contains a button and a text box. The plan was to transfer the contents of the text box to the Repository when the button is clicked. I have not been able to figure out how to write to the containers instance of the Repository. Can this approach work?
Updated 21-Dec-13 4:45am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900