码迷,mamicode.com
首页 > 编程语言 > 详细

spring依赖注入

时间:2015-07-27 18:37:00      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

参考

http://www.cnblogs.com/han1982/p/4177850.html

http://blog.csdn.net/fax5201314/article/details/8777298

http://www.tuicool.com/articles/zI7Rzy

  <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  
  </configSections>

  <spring>
    <context>
      <!--<resource uri="assembly://namespace/project/Objects.xml"/>-->
      <!--<resource uri="file://objects.xml"/>-->
      <resource uri="config://spring/objects" />
    </context>

    <objects>   
      <object id="BLLSession" type="BLL.BLLSession,BLL" singleton="false"></object>
      <object id="DBSessionFactory" type="DALMSSQL.DBSessionFactory,DALMSSQL"></object>
    </objects>
  </spring>
 public class SpringHelper
    {
        private static IApplicationContext SpringContext
        {
            get { return ContextRegistry.GetContext(); }
        }

        public static T GetObject<T>(string objName) where T : class
        {
            return SpringContext.GetObject(objName) as T;
        }
    }
 IDAL.IDBSessionFactory sessionFactory = DI.SpringHelper.GetObject<IDAL.IDBSessionFactory>("DBSessionFactory");

                    iDBSession = sessionFactory.GetDBSession();




IBLL.IBLLSession ibllSession = DI.SpringHelper.GetObject<IBLL.IBLLSession>("BLLSession");
            IBLL.IProductBLL ibll = ibllSession.IProductBLL;
            var list = ibll.GetListBy(a => a.ID >= 0).ToList();

 

spring依赖注入

标签:

原文地址:http://www.cnblogs.com/tgdjw/p/4680650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!