1.在寫邏輯層前,需要弄好反轉控制,因框架沒有寫接口,所以Ninject只負責返回當前實例,有點類似共享設計模式。

  public sealed class IOCHelper
{
private static IKernel kernel = new StandardKernel();
/// <summary>
/// 获取注入实例
/// </summary>
/// <typeparam name="T">接口名</typeparam>
/// <param name="name">实例配置名</param>
/// <returns>T的实现实例</returns>
public static T GetInstance<T>(string name = "") where T : class
{
try
{
if (string.IsNullOrEmpty(name))
return kernel.Get<T>();
return kernel.Get<T>(name);
}
catch (Exception ex)
{
throw new Exception("获取注入实例错误,请确认配置是否正确", ex);
} }
}

最新文章

  1. javaSE第一天
  2. hbase表结构设计
  3. poj 3694 pku 3694 Network tarjan求割边 lca
  4. Project Euler 84:Monopoly odds 大富翁几率
  5. eclipse 代码中突然出现特殊字符
  6. UItextField常用方法
  7. framework 4.5.1安装时发生严重错误
  8. Adding Validation to our Album Forms 添加类属性的一些验证特性
  9. Dragger代码实现
  10. poj 2356鸽笼原理水题
  11. 制作Linux登录欢迎界面
  12. Screen Space Depth Varying Glow based on Heat Diffusion
  13. 单点登录SSO:图示和讲解
  14. JS开发工具WebStorm使用快捷键
  15. 12种不宜使用的javascript的语法
  16. Codeforces 934D - A Determined Cleanup
  17. php的ob缓存详解
  18. python常用模块-调用系统命令模块(subprocess)
  19. VS2017安装或卸载错误1303
  20. 【第十九章】 springboot + hystrix(1)

热门文章

  1. 自启动脚本/etc/rc.local文件
  2. mysql的floor()报错注入方法详细分析
  3. FFMPEG+SDL实现视频播放器
  4. 第15节_BLE协议GATT层
  5. Python之flask框架2
  6. shell-基础2
  7. LeetCode 145. Binary Tree Postorder Traversal二叉树的后序遍历 (C++)
  8. 0x00 Wechall writeup
  9. [LeetCode] 99. Recover Binary Search Tree 复原二叉搜索树
  10. Jacobi-Gauss-Lobatto积分点和积分权