是否可以根据命名惯例在Castle Windsor中自动注册?

时间:2017-07-25 12:18:23

标签: c# inversion-of-control castle-windsor

public interface IMySpecialService {}
public interface MySpecialService : IMySpecialService {}

是否可以将MySpecialService注册为IMySpecialService的所选实现,而无需指定接口或实现的详细信息?即我可以将Castle Windsor配置为使用接口名称减去I吗?

1 个答案:

答案 0 :(得分:2)

这个应该适合你:

container.Register(
    Classes.FromThisAssembly()
        .InNamespace("YourNamespace")
        .WithService.DefaultInterfaces()
);

更多信息:

https://github.com/castleproject/Windsor/blob/master/docs/registering-components-by-conventions.md

相关问题