zoukankan      html  css  js  c++  java
  • .net core 【二】

    一、构造引擎:

    1.首先Core层创建一个接口实例:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace General.Core
    {
        //系统的引擎接口
        public interface IEngine
        {
            /// <summary>
            /// 构建一个实例
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <returns></returns>
            T Resolve<T>() where T : class;
        }
    }

    2. web层写一个继承实例的方法

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace General.Core
    {
        //系统的引擎接口
        public interface IEngine
        {
            /// <summary>
            /// 构建一个实例
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <returns></returns>
            T Resolve<T>() where T : class;
        }
    }

    3. 在core层添加该方法

    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Runtime;
    using System.Text;
    
    namespace General.Core
    {
        public class EnginContext
        {
            private static IEngine _engine;
    
            /// <summary>
            /// 静态方法的形式去构造出一个对象
            /// </summary>
            /// <param name="engine"></param>
            /// <returns></returns>
            /// 该方法就是保证每次只有一个
            [MethodImpl(MethodImplOptions.Synchronized)]
            public static IEngine Initialize(IEngine engine)
            {
                if (_engine == null)
                    _engine = engine;
                return _engine;
            }
    
            /// <summary>
            /// 当前引擎
            /// </summary>
            public static IEngine Current
            {
                get
                {
                    return _engine;
                }
            }
        }
    }

    4. 添加一个业务层操作对象

     // 添加对象
                EnginContext.Initialize(new GeneralEngine(services.BuildServiceProvider()));
  • 相关阅读:
    hdu 2569
    hdu 2571
    hdu 4540
    Linux:远程到linux的图形界面
    Windows:文件服务器,访问进去不能查看到完整的文件
    Linux:去除认证,加速 SSH登录
    Linux:永久修改网卡的MAC地址
    Loadrunner:LR提交JSON格式的POST请求
    Linux: vi 编辑器中文乱码
    自动化测试相关:Android SDK无法下载问题,不FQ的解决办法
  • 原文地址:https://www.cnblogs.com/wangjinya/p/11651473.html
Copyright © 2011-2022 走看看