2012-02-17 2 views
2

나는 다음과 같은 설정이있는 경우 :성 윈저 자동 등록

public interface IUsersQuery{} 

public class UsersQuery : IUsersQuery {} 

public interface ICompanyQuery{} 

public class CompanyQuery : ICompanyQuery {} 

이 가능하여 하나의 일을 한 번에 모든 IABCQuery와 해당 구현 ABCQuery을 대신 등록 자동차에를 하나

container.Regsiter(
    Component.For<ICompanyQuery>().ImplementedBy<CompanyQuery>(), 
    Component.For<IUsersQuery>().ImplementedBy<UsersQuery>() 
) 

내가 인터페이스에 마커의 일종을 추가하면 나는 어쩌면 생각,

public interface IEnhancedQuery {} 

public interface IUsersQuery : IEnhanceQuery {} 

public interface ICompanyQuery : IEnhancedQuery {} 

내가 할 수 있을지 모르지만, AllTypes를 통해 자동 등록을 등록하는 데 어려움을 겪고 있습니다.

답변

-1

캐슬에 자동 등록 기능이 있는지는 확실하지 않지만 리플렉션을 사용하여 구현할 수 있는지는 잘 모르겠습니다.

매우 어려운 작업이 수행하지 않는 것

: 자신의 이름이 검색어로 끝

1.Find 모든 인터페이스에 따라이 인터페이스에 사용할 수있는 유형이 있는지

2.Check보고 당신의 규칙에

3.If 유형이 존재하면 구성 요소를 등록하십시오.

2
container.Register(
    Classes.FromThisAssembly() 
     .Where(Component.IsInTheSameNamespaceAs<IUsersQuery>()) 
     .WithServiceDefaultInterfaces() 
     .LifestyleTransient() 
); 

The documentation 자세한 내용은 모두 옵션을 참조하십시오.

+0

'Container.Register (AllTypes.FromThisAssembly(). BasedOn c.LifeStyle.Is (LifestyleType.Transient)))); 'Then IUsersQuery -> 컨테이너에있는 UserQuery. – Liao

+1

구체적 유형으로 자동 이름을 지정하는 방법이 있습니까? –