Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Objects/Factory/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17770
Modified Files:
WebObjectFactory.cs
Log Message:
added first WebObjectFactory tests
Index: WebObjectFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Objects/Factory/Support/WebObjectFactory.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** WebObjectFactory.cs 2 Aug 2007 20:49:50 -0000 1.7
--- WebObjectFactory.cs 15 Dec 2007 21:21:47 -0000 1.8
***************
*** 50,62 ****
public class WebObjectFactory : DefaultListableObjectFactory
{
! private readonly static ILog log = LogManager.GetLogger(typeof(WebObjectFactory));
! private const string OBJECTTABLEKEY = "spring.objects";
!
! /// <summary>
! /// Holds the virtual path this factory has been created from.
! /// </summary>
private string contextPath;
!
#region Constructor (s) / Destructor
--- 50,62 ----
public class WebObjectFactory : DefaultListableObjectFactory
{
! private readonly static ILog log = LogManager.GetLogger(typeof(WebObjectFactory));
! private const string OBJECTTABLEKEY = "spring.objects";
!
! /// <summary>
! /// Holds the virtual path this factory has been created from.
! /// </summary>
private string contextPath;
!
#region Constructor (s) / Destructor
***************
*** 65,69 ****
EnsureEventHandlersRegistered();
}
!
/// <summary>
/// Registers events handlers with <see cref="WebSupportModule"/> to ensure
--- 65,69 ----
EnsureEventHandlersRegistered();
}
!
/// <summary>
/// Registers events handlers with <see cref="WebSupportModule"/> to ensure
***************
*** 76,80 ****
VirtualEnvironment.EndSession += new VirtualEnvironment.SessionEventHandler(OnEndSession);
}
!
/// <summary>
/// Creates a new instance of the
--- 76,80 ----
VirtualEnvironment.EndSession += new VirtualEnvironment.SessionEventHandler(OnEndSession);
}
!
/// <summary>
/// Creates a new instance of the
***************
*** 82,87 ****
/// </summary>
/// <param name="contextPath">The virtual path resources will be relative resolved to.</param>
! /// <param name="caseSensitive">Flag specifying whether to make this object factory case sensitive or not.</param>
! public WebObjectFactory( string contextPath, bool caseSensitive )
: this(contextPath, caseSensitive, null)
{
--- 82,87 ----
/// </summary>
/// <param name="contextPath">The virtual path resources will be relative resolved to.</param>
! /// <param name="caseSensitive">Flag specifying whether to make this object factory case sensitive or not.</param>
! public WebObjectFactory(string contextPath, bool caseSensitive)
: this(contextPath, caseSensitive, null)
{
***************
*** 92,105 ****
/// <see cref="Spring.Objects.Factory.Support.WebObjectFactory"/> class.
/// </summary>
! /// <param name="contextPath">The virtual path resources will be relative resolved to.</param>
! /// <param name="caseSensitive">Flag specifying whether to make this object factory case sensitive or not.</param>
! /// <param name="parentFactory">
/// The parent object factory.
/// </param>
! public WebObjectFactory( string contextPath, bool caseSensitive, IObjectFactory parentFactory)
: base(caseSensitive, parentFactory)
{
this.contextPath = contextPath;
! InstantiationStrategy = new WebInstantiationStrategy();
}
--- 92,105 ----
/// <see cref="Spring.Objects.Factory.Support.WebObjectFactory"/> class.
/// </summary>
! /// <param name="contextPath">The virtual path resources will be relative resolved to.</param>
! /// <param name="caseSensitive">Flag specifying whether to make this object factory case sensitive or not.</param>
! /// <param name="parentFactory">
/// The parent object factory.
/// </param>
! public WebObjectFactory(string contextPath, bool caseSensitive, IObjectFactory parentFactory)
: base(caseSensitive, parentFactory)
{
this.contextPath = contextPath;
! InstantiationStrategy = new WebInstantiationStrategy();
}
***************
*** 131,135 ****
objecttable = new Hashtable();
this.Context.Items[OBJECTTABLEKEY] = objecttable;
! }
}
return objecttable;
--- 131,135 ----
objecttable = new Hashtable();
this.Context.Items[OBJECTTABLEKEY] = objecttable;
! }
}
return objecttable;
***************
*** 144,158 ****
get
{
! IDictionary objecttable = null;
! if ( (Context != null) && (Context.Session != null))
! {
! objecttable = Context.Session[OBJECTTABLEKEY] as IDictionary;
! if (objecttable == null)
! {
! objecttable = new Hashtable();
! Context.Session[OBJECTTABLEKEY] = objecttable;
! }
! }
! return objecttable;
}
}
--- 144,158 ----
get
{
! IDictionary objecttable = null;
! if ((Context != null) && (Context.Session != null))
! {
! objecttable = Context.Session[OBJECTTABLEKEY] as IDictionary;
! if (objecttable == null)
! {
! objecttable = new Hashtable();
! Context.Session[OBJECTTABLEKEY] = objecttable;
! }
! }
! return objecttable;
}
}
***************
*** 220,232 ****
{
object instance;
! ObjectScope scope = ((IWebObjectDefinition) objectDefinition).Scope;
if (scope == ObjectScope.Application)
{
! return base.CreateAndCacheSingletonInstance(objectName, objectDefinition, arguments);
! // base.AddSingleton(objectName, TemporarySingletonPlaceHolder);
! // // eager caching (last parameter) should be allowed in order to resolve circular references
! // instance = CreateObject(objectName, objectDefinition, arguments, true);
! // base.AddSingleton(objectName, instance);
}
else if (scope == ObjectScope.Request)
--- 220,232 ----
{
object instance;
! ObjectScope scope = ((IWebObjectDefinition)objectDefinition).Scope;
if (scope == ObjectScope.Application)
{
! return base.CreateAndCacheSingletonInstance(objectName, objectDefinition, arguments);
! // base.AddSingleton(objectName, TemporarySingletonPlaceHolder);
! // // eager caching (last parameter) should be allowed in order to resolve circular references
! // instance = CreateObject(objectName, objectDefinition, arguments, true);
! // base.AddSingleton(objectName, instance);
}
else if (scope == ObjectScope.Request)
***************
*** 239,248 ****
else if (scope == ObjectScope.Session)
{
! IDictionary sessionCache = this.Session;
! if (sessionCache == null)
! {
! throw ConfigurationUtils.CreateConfigurationException(
! "'session'-scoped objects require SessionState to be enabled.");
! }
string key = GetObjectKey(objectName);
sessionCache[key] = TemporarySingletonPlaceHolder;
--- 239,248 ----
else if (scope == ObjectScope.Session)
{
! IDictionary sessionCache = this.Session;
! if (sessionCache == null)
! {
! throw ConfigurationUtils.CreateConfigurationException(
! "'session'-scoped objects require SessionState to be enabled.");
! }
string key = GetObjectKey(objectName);
sessionCache[key] = TemporarySingletonPlaceHolder;
***************
*** 269,273 ****
}
! /// <summary>
/// Injects dependencies into the supplied <paramref name="target"/> instance
/// using the named object definition.
--- 269,273 ----
}
! /// <summary>
/// Injects dependencies into the supplied <paramref name="target"/> instance
/// using the named object definition.
***************
*** 282,352 ****
/// <seealso cref="Spring.Objects.Factory.IObjectFactory.ConfigureObject(object, string)"/>
public override object ConfigureObject(object target, string name)
! {
// always configure object relative to contextPath
! using( new HttpContextSwitch( contextPath ))
{
return base.ConfigureObject(target, name);
}
! }
! /// <summary>
! /// Disposes all 'request'-scoped objects at the end of each Request
! /// </summary>
! private static void OnEndRequest(HttpContext context)
! {
! IDictionary items = context.Items[OBJECTTABLEKEY] as IDictionary;
! if(items != null)
! {
! log.Debug("disposing 'request'-scoped item cache");
! ArrayList keys = new ArrayList(items.Keys);
! for(int i=0;i<keys.Count;i++)
! {
! IDisposable d = items[keys[i]] as IDisposable;
! if (d != null)
! {
! d.Dispose();
! }
! }
! }
! }
!
! /// <summary>
! /// Disposes all 'session'-scoped objects at the end of a session
! /// </summary>
! private static void OnEndSession(HttpSessionState session, CacheItemRemovedReason reason)
! {
! IDictionary items = null;
! try
! {
! items = session[OBJECTTABLEKEY] as IDictionary;
! }
! catch
! {
// ignore exceptions while accessing session
! }
! if(items != null)
! {
! log.Debug("disposing 'session'-scoped item cache");
! object key = null;
! try
! {
! ArrayList keys = new ArrayList(items.Keys);
! for(int i=0;i<keys.Count;i++)
! {
! key = keys[i];
! IDisposable d = items[key] as IDisposable;
! if (d != null)
! {
! d.Dispose();
! }
! }
! }
! catch (Exception ex)
! {
! log.Fatal(string.Format("error during disposing session item with key '{0}'", key), ex);
! }
! }
! }
! }
}
\ No newline at end of file
--- 282,352 ----
/// <seealso cref="Spring.Objects.Factory.IObjectFactory.ConfigureObject(object, string)"/>
public override object ConfigureObject(object target, string name)
! {
// always configure object relative to contextPath
! using (new HttpContextSwitch(contextPath))
{
return base.ConfigureObject(target, name);
}
! }
! /// <summary>
! /// Disposes all 'request'-scoped objects at the end of each Request
! /// </summary>
! private static void OnEndRequest(HttpContext context)
! {
! IDictionary items = context.Items[OBJECTTABLEKEY] as IDictionary;
! if (items != null)
! {
! log.Debug("disposing 'request'-scoped item cache");
! ArrayList keys = new ArrayList(items.Keys);
! for (int i = 0; i < keys.Count; i++)
! {
! IDisposable d = items[keys[i]] as IDisposable;
! if (d != null)
! {
! d.Dispose();
! }
! }
! }
! }
!
! /// <summary>
! /// Disposes all 'session'-scoped objects at the end of a session
! /// </summary>
! private static void OnEndSession(HttpSessionState session, CacheItemRemovedReason reason)
! {
! IDictionary items = null;
! try
! {
! items = session[OBJECTTABLEKEY] as IDictionary;
! }
! catch
! {
// ignore exceptions while accessing session
! }
! if (items != null)
! {
! log.Debug("disposing 'session'-scoped item cache");
! object key = null;
! try
! {
! ArrayList keys = new ArrayList(items.Keys);
! for (int i = 0; i < keys.Count; i++)
! {
! key = keys[i];
! IDisposable d = items[key] as IDisposable;
! if (d != null)
! {
! d.Dispose();
! }
! }
! }
! catch (Exception ex)
! {
! log.Fatal(string.Format("error during disposing session item with key '{0}'", key), ex);
! }
! }
! }
! }
}
\ No newline at end of file
|