代码之家  ›  专栏  ›  技术社区  ›  stiank81

如何将我的iservicelocator实现设置为servicelocator.current?

  •  4
  • stiank81  · 技术社区  · 15 年前

    我正在用棱镜框架中的ninject替换unity。这需要我实现一个特定于九个对象的iservicelocator。根据我的理解,我可以继承servicelocatorimplbase,所以我就是这么做的。现在如何将其设置为当前服务定位器?我需要这个,以便让区域管理器在创建区域时获得它,并调用:

    IServiceLocator locator = ServiceLocator.Current;
    

    这是一个静态属性,但它没有setter..有一个功能:

    void ServiceLocator.SetLocatorProvider(ServiceLocatorProvider newProvider);
    

    …但参数与我的ServiceLocatorImplBase不匹配。有什么主意吗?

    1 回复  |  直到 14 年前
        1
  •  4
  •   Steven    15 年前

    这个 ServiceLocatorProvider 作为代表,您可以执行以下操作:

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