Using Prism, Unity and WCF, I have the following simple login scenario.
I define a LoginModule containing three elements : a LoginView, a LoginViewModel, and a LoginService.
What is different from all the other examples I have found is that :
- server url is not known on startup (no app.config wcf definition)
- server url may change (user disconnects, changes server address, and reconnects)
I face two major problems in LoginModule :
- I can't register LoginView, because it depends on LoginViewModel, which needs LoginService . But LoginService can't be registered at that time, because server address is unknown.
- When LoginService is initialized with an address, how to change the underlying channel, LoginService beeing registered using WCF ChannelFactory and Unity ?
I have tried many things using LifetimeManager and proxy, but no success at the moment.
Any help would be appreciated.
Dec 3, 2013 at 7:55 PM
Based on your description I am assuming the user needs to enter the authentication server's address along with the login and password in the
In that case a possible approach to be able to maintain the chain of dependencies is to inject in the view model a
instead of the real WCF Service
that connects to the server. Like this, the
could be constructed and injected by Unity in an "uninitialized" state. When the user enters his credentials along with the server's address the view model could pass that information to the proxy service that will
be in charge of initializing the real WCF Service and authenticating against the server.
How to configure and set-up the real WCF Service to connect to the corresponding server is more of a WCF-specific topic; therefore I believe you might find better support for that part in the Windows Communication Forums forums: