Caliburn 是否提供了一种从任何地方获取容器引用的方法?
我目前正在研究 Rob Eisenberg 的 Caliburn 框架。 查看 http://caliburn.codeplex.com 上提供的文档时,有一个示例说明如何从容器解析 Caliburn 服务。
这与此类似:
SimpleContainer container = new SimpleContainer();
CaliburnFramework
.ConfigureCore(container)
.WithCommonDialogs()
.WithPresentationFramework()
.Start();
var service = container.GetInstance(typeof (IService)) as Service;
但是我缺少的是一种在应用程序中的任何位置获取对容器的引用的方法。 像这样:
var service = Caliburn.Container.GetInstance(typeof(IService))as Service;
我是否必须构建一个自定义静态类来保存对容器的引用,或者 Caliburn 中是否已经内置了某些内容?
预先致谢并致以诚挚的问候!
I'm currently messing around with Rob Eisenberg's Caliburn framework. When looking at the documentation that is provided on http://caliburn.codeplex.com there is an example of how to resolve a Caliburn service from the container.
It's something along the lines of this:
SimpleContainer container = new SimpleContainer();
CaliburnFramework
.ConfigureCore(container)
.WithCommonDialogs()
.WithPresentationFramework()
.Start();
var service = container.GetInstance(typeof (IService)) as Service;
However what I am missing is a way to get a reference to the container anywhere in the app. Like this:
var service = Caliburn.Container.GetInstance(typeof(IService))as Service;
Do I have to build a custom static class that holds a reference to the container or is there something already built into Caliburn?
Thanks in advance and best regards!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Caliburn 的最新主干版本会在框架启动时自动将容器注册为服务定位器。 您只需在代码中引用
Microsoft.Practices.ServiceLocation
,然后向ServiceLocator
请求您的服务实例。希望有帮助。
The latest trunk version of Caliburn automatically registers the container on framework startup as an service locator. You just have to reference
Microsoft.Practices.ServiceLocation
on your code and then ask theServiceLocator
for a instance of your service.Hope that helps.