2011-09-28 2 views
0

저는 Castle Windsor IoC를 시작했습니다. 예제를 따르는 데 어려움을 겪고 있습니다. 누군가이 간단한 콘솔 응용 프로그램이 실패하는 이유를 설명해주십시오. 나는 쉬운 것을 놓치고 있어야합니다. 감사.Castle Windsor가이 간단한 예제에서 ComponentNotFoundException을 던지는 이유는 무엇입니까?

using System; 
using Castle.MicroKernel.Registration; 
using Castle.MicroKernel.SubSystems.Configuration; 
using Castle.Windsor; 
using Castle.Windsor.Installer; 

namespace CastleTest 
{ 
    public interface ISomething 
    { 
     void DoSomething(); 
    } 

    public class Something : ISomething 
    { 
     public void DoSomething() 
     { 
      Console.WriteLine("Hello World"); 
     } 
    } 

    public class SomethingInstaller : IWindsorInstaller 
    { 
     public void Install(IWindsorContainer container, IConfigurationStore store) 
     { 
      container.Register(AllTypes.FromThisAssembly().BasedOn<ISomething>()); 
     } 
    } 

    class Program 
    { 
     static void Main() 
     { 
      using (var container = new WindsorContainer()) 
      { 
       container.Install(FromAssembly.This()); 

       // the following line throws a ComponentNotFoundException 
       var something = container.Resolve<ISomething>(); 

       something.DoSomething(); 
      } 
     } 
    } 
} 

답변

2

절대로, 문제를 발견했습니다.

설치 프로그램이 서비스를 등록해야합니다. 수정 된 내용 :

public void Install(IWindsorContainer container, IConfigurationStore store) 
{ 
    container.Register(AllTypes.FromThisAssembly().BasedOn<ISomething>() 
         .WithService.DefaultInterface() 
        ); 
} 
관련 문제