WCF サービス内から Prism モジュール システムをブーストラップできますか? 何をしても、MEF の依存関係が満たされていないからです。
例えば:
これは私のWCF サービスの実装です
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();
}
}
これは、MEF 風味の私のPrism ブーストラップです。
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;
}
}
Database 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 ...
}
最後に、Prism データベース サービス自体を次に示します。
[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 ...
}
これを最後の数時間試しましたが、成功しませんでした。私のdb
インポートは常にnull
初期化されていません。
Prism を使用せずに、MEF のみを使用してこれらすべてを実行すると、すべてが機能することに注意してください。