Note that there are some explanatory texts on larger screens.

plurals
  1. POContext while loading Assemblies via Structuremap
    primarykey
    data
    text
    <p>I want to load plugins in a similar way as <a href="https://stackoverflow.com/questions/809051/ioc-dll-references-and-assembly-scanning/816376#816376">shown here</a> however the loaded assemblies seem not to share the same context.</p> <p>Trying to solve the problem I just build a tiny spike containing two assemblies. One console app and one library. The console app contains the IPlugin interface and has no references to the Plugin dll.</p> <p>I am scanning the plugin dir using a custom Registration convention:</p> <pre><code>ObjectFactory.Initialize(x =&gt; x.Scan(s =&gt; { s.AssembliesFromPath(@"..\Plugin"); s.With(new PluginScanner()); })); public void Process(Type type, Registry registry) { if (!type.Name.StartsWith("P")) return; var instance = ObjectFactory.GetInstance(type); registry.For&lt;IPlugin&gt;().Add((IPlugin)instance); } </code></pre> <p>Which thows an invalid cast exception saying "can not convert the plugin Type to IPlugin".</p> <pre><code>public class P1 : IPlugin { public void Start() { Console.WriteLine("Hello from P1"); } } </code></pre> <p>Further if I just construct the instance (which works fine by the way) and try to access ObjectFactory in the plugin ObjectFactory.WhatDoIHave() shows that plugin instance and host instance don't even share the same container instance.</p> <p>Experimenting around with MEF, Structuremap and loading the assembly manually whith Assembly.Load("Plugin") shows if loaded with Assembly.Load it works fine. Any ideas how I can fix this to work with StructureMaps assembly scanning?</p>
    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.
 

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