Note that there are some explanatory texts on larger screens.

plurals
  1. POMef and asp.net problem
    text
    copied!<p>I have an asp.net application using a model assembly (with a Model class) for business logic. This model assembly has a dependency on a MailService through an IMailService interface and I am trying to use MEF to fill the Models need for a MailService implementation. I am doing the MEF composition in the contructor of the Model class.</p> <p>The idea behind this is to create a MailService assembly I can reuse between my websites without the sites themselves need to know how the mail is sent. Maybe an IoC container would be a better choise but I just think the MEF approach is simpler to understand and I like the idea of composing my apps by combining parts. Also does the mef approach have any negative sides if you compare with a IoC container?</p> <pre><code>[Import] private IMailService _mailService; public Model() { Compose(); } private void Compose() { DirectoryCatalog cat = new DirectoryCatalog(Settings.Default.PluginsFolder); var container = new CompositionContainer(cat); container.ComposeParts(this); } </code></pre> <p>The code below is in another assembly and the interface in yet another assembly</p> <pre><code>[Export(typeof(IMailService))] public class MailService : IMailService { } </code></pre> <p>this works fine in my unit tests for the model assembly but when I am using the model assembly through my asp.net site it fails with the exception below. I also tried to set the trust to full in web.config but still no luck</p> <blockquote> <p>The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.</p> <p>1) No exports were found that match the constraint '((exportDefinition.ContractName = "ExtensionInterfaces.IMailService") &amp;&amp; (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") &amp;&amp; "ExtensionInterfaces.IMailService".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.</p> <p>Resulting in: Cannot set import Model.Model._mailService (ContractName="ExtensionInterfaces.IMailService")' on part Model.Model'. Element: Model.Model._mailService (ContractName="ExtensionInterfaces.IMailService") --> Model.Model</p> </blockquote>
 

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