标签:abs domain www sys 1.0 details bsp defaults 需要
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SpringDemo.Pub { public static class Pub { public static string ServiceNameA = "SpringDemo.Lib.Oracle.OracleDatabase"; public static string ServiceNameB = "SpringDemo.Lib.Sql.SqlDatabase"; public static string FullNameA = "SpringDemo.Lib.Oracle.OracleDatabase, SpringDemo.Lib.Oracle"; public static string FullNameB = "SpringDemo.Lib.Sql.SqlDatabase, SpringDemo.Lib.Sql"; public static Type TypeA = Type.GetType(FullNameA); public static Type TypeB = Type.GetType(FullNameB); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SpringDemo.Lib; using Spring.Core; using Spring.Context; using Spring.Context.Support; using Spring.Objects.Factory.Support; namespace SpringDemo.Lib.Mgr { /// <summary> /// 管理类 /// </summary> public partial class Mgr { private static IApplicationContext container = null; /// <summary> /// 自定义容器和组件注册 /// </summary> /// <returns></returns> public static IApplicationContext GetContainer() { if (container == null) { IObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); AbstractObjectDefinition defiA = factory.CreateObjectDefinition(SpringDemo.Pub.Pub.FullNameA, null, AppDomain.CurrentDomain); AbstractObjectDefinition defiB = factory.CreateObjectDefinition(SpringDemo.Pub.Pub.FullNameB, null, AppDomain.CurrentDomain); //建立容器 GenericApplicationContext tmpContainer = new GenericApplicationContext(); tmpContainer.RegisterObjectDefinition(SpringDemo.Pub.Pub.ServiceNameA, defiA); tmpContainer.RegisterObjectDefinition(SpringDemo.Pub.Pub.ServiceNameB, defiB); container = tmpContainer; } return container; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Spring.Core; using Spring.Context; using Spring.Context.Support; using Spring.Objects.Factory.Support; using SpringDemo.Lib; namespace SpringDemo.Lib.Container { /// <summary> /// 管理类 /// </summary> public partial class Container { private static IApplicationContext container = null; /// <summary> /// 自定义容器和组件注册 /// </summary> /// <returns></returns> public static IApplicationContext GetContainer() { if (container == null) { IObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory(); AbstractObjectDefinition defiA = factory.CreateObjectDefinition(SpringDemo.Pub.Pub.FullNameA, null, AppDomain.CurrentDomain); AbstractObjectDefinition defiB = factory.CreateObjectDefinition(SpringDemo.Pub.Pub.FullNameB, null, AppDomain.CurrentDomain); //建立容器 GenericApplicationContext tmpContainer = new GenericApplicationContext(); tmpContainer.RegisterObjectDefinition(SpringDemo.Pub.Pub.ServiceNameA, defiA); tmpContainer.RegisterObjectDefinition(SpringDemo.Pub.Pub.ServiceNameB, defiB); container = tmpContainer; } return container; } } }
<?xml version="1.0"?> <configuration> <configSections> <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://FirstSpringNetApp/FirstSpringNetApp/Objects.xml"/>--> <resource uri="config://spring/objects" /> </context> <objects xmlns="http://www.springframework.net"> <object id="SpringDemo.Lib.Oracle.OracleDatabase" type="SpringDemo.Lib.Oracle.OracleDatabase, SpringDemo.Lib.Oracle" singleton="false" /> <object id="SpringDemo.Lib.Sql.SqlDatabase" type="SpringDemo.Lib.Sql.SqlDatabase, SpringDemo.Lib.Sql" singleton="false" /> </objects> </spring> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SpringDemo.Lib; using Spring.Core; using Spring.Context; using Spring.Context.Support; namespace SpringDemo.Run { public partial class Helper { /// <summary> /// 根据配置文件里的服务名生成对象 /// </summary> public static void GetFrom_Config(string vServiceName) { IApplicationContext container = ContextRegistry.GetContext(); if (container != null) { IDatabase db = null; //db = container.GetObject(vServiceName) as IDatabase; db = container.GetObject<IDatabase>(vServiceName); ; if (db != null) { db.Select(".........."); } } } } }
标签:abs domain www sys 1.0 details bsp defaults 需要
原文地址:http://www.cnblogs.com/xdot/p/7337364.html