Removed:
experiments/ninject2/src/Ninject.Tests/ExtensionsForWeakReference.cs
Modified:
experiments/ninject2/src/Ninject.Tests/Integration/ActivationScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/ThreadScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj
experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
Log:
Modified:
experiments/ninject2/src/Ninject.Tests/Integration/ActivationScopeTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/ActivationScopeTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/ActivationScopeTests.cs
Fri Feb 20 06:42:13 2009
@@ -48,7 +48,9 @@
kernel.Bind<NotifiesWhenDisposed>().ToSelf();
var instance = scope.Get<NotifiesWhenDisposed>();
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
instance.IsDisposed.ShouldBeFalse();
}
Modified:
experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
Fri Feb 20 06:42:13 2009
@@ -38,7 +38,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeTrue();
}
@@ -77,7 +79,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeTrue();
}
@@ -116,7 +120,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeTrue();
}
@@ -155,7 +161,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeTrue();
}
Modified:
experiments/ninject2/src/Ninject.Tests/Integration/ThreadScopeTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Integration/ThreadScopeTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Integration/ThreadScopeTests.cs
Fri Feb 20 06:42:13 2009
@@ -75,7 +75,6 @@
ThreadStart callback = () => instance =
kernel.Get<NotifiesWhenDisposed>();
var thread = new Thread(callback);
- var threadReference = new WeakReference(thread);
thread.Start();
thread.Join();
@@ -83,8 +82,8 @@
thread = null;
GC.Collect();
+ GC.WaitForPendingFinalizers();
- threadReference.WaitUntilGarbageCollected();
cache.Prune();
instance.ShouldNotBeNull();
Modified:
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
Fri Feb 20 06:42:13 2009
@@ -37,7 +37,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeFalse();
}
@@ -65,7 +67,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeFalse();
}
@@ -93,7 +97,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeFalse();
}
@@ -121,7 +127,9 @@
var reference = new WeakReference(instance);
instance = null;
+
GC.Collect();
+ GC.WaitForPendingFinalizers();
reference.IsAlive.ShouldBeFalse();
}
Modified: experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj (original)
+++ experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj Fri Feb 20
06:42:13 2009
@@ -56,7 +56,6 @@
<Compile Include="Integration\ExternalInjectionTests.cs" />
<Compile Include="Fakes\NotifiesWhenDisposed.cs" />
<Compile Include="SpecExtensions.cs" />
- <Compile Include="ExtensionsForWeakReference.cs" />
<Compile Include="ExtensionsForIEnumerable.cs" />
<Compile Include="Integration\CircularDependenciesTests.cs" />
<Compile Include="Integration\TransientScopeTests.cs" />
Modified: experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs Fri Feb 20
06:42:13 2009
@@ -47,7 +47,7 @@
{
_entries = new Multimap<IBinding, CacheEntry>();
Pipeline = pipeline;
- cachePruner.Register(this);
+ cachePruner.Start(this);
}
/// <summary>
Modified:
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
(original)
+++
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
Fri Feb 20 06:42:13 2009
@@ -42,23 +42,34 @@
public override void Dispose(bool disposing)
{
if (disposing && !IsDisposed && _timer != null)
- {
- _timer.Change(Timeout.Infinite, Timeout.Infinite);
- _timer.Dispose();
- _timer = null;
- }
+ Stop();
+
base.Dispose(disposing);
}
/// <summary>
- /// Registers the specified cache for pruning.
+ /// Starts pruning the specified cache based on the rules of the pruner.
/// </summary>
/// <param name="cache">The cache that will be pruned.</param>
- public void Register(ICache cache)
+ public void Start(ICache cache)
{
+ if (_timer != null)
+ Stop();
+
Cache = cache;
_timer = new Timer(PruneCacheIfGarbageCollectorHasRun, null,
Settings.CachePruningIntervalMs, Timeout.Infinite);
+ }
+
+ /// <summary>
+ /// Stops pruning.
+ /// </summary>
+ public void Stop()
+ {
+ _timer.Change(Timeout.Infinite, Timeout.Infinite);
+ _timer.Dispose();
+ _timer = null;
+ Cache = null;
}
private void PruneCacheIfGarbageCollectorHasRun(object state)
Modified:
experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
(original)
+++ experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs Fri
Feb 20 06:42:13 2009
@@ -27,9 +27,14 @@
public interface ICachePruner : INinjectComponent
{
/// <summary>
- /// Registers the specified cache for pruning.
+ /// Starts pruning the specified cache based on the rules of the pruner.
/// </summary>
/// <param name="cache">The cache that will be pruned.</param>
- void Register(ICache cache);
+ void Start(ICache cache);
+
+ /// <summary>
+ /// Stops pruning.
+ /// </summary>
+ void Stop();
}
}