温莎城堡:启动服务时的自定义处理
Windsor实例化类型时是否可以执行一些自定义处理?
类似于:
container.Register(
AllTypes.Pick()
.FromAssembly(Assembly.GetExecutingAssembly())
.BasedOn<MyMarkerInterface>()
.WhenInstantiating(instance => // do some stuff with this instance)
.Configure(component => component.Startable().LifeStyle.Singleton)
.WithService.Base());
目前我们正在使用 IStartable< /a>.由于“开始”代码(即自定义处理)是相同的,因此最好将此逻辑移出每个类。
谢谢! 布莱恩
Is it possible to perform some custom processing when Windsor instantiates a type?
Something similar to:
container.Register(
AllTypes.Pick()
.FromAssembly(Assembly.GetExecutingAssembly())
.BasedOn<MyMarkerInterface>()
.WhenInstantiating(instance => // do some stuff with this instance)
.Configure(component => component.Startable().LifeStyle.Singleton)
.WithService.Base());
Currently we are using IStartable. Since the "Start" code (i.e. the custom processing) is identical it would be nice to move this logic out of each class.
Thanks!
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是指类似
OnCreate
方法吗?Singleton 是默认的生活方式,因此您不必明确声明。
但请注意,与可启动设施的工作方式相比,此处的行为略有不同。
此外,虽然文档指出 OnCreate 存在于设施中,但事实已不再如此(是的,我们需要更新文档)。此方法开箱即用。
You mean something like
OnCreate
method?Singleton is default lifestyle so you don't have to state that explicitly.
Notice however that behavior is slightly different here, as compared to how Startable facility works.
Also while the docs state that OnCreate lives in a facility, it is not true anymore (yeah, we need to update docs). This method will work out of the box.