2009-08-06 14 views
4

私はこのコードを使用して...登録するすべてのコントローラ

 container.Register(
      AllTypes 
      .FromAssembly(Assembly.Load("MyNamespace.Dashboard")) 
      .BasedOn<IController>() 
      .Configure(component => component.LifeStyle.Transient 
      .Named(ControllerNameFromType(component.Implementation))) 
      ); 

...しかし、私はからのすべてのコントローラを登録できるようにしたいと思いますすべてのアセンブリは物事をよりプラガブルにする。私は以下のコードはうまくいくはずだと思ったが、それは思いついた?

 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); 

     foreach (var assembly in assemblies) { 
      container.Register(
       AllTypes 
       .FromAssembly(assembly) 
       .BasedOn<IController>() 
       .Configure(component => component.LifeStyle.Transient 
       .Named(ControllerNameFromType(component.Implementation))) 
       ); 
     } 
+0

得るのですか?もしそうなら、完全なスタックトレースを投稿してください –

+0

はい私はこの例外を取得します。http://pastebin.com/m3c41b842 – Marcus

+0

これはLinq2Sqlの例外です.Windsorに関連していないようです... –

答えて

0

アセンブリをチェックして、すべてのアセンブリがロードされているかどうかを確認します。

はこのような何かを行う場合ではない:あなたは、例外を

 foreach (string dllPath in Directory.GetFiles(directoryPath, "*.dll")) 
     { 
      try 
      { 
       Assembly a = Assembly.ReflectionOnlyLoadFrom(dllPath); 
       if (Matches(a.FullName) && !loadedAssemblyNames.Contains(a.FullName)) 
       { 
        App.Load(a.FullName); 
       } 
      } 
      catch (BadImageFormatException ex) 
      { 
       Trace.TraceError(ex.ToString()); 
      } 
     } 
関連する問題