Prism and Silverlight: Mapping interface to a type from remote module

Topics: Prism v2 - Silverlight 2
Apr 23, 2009 at 2:35 PM
Edited Apr 23, 2009 at 2:37 PM
In Prism we can map one type to another:
container.RegisterType(typeof(IServiceInterface), typeof(ServiceClass));

But what if we have remote module? Then we know interface (IServiceInterface) and we don't know about concrete class (we haven't reference to assembly with this type).

Of course we can get name of type via service or something else and use it like this:
container.RegisterType(typeof(IServiceInterface), Type.GetType("Here is the name of the concrete class"));

It's not work (Type.GetType returns null, because module is still loading).
So, how I can map interface of remote module to concrete class of remote module using Prism?
Apr 23, 2009 at 6:24 PM



Although I do not know what you application specifics are let me try to see if I understood your scenario correctly.


Let’s say you are in ModuleA. You want to be able to resolve the instance of type IServiceInterface that is registered in the Unity container of your application. But this service is in another module, so as you said you do not have a reference to the concrete implementation of the service.


What you need to do is register the type mapping in the module that does have the implementation of the service, in your example ModuleB. Since you will not be able to resolve the service in ModuleA until ModuleB has registered it into the container, you should have no problem with this.


For the scenario I am thinking, there is a module dependency between modules A and B. ModuleA requires ModuleB to be loaded and register the service before it can work correctly. Prism-v2 tackles this scenario by giving you the possibility of defining modules dependencies. This is explained with detailed in this document:

·         How to: Define Dependencies Between Modules


Please let me know if this helps.


Damian Schenkelman

Apr 24, 2009 at 7:17 AM
Thank you!