2

I want to have create a WPF or Silverlight module which cannot only be utilised by Shell's bootstrapper, but also can be embedded in non-PRISM applications.

In short is there a way PRISM module can be intialised from module itself rather than initialsing from Shell?

Ulimate goal is to have WPF/Silverlight PRISM module, which can be initialsed by non-PRISM applications.

2 Answers 2

2

There is no barrier to this.

The IModule interface has a single, parameterless void method: Initialize().

A non-prism application can initialize the module by calling that method. That's it.

If the other application has a different plugin system, with a different interface, your module can implement that interface as well, and the body of whatever initialization method that interface uses can simply call Initialize(), or vice versa.

For example:

public interface IMyPluginModule
{
    void StartModule();
}

public class MyModule : IModule, IMyPluginModule
{
    public void Initialize()
    {
        // actual initialization code here
    }

    public void StartModule()
    {
        Initialize();
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

But how would module get a handle of UnityContainer, RegionManager or EventAggregator from non-prism application or do I need to create one if the handle is null?
I'm not sure I understand what you mean by "get a handle," but it is going to depend on whether this other, non-prism application uses any of those things. If your module is designed to deal with IUnityContainer, for example, but the other application uses Castle Windsor, you'd probably want to create a new IUnityContainer implementation that delegates all its calls to Windsor. Same sort of thing with IRegionManager. Alternatively, you design the module with an additional layer of abstraction to delegate DI, view management, event aggregation, etc., instead of consuming prism components.
What I tried doing is your alternate approach that you suggested. But somehow initializing IUnityContainer and IRegionManager from within IModule doesn't seem to work for me. I did configured the container and all other things that is mentioned in typical boostrapper, but I don't know how to add regions dynamically from the code with the container(of non-prism) passed to module intialiser. I used RegionManager.SetRegionName(container, "MainControlRegion"); RegionManager.UpdateRegions(); but that doesnt seem to help
I think Jay's point is that nothing stops you from not using the default implementation of the Prism interfaces. Something still needs to implement IRegionManager, IEventAggregator, etc. If you don't want to use Prism's defualt implementations, you're free to provide your own: but you'll have to roll your own implementations of them. That's obviously non-trivial...
1

It's a little more complicated than it appears at first glance, but it is doable. I don't know if you are using Prism 4 yet, but if so, Microsoft actually provides guidance for this scenario:

http://msdn.microsoft.com/en-us/library/ff921109(v=PandP.40).aspx

There is a bit of project manipulation you need to do to get two projects running side-by-side. There is a sample included with Prism v4 called "MultiTargeting" if you need to see a working sample.

Your question regarding to allowing a module to be initialized by itself, rather than having the orchestrating Shell / Bootstrapper is the wrong approach, however. Essentially what you would have would be two shells... one WPF and one Silverlight. Take a look at the samples and see what you think.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.