2014-06-17 2 views
0

성 구조체에 구조체 코드를 포팅하려고합니다.구조체 포트와 윈저 성

No component for supporting the service CreateTestCommandHandler was found 

내가 가지 테스트 콘솔 응용 프로그램을 사용하고 있습니다 :

콘솔 응용 프로그램 :

private static IWindsorContainer _container; 
... 
static void Main() 
{ 
_container = new WindsorContainer(); 
ApplicationBootStrapperCastleWindsor.BootStrap(_container); 
... 

좀 더 단축 코드 :

public class CreateTestCommandHandler : ICommandHandler<CreateTestCommand> 
     { 
      private readonly IDomainRepository<IDomainEvent> _repository; 

      public CreateTestCommandHandler(IDomainRepository<IDomainEvent> repository) 
      { 
       _repository = repository; 
      } 
... 
을 순간, 나는이 오류를 얻고있다

및 :

,

과 :

public class DomainInstaller : IWindsorInstaller 
{ 
public void Install(IWindsorContainer container, IConfigurationStore store) 
{ 
    container.Register(
    Component.For<IDomainRepository<IDomainEvent>>().ImplementedBy<DomainRepository<IDomainEvent>>()); 

누군가가 어떤 명백한 잘못 볼 수 있을까요? 컨테이너를 검사하면 잠재적으로 재구성 된 구성 요소에 IDomainRepository도 표시됩니다. 다음

원래 structuremap 코드 :

ForRequestedType<IDomainRepository<IDomainEvent>>() 
.TheDefault.Is.OfConcreteType<DomainRepository<IDomainEvent>>(); 

PS :

실제 예외 (일본어 structuremap 코드 here을 발견 할 수있다) GetCorrectlyInjectedCommandHandler에 슬로우

:

public class RegisterCommandHandlersInMessageRouter 
    { 
     private static IWindsorContainer _container; 

     public static void BootStrap(IWindsorContainer container) 
     { 
      _container = container; 
      new RegisterCommandHandlersInMessageRouter().RegisterRoutes(new MessageRouter()); 
     } 

     private static object GetCorrectlyInjectedCommandHandler(Type commandHandler) 
     { 
      return _container.Resolve(commandHandler); 
     } 
    } 
+0

'CreateTestCommandHandler'를 등록한 코드와 오류가 발생한 코드를 표시 할 수 있습니까? –

+0

답장을 보내 주셔서 감사합니다. 나는 원래의 질문에 적응했다 (PS 참조). 예외는 GetCorrectlyInjectedCommandHandler에서 throw됩니다. 내가 콘크리트 인 것처럼 CreateTestCommandHandler를 등록해야한다는 것에 대해 혼란 스럽다. – cs0815

답변

1

에게 그것을 윈저가 당신의 구성 요소를 어떻게 찾았는지 오해하고있는 것처럼 보입니다. 구성 요소를 명시 적으로 등록 할 수 있습니다 (예 : DomainInstallerIDomainRepository<IDomainEvent>을 입력 한 경우) 또는 모든 유형을 규칙으로 어셈블리에 등록 할 수 있습니다. 어느 쪽이든 윈저에 귀하의 유형에 대해 말하지 않으면 귀하가받은 예외를 던질 것입니다.

보기를 시작하면 쉽게 시작할 수있는 경향이 있으며 많은 유지 관리를 줄일 수 있습니다. 라이프 스타일이나 특정 구성 요소의 다른 속성을 변경해야하는 경우 수동 등록을 수행하여 자동 등록을 무시할 수 있습니다 (위와 동일).

StructureMap에 대해 많이 알지는 못하지만 이미 사용하고있는 it has similar auto-registration functionality이 있습니다.

+0

나는 둘 다 과거의 혼합물을 사용했습니다. 우선 원래 구조 맵 코드를 복제하고 싶습니다. – cs0815

+0

'CreateTestCommandHandler'를 윈저에 등록해야합니다. 만약 수동으로하고 싶다면'container.Register (Component.For ()); '를 호출하십시오. 이것은 [documentation] (http://docs.castleproject.org/Windsor.Registering-components- one-by-one .ashx). –

+0

감사합니다. 나는 그 의사를 연구 할 것이다. 어떤 생각을 어떻게 '자동'으로 할 것인가? 제 기억이 맞다면 수업을받을 때 할 수 있다고 생각합니다. – cs0815