Windsor Castle: how to register internal implementations

This registration works when all IService implementations are publicly available:

AllTypes .Of<IService>() .FromAssembly(GetType().Assembly) .WithService.FirstInterface() 

For example:

 public interface IService {} public interface ISomeService : IService {} public class SomeService : ISomeService {} 

The ISomeService permission returns an instance of SomeService.

But if the SomeService class is internal, the container throws an exception stating that ISomeService is not registered.

So, is there a way to register internal implementations for public interfaces?

+3
castle-windsor
source share
1 answer

UPDATE2: Although I think this is not a good idea, you can achieve this with the following code.

 AllTypes.FromAssembly(GetType().Assembly) .IncludeNonPublicTypes() .BasedOn<IService>() .WithService.FirstInterface(); 

UPDATE: This is a very logical behavior, and I consider it a mistake if it were otherwise. AllTypes provides only a public type, because it assumes that if you made your type internal, you did it for some reason, and if it expanded it, it could be a security issue.

When you register a type explicitly on the other hand, it works because Windsor assumes, since you explicitly ask it to use an internal type, you know better.


+5
source share

All Articles