Why i need to add reference module from shell project?

Topics: Prism v4 - Silverlight 4
Sep 24, 2012 at 6:03 PM

Hi to all friends out there.

I am developing application by using Modularity of prism.To make it work i have to add reference in my shell module.If i have to do so ,don't we are loosing decoupling of application concept.

It may be possible i am not aware of other solution.So if there is any way to add reference of module without there directly adding reference than please me clear.

 

Thanks in advance.

Developer
Sep 25, 2012 at 9:45 PM
Edited Sep 25, 2012 at 9:46 PM

Hi,

I believe you could find the following chapter of the Prism documentation useful regarding this topic:

There you could find the different approaches you could use to register your modules in your application. As far as I know Prism allows Registering modules for Silverlight applications in the following ways:

  • Directly in code. Modules can be directly registered in the module catalog in the application code. Using this approach, you can use conditional logic to determine which module should be included in your application. Modules added in code are referenced by the application instead of being loaded at run time.
  • Using XAML. Prism can register modules with the module catalog by loading an Extensible Application Markup Language (XAML) file. Declaring the modules in XAML allows the modules to be downloaded and initialized independent of the application XAP file.

Which approach you take will depend on what your application needs, if you require not having references to the modules then using a configuration XAML file should be the recommended approach.

Also for examples of this approaches I recommend you to check the Modularity QuickStarts for Silverlight provided with Prism.

I hope you find this useful,

Agustin Adami
http://blogs.southworks.net/aadami

Sep 26, 2012 at 10:57 AM

Thanks for reply.

I think you don't get my problem.I am only able to register module when i reference to solution.Without adding reference it gives error " missing reference of assembly like which we get normally when you don't reference assembly and use it.

While using XAML do we need to add reference also like i have to do while adding in view model.

 

Thanks in advance.

Developer
Sep 26, 2012 at 10:47 PM

Hi,

When registering a module in XAML, you don't to reference the module in the shell project. That is because you don't need to register the module in the bootstrapper's code; instead the module is defined in a XAML file, from which the module catalog will be created.

As an example, you can take a look at the Modularity QuickStart provided with Prism as out of the box. This QuickStart has several modules, where the modules B, D, E and F are defined in the ModulesCatalog.xaml file and not in code. To create a module catalog using the aforementioned XAML file, the bootstrapper of the QuickStart has the following code:

        protected override IModuleCatalog CreateModuleCatalog()
        {
            // Module B, D, E and F are defined in XAML.
            return Modularity.ModuleCatalog.CreateFromXaml(new Uri("/ModularityWithUnity.Silverlight;component/ModulesCatalog.xaml", 
UriKind.Relative)); }
The shell project of the Modularity QuickStart does not reference module B, D, E or F. However, the QuickStart is able to identify and load the aforementioned modules using the XAML file.

On the other hand, if you are receiving "missing reference or assembly" error, this could be cause by:

  • You are trying to register the modules both in XAML and in code.
  • Your shell project uses code directly from those modules.

In the later case, this would mean that your shell project is coupled up to some degree to the module, and therefore, you cannot decouple it from the shell. You will need first to refactor the shell project to avoid using the module's code directly (for example, using interfaces, dependency injection, etc).

I hope this helps.

Damian Cherubini
http://blogs.southworks.net/dcherubini

Sep 27, 2012 at 5:47 AM

Hi

Thanks allot for making me clear.