Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To avoid your shell app from having to know anything about your modules and your modules from reaching out into the shell in any way, I'd provide an interface to your modules like this:</p> <pre><code>IMergeDictionaryRegistry { void AddDictionaryResource(Uri packUri); } </code></pre> <p>You'd ask for this interface in your Module code:</p> <pre><code>public class MyModule : IModule { IMergeDictionaryRegistry _merger; public MyModule(IMergeDictionaryRegistry merger) { _merger = merger; } public void Initialize() { _merger.AddDictionaryResource(new Uri("pack://application:,,,/Module1;component/Module1Resources.xaml"); } } </code></pre> <p>You would then implement this in your shell to do this:</p> <pre><code>public MergeDictionaryRegistry : IMergeDictionaryRegistry { public void AddDictionaryResource(Uri packUri) { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = packUri; }); } } </code></pre> <p>And then finally, in your Bootstrapper's ConfigureContainer:</p> <pre><code>public override void ConfigureContainer() { base.ConfigureContainer(); Container.RegisterType&lt;IMergeDictionaryRegistry, MergeDictionaryRegistry&gt;(); } </code></pre> <p>This will get you the functionality you want <em>and</em> your Shell and your Module will remain independent of each other. This has the added benefit of being more testable in that you have no need to spin up an <code>Application</code> to test your module code (just mock <code>IMergeDictionaryRegistry</code> and you are done).</p> <p>Let us know how this goes for you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload