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();
            }
  • 相关阅读:
    centos 7 安装zabbix 4.0
    django Middleware
    初探paramiko
    python中的反射
    python异常处理
    双绞线
    简易的CMDB服务端
    4-初识Django Admin
    数据资产管理实践纲要
    matplotlib 散点图,为不同区域的点添加不同颜色
  • 原文地址:https://www.cnblogs.com/codesee/p/3908675.html
Copyright © 2011-2022 走看看