実行時にプラグイン ディレクトリから複数のアセンブリをロードしたいと考えています。コア アプリには事前にアセンブリへの参照がありません。アセンブリは、コア アプリによって指定されたインターフェイスを実装するため、それへの参照があります。2005 年の記事を見つけて、これを機能させるために何をする必要があるかを正確に説明しています。
現在、私はこのコードを持っています。これは基本的に、上記の記事で見つけたものを LINQ 化したバージョンです。
foreach (
IModule module in
Directory.EnumerateDirectories(string.Format(@"{0}/{1}", Application.StartupPath, ModulePath))
.Select(dir => Directory.GetFiles(dir, "*.dll"))
.SelectMany(files => files.Select(Assembly.LoadFrom)
.SelectMany(assembly => (from type in assembly.GetTypes()
where type.IsClass && !type.IsNotPublic
let interfaces = type.GetInterfaces()
where
((IList) interfaces).Contains(
typeof (IModule))
select
(IModule) Activator.CreateInstance(type))))
)
{
module.Core = this;
module.Initialize();
AddModule(module);
}
実行時にプラグイン/モジュール/アセンブリを動的にロードする現在の方法は何ですか?