如何将我的 IServiceLocator 实现设置为 ServiceLocator.Current?

发布于 2024-08-28 04:24:25 字数 451 浏览 6 评论 0原文

我正在努力在 Prism 框架中用 Ninject 替换 Unity。这需要我实现一个 Ninject 特定的 IServiceLocator。根据我的理解,我可以继承 ServiceLocatorImplBase,所以这就是我所做的。现在如何将其设置为当前 ServiceLocator?我需要这个,以便 RegionManager 在创建区域时获取它,并调用:

IServiceLocator locator = ServiceLocator.Current;

这是一个静态属性,但它没有设置器..有一个函数:

void ServiceLocator.SetLocatorProvider(ServiceLocatorProvider newProvider);

..但参数不匹配我的 ServiceLocatorImplBase。有什么想法吗?

I'm working on replacing Unity with Ninject in the Prism framework. This requires me to implement a Ninject specific IServiceLocator. From what I've understood I can inherit the ServiceLocatorImplBase instead, so that's what I do. Now how can I set this to be the Current ServiceLocator? I need this in order to have e.g. the RegionManager get it when it creates regions, and calls:

IServiceLocator locator = ServiceLocator.Current;

This is a static property, but it doesn't have a setter.. There is a function:

void ServiceLocator.SetLocatorProvider(ServiceLocatorProvider newProvider);

..but the argument doesn't match my ServiceLocatorImplBase. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送你一个梦 2024-09-04 04:24:25

ServiceLocatorProvider 是一个委托,您可以这样做:

var container = NInjectServiceLocator(); // your ServiceLocatorImplBase impl.

ServiceLocator.SetLocatorProvider(() => container);

The ServiceLocatorProvider is a delegate, you can do this:

var container = NInjectServiceLocator(); // your ServiceLocatorImplBase impl.

ServiceLocator.SetLocatorProvider(() => container);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文