<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<section name="SpringOverrideProperty" type="System.Configuration.NameValueSectionHandler"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
<resource uri="assembly://SpringDao/SpringDao/spring_hibernate_dao.xml"/>
<resource uri="assembly://SpringDao/SpringDao/Controller.xml"></resource>
</context>
<objects xmlns="http://www.springframework.net"/>
</spring>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="ssCode" type="Model.SS_CODE,Model">
<property name="C_DATA" value="2"></property>
</object>
<object id="CodeController" type="Controllers.CodeController,NormalUniversity" singleton="false" autowire="byName" >
<property name="ssCode" ref="ssCode"></property>
</object>
</objects>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="DbProvider" type="SpringDao.SQLProvider, SpringDao">
<property name="ConnectionString" value="server=.\sql2k5;uid=sa;pwd=sa123;database=test;" />
</object>
<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider" />
<property name="MappingAssemblies">
<list>
<value>Model</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<entry key="show_sql" value="true" />
</dictionary>
</property>
</object>
<object id="HibernateTransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider" />
<property name="sessionFactory" ref="sessionFactory" />
</object>
<object id="TransactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
<property name="TransactionManager" ref="HibernateTransactionManager" />
<property name="TransactionAttributeSource">
<object type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data" />
</property>
</object>
<object id="DaoHelper" type="Dao.SS_CodeDao,Dao">
<property name="sessionFactory" ref="sessionFactory" />
</object>
</objects>
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web;
namespace SpringDao
{
public class ControllerFactory : IControllerFactory
{
private static DefaultControllerFactory defalutf = null;
public IController CreateController(RequestContext requestContext, string controllerName)
{
string controller = controllerName + "Controller";
IApplicationContext ctx = Container.GetContext();
if (ctx.ContainsObject(controller))
{
object controllerf = ctx.GetObject(controller);
return (IController)controllerf;
}
else
{
if (defalutf == null)
{
defalutf = new DefaultControllerFactory();
}
return defalutf.CreateController(requestContext, controllerName);
}
}
public void ReleaseController(IController controller)
{
IApplicationContext ctx = Container.GetContext();
if (!ctx.ContainsObject(controller.GetType().Name))
{
if (defalutf == null)
{
defalutf = new DefaultControllerFactory();
}
defalutf.ReleaseController(controller);
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using System.Collections;
namespace SpringDao
{
public class Container
{
/// <summary>
/// 获取应用程序上下文.
/// </summary>
/// <returns><see cref="IApplicationContext"/>应用程序上下文.</returns>
public static IApplicationContext GetContext()
{
if (FApplicationContext == null)
{
FApplicationContext = ContextRegistry.GetContext();
}
return FApplicationContext;
}
/// <summary>
/// 获取应用程序上下文.
/// </summary>
/// <param name="name"><see cref="IApplicationContext"/>应用程序上下文名称.</param>
/// <returns><see cref="IApplicationContext"/>应用程序上下文.</returns>
public static IApplicationContext GetContext(string name)
{
return ContextRegistry.GetContext(name);
}
/// <summary>
/// 获取对象.
/// </summary>
/// <typeparam name="T">对象的类型.</typeparam>
/// <param name="id">标识.</param>
/// <returns></returns>
public static T GetObject<T>(string id)
{
return (T)GetContext().GetObject(id);
}
/// <summary>
/// 获取对象类表.
/// </summary>
/// <typeparam name="T">对象的类型.</typeparam>
/// <returns></returns>
public static IList<T> GetObjects<T>()
{
IEnumerable items = GetContext().GetObjectsOfType(typeof(T));
IList<T> objects = new List<T>();
foreach (DictionaryEntry item in items)
{
objects.Add((T)item.Value);
}
return objects;
}
[ThreadStatic]
private static IApplicationContext FApplicationContext;
}
}
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model;
using NHibernate.Expression;
namespace Controllers
{
public class CodeController : BaseController<SS_CODE>
{
private SS_CODE ssCode { set; get; }
public ActionResult Index()
{
ssCode.C_DATA = "aaaa";
return base.Index1("~/Views/System/Code/Index.aspx");
}
}
}
<log4net>
<logger name="WebLogger">
<level Value="DEBUG"></level>
<appender-ref ref="LogFileAppender" />
<appender-ref ref="RollingLogFileAppender"></appender-ref>
</logger>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--日志文件名开头-->
<file value="App_Data\\Log.txt" />
<!--是否追加到文件-->
<appendToFile value="true" />
<!--混合使用日期和文件大小变换日志文件名-->
<rollingStyle value="Composite" />
<!--日期的格式-->
<datePattern value="yyyyMMdd" />
<!--最大变换数量-->
<maxSizeRollBackups value="10" />
<!--最大文件大小-->
<maximumFileSize value="1MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
{
if (lg.IsErrorEnabled)
{
lg.Error(this.GetType().ToString()+"xxxx李磊");
}
}