zoukankan      html  css  js  c++  java
  • 《Prism 5.0源码走读》Service Locator Pattern

    在Prism Bootstrapper里面取实例的时候使用 ServiceLocator模式,使用的是CommonServiceLocator库 (http://commonservicelocator.codeplex.com/)。

    ServiceLocation定义了IServiceLocator及其基本实现ServiceLocatorImplBase;定义了IServiceLocator委托ServiceLocatorProvider;定义了ActivationException;还有个静态类ServiceLocator。

     Prism ServiceLocator的设置和使用

    1. Bootstrapper定义了抽象方法去设置ServiceLocator

      protected abstract void ConfigureServiceLocator();

    UnityBootstrapper提供了使用Unity Container的实现:

    UnityServiceLocatorAdapter:

    public class UnityServiceLocatorAdapter : ServiceLocatorImplBase
        {

    设置Unity Container到ServiceLocator:

            protected override void ConfigureServiceLocator()
            {
                ServiceLocator.SetLocatorProvider(() => this.Container.Resolve<IServiceLocator>());
            }

    2. 使用ServiceLocator:

            /// <summary>
            /// Initializes the modules. May be overwritten in a derived class to use a custom Modules Catalog
            /// </summary>
            protected virtual void InitializeModules()
            {
                IModuleManager manager = ServiceLocator.Current.GetInstance<IModuleManager>();
                manager.Run();
            }
  • 相关阅读:
    字串变换
    重建道路
    poj3278 Catch That Cow
    机器人搬重物
    [HNOI2004]打鼹鼠
    曼哈顿距离
    邮票面值设计
    poj1101 The Game
    解决了一个堆破坏问题
    模型资源从无到有一条龙式体验
  • 原文地址:https://www.cnblogs.com/codesee/p/3908675.html
Copyright © 2011-2022 走看看