Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm working on a solution where the MEF parts that I want to use across WCF calls are stored in a singleton at the application level. This is all hosted in IIS. The services are decorated to be compatible with asp.net. </p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] </code></pre> <p>In Global.asax, I import the parts. </p> <pre><code>[ImportMany(typeof(IOption))] public IEnumerable&lt;IOption&gt; AvailableOptions{ get; set; } </code></pre> <p>After initializing the catalog and container, I copy the imported objects to my singleton class.</p> <pre><code>container.ComposeParts(this); foreach (var option in AvailableOptions) OptionRegistry.AddOption(option); </code></pre> <p>EDIT:</p> <p>My registry class:</p> <pre><code>public static class OptionRegistry { private static List&lt;IOption&gt; _availableOptions= new List&lt;IOption&gt;(); public static void AddOption(IOption option) { if(!_availableOptions.Contains(option)) _availableOptions.Add(option); } public static List&lt;IOption&gt; GetOptions() { return _availableOptions; } } </code></pre> <p>This works but I want to make it thread safe so I'll post that version once it's done.</p> <p>Thread-safe Registry:</p> <pre><code>public sealed class OptionRegistry { private List&lt;IOptionDescription&gt; _availableOptions; static readonly OptionRegistry _instance = new OptionRegistry(); public static OptionRegistry Instance { get { return _instance; } } private OptionRegistry() { _availableOptions = new List&lt;IOptionDescription&gt;(); } public void AddOption(IOptionDescription option) { lock(_availableOptions) { if(!_availableOptions.Contains(option)) _availableOptions.Add(option); } } public List&lt;IOptionDescription&gt; GetOptions() { return _availableOptions; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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