Können Sie ein Prism-Modulsystem vom WCF-Service aus boosten? Denn egal was ich mache, meine MEF Abhängigkeiten werden nicht erfüllt.Prism-Modul-System aus WCF-Service?
ZB:
Das ist mein WCF-Dienst Implementierung
public class MyService : IMyServiceContract{
// This should get filled by MEF after Prism loads the required modules
[Import]
IDatabase db;
public MyService(){
var bootsrapper = new MyServiceBoostrapper();
bootsrapper.Run();
}
}
Das ist mein Prism boostrapper mit MEF Geschmack:
public class MyServiceBoostrapper : MefBootstrapper
{
protected override void ConfigureContainer()
{
base.ConfigureContainer();
}
protected override IModuleCatalog CreateModuleCatalog()
{
return new ConfigurationModuleCatalog();
}
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
// TODO: Add this assembly ... don't know why
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyServiceBoostrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(IDatabase).Assembly));
// This is what provides the service
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(DatabaseImpl).Assembly));
}
protected override DependencyObject CreateShell()
{
// we don't need the shell
return null;
}
}
Hier mein Modul ist dass enthält die Schnittstellen für Datenbank Prism Service:
[ModuleExport(typeof(IDatabase))]
public class ModuleActivator : IModule
{
public void Initialize()
{
// Do nothing as this module simply provides the API.
}
}
public interface IDatabase
{
// interface methods here ...
}
und schließlich ist hier der Prism-Datenbank-Dienst selbst:
[ModuleExport(typeof(DatabaseImpl), DependsOnModuleNames = new string[] { "IDatabase" })]
public class ModuleActivator : IModule
{
public void Initialize()
{
// Do nothing as this is a library module.
}
}
[Export(typeof(IDatabase))]
public class DatabaseImpl : IDatabase
{
/// implementation here ...
}
für die letzten paar Stunden versucht, dies ohne Erfolg. Mein db
Import ist immer null
und wird nie initialisiert.
Beachten Sie, dass alles funktioniert, wenn ich das alles ohne Prisma mache, aber nur mit MEF.
Also, was ist mit den Fortschritten zu diesem Thema? –
Ich glaube, ich habe im Buch "Dependency Injection in .NET" (Teil 3, Kap. 7.3) eine Lösung gefunden. Testen Sie es noch. Im Grunde genommen ist es nur eine Frage des Einstiegs in die WCF-Startroutine. – drozzy
Wie ich in meinem Kommentar gesagt habe. Ich denke wirklich, es ist ein Problem der Konfiguration Ihres Containers und der Registrierung der Typen ... –