Castle Windsor Fluent Configuration:是否可以在不使用具体实现的情况下为给定服务制定特定的生活方式?
我有一组服务,想要使用流畅的注册技术向 Castle Windsor(版本 3.0 RC1)注册。
我希望除了特定的一个使用短暂的生活方式之外的所有其他人都希望成为单身人士,所以我这样做:
container.Register(AllTypes
.FromThisAssembly()
.InSameNamespaceAs<IMyService>()
.WithServiceDefaultInterfaces()
.ConfigureIf(s => s.Implementation == typeof(MyService),
s => s.LifestyleSingleton(),
s => s.LifestyleTransient()));
我遇到的问题是我正在使用 typeof(MyService)在ConfigureIf的第一个参数中,但如果我可以使用IMyService来确定它是否是单例(即实现是什么并不重要,它应该始终是单身人士)。这有可能吗?
I have a collection of services that I want to register with Castle Windsor (version 3.0 RC1) using the fluent registration technique.
I want all of them except for a particular one to use the transient lifestyle and that one I want to be a singleton, so I do this:
container.Register(AllTypes
.FromThisAssembly()
.InSameNamespaceAs<IMyService>()
.WithServiceDefaultInterfaces()
.ConfigureIf(s => s.Implementation == typeof(MyService),
s => s.LifestyleSingleton(),
s => s.LifestyleTransient()));
The problem I have with that is that I am using typeof(MyService) in the first parameter of ConfigureIf, but I would prefer it if I could use IMyService to determine whether it is a singleton or not (i.e. it does not matter what the implementation is, it should always be a singleton). Is that somehow possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢 oleksii,他建议查看这个问题:如何确定一个类型是否实现了特定的泛型接口类型在问题的评论中,对此的答案是执行以下操作:
With many thanks to oleksii, who suggested looking at this question: How to determine if a type implements a specific generic interface type in the comments on the question, the answer to this is to do the following: