1

すべてのインターフェイスを含むアセンブリの名前をCastleに渡し、Castleがそれらのインターフェイスの実装を含む現在のディレクトリ内のすべてのアセンブリを自動的に検索して登録することは可能ですか?

4

1 に答える 1

2

次のコードで問題が解決しました。問題がある場合はコメントしてください。

var InterfacesAssemblyName = /* get assembly name from appSettings */;

if (!string.IsNullOrEmpty(InterfacesAssemblyName))
{
    var interfaces = Assembly.Load(InterfacesAssemblyName).GetTypes().Where(type => type.IsInterface && type.IsPublic).ToList();

    this._container.Register(
        Classes
            .FromAssemblyInDirectory(new AssemblyFilter("bin"))
            .Where(x => x.GetInterfaces().Intersect(interfaces).Any())
            .LifestyleTransient()
            .WithService.DefaultInterfaces());
}
于 2012-07-25T14:05:19.467 に答える