MVC 涡轮机的寿命管理?
如何管理 mvc 涡轮机中服务的生命周期(使用 Unity)?
我有一个 ISearchService 实现 LuceneSearchService,它采用 IConfigurationService 和 ILoggerService。
目前我的搜索服务注册如下所示:
public class SearchServiceRegistration: IServiceRegistration
{
public void Register(IServiceLocator locator)
{
locator.Register<ISearchService, LuceneSearchService>();
}
}
我想保留在 Turbine 中创建实例的责任,但我希望它是一个单例。
或者换句话说,我该如何定义生命周期?
How can I manage the lifetime of my services in mvc turbine (using Unity)?
I have an ISearchService implementation LuceneSearchService that takes an IConfigurationService and ILoggerService.
Currently my searchservice registration looks like this:
public class SearchServiceRegistration: IServiceRegistration
{
public void Register(IServiceLocator locator)
{
locator.Register<ISearchService, LuceneSearchService>();
}
}
I would like to keep the responsibility of creating the instance in Turbine, but I want it to be a singleton.
Or in other words, how can I define the lifetime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,涡轮钻头不允许进行生命周期管理,因为我认为这最适合您的容器。如果您有兴趣,可以使用我在这篇博客文章中定义的内容: 将您最喜欢的 IoC 注入 MVC Turbine
如果您同意在 IServiceRegistration 实现中公开您的容器,您可以执行以下操作:HACK 在您的注册中暴露您的特定 SL
如果我收到很多需要生命周期管理的请求,我会将其添加到 Turbine 的 V3 中。
Currently the Turbine bits don't allow for lifetime management since I felt that was best suited work for your container. If you're interested, you can use something like what I define on this blog post: Injecting Your Favorite IoC Into MVC Turbine
If you're OK with exposing your container with your within your IServiceRegistration implementation you can do something like this: HACK to expose your specific SL within your registration
If I get a lot of requests for the need of lifetime management, I will add it to V3 of Turbine.