[C#] MEF SIlverlight acceder au DLL
Bonjour,
Je développe une application en utilisant Silverlight, et je souhaiterais implémenter un systeme de plugin.
Cependant la documentation et les tutos sur MEF sont soit obsolètes, soit incomplets.
Je souhaite charger une classe simple située dans un autre projet (projet de type classe).
Ce qu'il manque dans mon code, c'est la configuration de MEF afin d'acceder à l'endroit ou est placé le plugin, ce que je n'arrive pas à importer.
Voici mon code du coté de l'application:
app.xaml.cs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
namespace MEFdevellopez
{
public partial class App : Application
{
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
CompositionInitializer.SatisfyImports(this);
var mainPage = new MainPage();
RootVisual = mainPage;
}
private void Application_Exit(object sender, EventArgs e)
{
}
}
public abstract class IPlugin
{
public string reponse;
public string getMere()
{
return reponse;
}
}
} |
mainpage.xaml.cs:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
namespace MEFdevellopez
{
public partial class MainPage : UserControl
{
[Import]
public IPlugin plug{ get; set; }
public class Plugin : IPlugin
{
}
public MainPage()
{
Plugin mere = (Plugin)plug;
InitializeComponent();
textBox1.Text = mere.getMere();
}
}
} |
Et la classe que je veux exporter:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
namespace DLL
{
public abstract class IPlugin
{
public string reponse;
public string getMere()
{
return reponse;
}
}
[Export(typeof(Plugin))]
public class Plugin : IPlugin
{
public Plugin()
{
this.reponse = "lol";
}
}
} |
Merci d'avance;
Cordialement;
Eko