codesite...@google.com
unread,Feb 18, 2009, 11:12:30 PM2/18/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ninje...@googlegroups.com
Author: nkohari
Date: Wed Feb 18 20:10:57 2009
New Revision: 149
Added:
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionConstructorInjectorTests.cs
- copied, changed from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionMethodInjectorTests.cs
- copied, changed from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionPropertyInjectorTests.cs
- copied, changed from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionVoidMethodInjectorTests.cs
- copied, changed from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
- copied, changed from r148,
/experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
- copied, changed from r146,
/experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs
experiments/ninject2/src/Ninject/Injection/Expressions/
- copied from r145, /experiments/ninject2/src/Ninject/Injection/Linq/
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionConstructorInjector.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/ConstructorInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionInjectorFactory.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/InjectorFactory.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjector.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/MethodInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjectorBase.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/MethodInjectorBase.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionPropertyInjector.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/PropertyInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionVoidMethodInjector.cs
- copied, changed from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/VoidMethodInjector.cs
Removed:
experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
experiments/ninject2/src/Ninject/Infrastructure/IGarbageCollectionWatcher.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ConstructorInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/InjectorFactory.cs
experiments/ninject2/src/Ninject/Injection/Expressions/MethodInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/MethodInjectorBase.cs
experiments/ninject2/src/Ninject/Injection/Expressions/PropertyInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/VoidMethodInjector.cs
experiments/ninject2/src/Ninject/Injection/Linq/
Modified:
experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj
experiments/ninject2/src/Ninject.Tests/Unit/CacheTests.cs
experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs
experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
experiments/ninject2/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionBasedInjector.cs
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionHelper.cs
experiments/ninject2/src/Ninject/KernelBase.cs
experiments/ninject2/src/Ninject/Ninject.csproj
experiments/ninject2/src/Ninject/StandardKernel.cs
Log:
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 Wed Feb 18
20:10:57 2009
@@ -62,7 +62,7 @@
<Compile Include="Integration\TransientScopeTests.cs" />
<Compile Include="Integration\ThreadScopeTests.cs" />
<Compile Include="Integration\SpecialResolutionTests.cs" />
- <Compile Include="Unit\ConstructorInjectorTests.cs" />
+ <Compile Include="Unit\ExpressionConstructorInjectorTests.cs" />
<Compile Include="Integration\SingletonScopeTests.cs" />
<Compile Include="Integration\EnumerableDependenciesTests.cs" />
<Compile Include="Integration\ActivationScopeTests.cs" />
@@ -79,14 +79,14 @@
<Compile Include="Unit\DisposableStrategyTests.cs" />
<Compile Include="Unit\MethodInjectionStrategyTests.cs" />
<Compile Include="Unit\PipelineTests.cs" />
- <Compile Include="Unit\MethodInjectorTests.cs" />
+ <Compile Include="Unit\ExpressionMethodInjectorTests.cs" />
<Compile Include="Fakes\AbstractWeapon.cs" />
<Compile Include="Fakes\Shuriken.cs" />
<Compile Include="Unit\CacheTests.cs" />
<Compile Include="Integration\StandardKernelTests.cs" />
<Compile Include="Unit\ComponentContainerTests.cs" />
- <Compile Include="Unit\VoidMethodInjectorTests.cs" />
- <Compile Include="Unit\PropertyInjectorTests.cs" />
+ <Compile Include="Unit\ExpressionVoidMethodInjectorTests.cs" />
+ <Compile Include="Unit\ExpressionPropertyInjectorTests.cs" />
<Compile Include="Fakes\IWarrior.cs" />
<Compile Include="Fakes\Samurai.cs" />
<Compile Include="Fakes\Sword.cs" />
Modified: experiments/ninject2/src/Ninject.Tests/Unit/CacheTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/CacheTests.cs (original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/CacheTests.cs Wed Feb 18
20:10:57 2009
@@ -12,26 +12,16 @@
public class CacheContext
{
protected Mock<IPipeline> activatorMock;
- protected Mock<IGarbageCollectionWatcher> gcWatcherMock;
+ protected Mock<ICachePruner> cachePrunerMock;
protected Mock<IBinding> bindingMock;
protected Cache cache;
public CacheContext()
{
activatorMock = new Mock<IPipeline>();
- gcWatcherMock = new Mock<IGarbageCollectionWatcher>();
+ cachePrunerMock = new Mock<ICachePruner>();
bindingMock = new Mock<IBinding>();
- cache = new Cache(activatorMock.Object) { GCWatcher =
gcWatcherMock.Object };
- }
- }
-
- public class WhenCacheIsDisposed : CacheContext
- {
- [Fact]
- public void DisposesOfGCWatcher()
- {
- cache.Dispose();
- gcWatcherMock.Verify(x => x.Dispose());
+ cache = new Cache(activatorMock.Object, cachePrunerMock.Object);
}
}
Copied:
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionConstructorInjectorTests.cs
(from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs)
==============================================================================
---
/experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionConstructorInjectorTests.cs
Wed Feb 18 20:10:57 2009
@@ -1,24 +1,24 @@
using System;
using System.Reflection;
-using Ninject.Injection.Linq;
+using Ninject.Injection.Expressions;
using Ninject.Tests.Fakes;
using Xunit;
-namespace Ninject.Tests.Unit.ConstructorInjectorTests
+namespace Ninject.Tests.Unit.ExpressionConstructorInjectorTests
{
- public class ConstructorInjectorContext
+ public class ExpressionConstructorInjectorContext
{
protected ConstructorInfo constructor;
- protected ConstructorInjector injector;
+ protected ExpressionConstructorInjector injector;
- public ConstructorInjectorContext()
+ public ExpressionConstructorInjectorContext()
{
constructor = typeof(Samurai).GetConstructor(new[] { typeof(IWeapon) });
- injector = new ConstructorInjector(constructor);
+ injector = new ExpressionConstructorInjector(constructor);
}
}
- public class WhenConstructorInjectorIsCreated : ConstructorInjectorContext
+ public class WhenConstructorInjectorIsCreated :
ExpressionConstructorInjectorContext
{
[Fact]
public void CanGetCallback()
@@ -27,7 +27,7 @@
}
}
- public class WhenConstructorInjectorIsInvoked : ConstructorInjectorContext
+ public class WhenConstructorInjectorIsInvoked :
ExpressionConstructorInjectorContext
{
[Fact]
public void CallsConstructor()
Copied:
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionMethodInjectorTests.cs
(from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionMethodInjectorTests.cs
Wed Feb 18 20:10:57 2009
@@ -1,24 +1,24 @@
using System;
using System.Reflection;
-using Ninject.Injection.Linq;
+using Ninject.Injection.Expressions;
using Ninject.Tests.Fakes;
using Xunit;
-namespace Ninject.Tests.Unit.MethodInjectorTests
+namespace Ninject.Tests.Unit.ExpressionMethodInjectorTests
{
- public class MethodInjectorContext
+ public class ExpressionMethodInjectorContext
{
protected MethodInfo method;
- protected MethodInjector injector;
+ protected ExpressionMethodInjector injector;
- public MethodInjectorContext()
+ public ExpressionMethodInjectorContext()
{
method = typeof(Samurai).GetMethod("Attack");
- injector = new MethodInjector(method);
+ injector = new ExpressionMethodInjector(method);
}
}
- public class WhenMethodInjectorIsCreated : MethodInjectorContext
+ public class WhenMethodInjectorIsCreated : ExpressionMethodInjectorContext
{
[Fact]
public void CanGetCallback()
@@ -27,7 +27,7 @@
}
}
- public class WhenMethodInjectorIsInvoked : MethodInjectorContext
+ public class WhenMethodInjectorIsInvoked : ExpressionMethodInjectorContext
{
[Fact]
public void CallsMethod()
Copied:
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionPropertyInjectorTests.cs
(from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionPropertyInjectorTests.cs
Wed Feb 18 20:10:57 2009
@@ -1,24 +1,24 @@
using System;
using System.Reflection;
-using Ninject.Injection.Linq;
+using Ninject.Injection.Expressions;
using Ninject.Tests.Fakes;
using Xunit;
-namespace Ninject.Tests.Unit.PropertyInjectorTests
+namespace Ninject.Tests.Unit.ExpressionPropertyInjectorTests
{
- public class PropertyInjectorContext
+ public class ExpressionPropertyInjectorContext
{
protected PropertyInfo property;
- protected PropertyInjector injector;
+ protected ExpressionPropertyInjector injector;
- public PropertyInjectorContext()
+ public ExpressionPropertyInjectorContext()
{
property = typeof(Samurai).GetProperty("Weapon");
- injector = new PropertyInjector(property);
+ injector = new ExpressionPropertyInjector(property);
}
}
- public class WhenPropertyInjectorIsCreated : PropertyInjectorContext
+ public class WhenPropertyInjectorIsCreated :
ExpressionPropertyInjectorContext
{
[Fact]
public void CanGetCallback()
@@ -27,7 +27,7 @@
}
}
- public class WhenPropertyInjectorIsInvoked : PropertyInjectorContext
+ public class WhenPropertyInjectorIsInvoked :
ExpressionPropertyInjectorContext
{
[Fact]
public void SetsPropertyValue()
Copied:
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionVoidMethodInjectorTests.cs
(from r146,
/experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/ExpressionVoidMethodInjectorTests.cs
Wed Feb 18 20:10:57 2009
@@ -1,24 +1,24 @@
using System;
using System.Reflection;
-using Ninject.Injection.Linq;
+using Ninject.Injection.Expressions;
using Ninject.Tests.Fakes;
using Xunit;
-namespace Ninject.Tests.Unit.VoidMethodInjectorTests
+namespace Ninject.Tests.Unit.ExpressionVoidMethodInjectorTests
{
- public class VoidMethodInjectorContext
+ public class ExpressionVoidMethodInjectorContext
{
protected MethodInfo method;
- protected VoidMethodInjector injector;
+ protected ExpressionVoidMethodInjector injector;
- public VoidMethodInjectorContext()
+ public ExpressionVoidMethodInjectorContext()
{
method = typeof(Samurai).GetMethod("SetName");
- injector = new VoidMethodInjector(method);
+ injector = new ExpressionVoidMethodInjector(method);
}
}
- public class WhenVoidMethodInjectorIsCreated : VoidMethodInjectorContext
+ public class WhenVoidMethodInjectorIsCreated :
ExpressionVoidMethodInjectorContext
{
[Fact]
public void CanGetCallback()
@@ -27,7 +27,7 @@
}
}
- public class WhenVoidMethodInjectorIsInvoked : VoidMethodInjectorContext
+ public class WhenVoidMethodInjectorIsInvoked :
ExpressionVoidMethodInjectorContext
{
[Fact]
public void CallsMethod()
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 Wed Feb 18
20:10:57 2009
@@ -31,54 +31,23 @@
/// </summary>
public class Cache : NinjectComponent, ICache
{
- private readonly object _mutex = new object();
private readonly Multimap<IBinding, CacheEntry> _entries = new
Multimap<IBinding, CacheEntry>();
- private IGarbageCollectionWatcher _gcWatcher;
- private bool _initialized;
-
/// <summary>
/// Gets or sets the pipeline component.
/// </summary>
public IPipeline Pipeline { get; private set; }
/// <summary>
- /// Gets or sets the garbage collection watcher.
- /// </summary>
- public IGarbageCollectionWatcher GCWatcher
- {
- get
- {
- if (_gcWatcher == null) _gcWatcher = new
GarbageCollectionWatcher(Settings.CachePruningIntervalMs);
- return _gcWatcher;
- }
- set
- {
- _gcWatcher = value;
- }
- }
-
- /// <summary>
/// Initializes a new instance of the <see cref="Cache"/> class.
/// </summary>
/// <param name="pipeline">The pipeline component.</param>
- public Cache(IPipeline pipeline)
+ /// <param name="cachePruner">The cache pruner component.</param>
+ public Cache(IPipeline pipeline, ICachePruner cachePruner)
{
- Pipeline = pipeline;
_entries = new Multimap<IBinding, CacheEntry>();
- }
-
- /// <summary>
- /// Releases resources held by the object.
- /// </summary>
- public override void Dispose()
- {
- if (_initialized)
- GCWatcher.GarbageCollected -= OnGarbageCollected;
-
- GCWatcher.Dispose();
-
- base.Dispose();
+ Pipeline = pipeline;
+ cachePruner.Register(this);
}
/// <summary>
@@ -87,14 +56,8 @@
/// <param name="context">The context to store.</param>
public void Remember(IContext context)
{
- lock (_mutex)
+ lock (_entries)
{
- if (!_initialized)
- {
- GCWatcher.GarbageCollected += OnGarbageCollected;
- _initialized = true;
- }
-
var entry = new CacheEntry(context);
_entries[context.Binding].Add(entry);
@@ -112,7 +75,7 @@
/// <returns>The instance for re-use, or <see langword="null"/> if none
has been stored.</returns>
public object TryGet(IContext context)
{
- lock (_mutex)
+ lock (_entries)
{
Prune();
@@ -144,7 +107,7 @@
/// </summary>
public void Prune()
{
- lock (_mutex)
+ lock (_entries)
{
foreach (IBinding binding in _entries.Keys)
_entries[binding].Where(e => !e.Scope.IsAlive).ToArray().Map(Forget);
@@ -153,16 +116,11 @@
private void Forget(CacheEntry entry)
{
- lock (_mutex)
+ lock (_entries)
{
Pipeline.Deactivate(entry.Context);
_entries[entry.Context.Binding].Remove(entry);
}
- }
-
- private void OnGarbageCollected(object sender, EventArgs e)
- {
- Prune();
}
private class CacheEntry
Copied:
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
(from r148,
/experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs)
==============================================================================
---
/experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
(original)
+++
experiments/ninject2/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
Wed Feb 18 20:10:57 2009
@@ -17,59 +17,59 @@
#region Using Directives
using System;
using System.Threading;
-using Ninject.Infrastructure.Disposal;
-using Ninject.Infrastructure.Language;
+using Ninject.Components;
#endregion
-namespace Ninject.Infrastructure
+namespace Ninject.Activation.Caching
{
/// <summary>
- /// Uses a <see cref="Timer"/> to poll the garbage collector to see if it
has run.
+ /// Uses a <see cref="Timer"/> and some <see cref="WeakReference"/> magic
to poll
+ /// the garbage collector to see if it has run.
/// </summary>
- public class GarbageCollectionWatcher : DisposableObject,
IGarbageCollectionWatcher
+ public class GarbageCollectionCachePruner : NinjectComponent, ICachePruner
{
private readonly WeakReference _indicator = new WeakReference(new
object());
private Timer _timer;
/// <summary>
- /// Occurs when the garbage collector has run. Since the GC operation
may be concurrent,
- /// collection may not be complete when this event is fired.
+ /// Gets the cache that is being pruned.
/// </summary>
- public event EventHandler GarbageCollected;
-
- /// <summary>
- /// Initializes a new instance of the <see
cref="GarbageCollectionWatcher"/> class.
- /// </summary>
- /// <param name="pollIntervalMs">The interval at which to poll the
garbage collector.</param>
- public GarbageCollectionWatcher(int pollIntervalMs)
- {
- _timer = new Timer(RaiseEventIfGarbageCollectorHasRun, null,
pollIntervalMs, pollIntervalMs);
- }
+ public ICache Cache { get; private set; }
/// <summary>
/// Releases resources held by the object.
/// </summary>
- public override void Dispose()
+ public override void Dispose(bool disposing)
{
- if (_timer != null)
+ if (disposing && !IsDisposed && _timer != null)
{
_timer.Change(Timeout.Infinite, Timeout.Infinite);
_timer.Dispose();
_timer = null;
}
- GarbageCollected = null;
+ base.Dispose(disposing);
+ }
- base.Dispose();
+ /// <summary>
+ /// Registers the specified cache for pruning.
+ /// </summary>
+ /// <param name="cache">The cache that will be pruned.</param>
+ public void Register(ICache cache)
+ {
+ Cache = cache;
+ _timer = new Timer(PruneCacheIfGarbageCollectorHasRun, null,
Settings.CachePruningIntervalMs, Timeout.Infinite);
}
- private void RaiseEventIfGarbageCollectorHasRun(object state)
+ private void PruneCacheIfGarbageCollectorHasRun(object state)
{
if (_indicator.IsAlive)
return;
- GarbageCollected.Raise(this, EventArgs.Empty);
+ Cache.Prune();
_indicator.Target = new object();
+
+ _timer.Change(Settings.CachePruningIntervalMs, Timeout.Infinite);
}
}
}
Copied: experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
(from r146, /experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs
(original)
+++ experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs Wed
Feb 18 20:10:57 2009
@@ -22,26 +22,14 @@
namespace Ninject.Activation.Caching
{
/// <summary>
- /// Tracks instances for re-use in certain scopes.
+ /// Prunes instances from an <see cref="ICache"/> based on environmental
information.
/// </summary>
- public interface ICache : INinjectComponent
+ public interface ICachePruner : INinjectComponent
{
/// <summary>
- /// Stores the specified context in the cache.
+ /// Registers the specified cache for pruning.
/// </summary>
- /// <param name="context">The context to store.</param>
- void Remember(IContext context);
-
- /// <summary>
- /// Tries to retrieve an instance to re-use in the specified context.
- /// </summary>
- /// <param name="context">The context that is being activated.</param>
- /// <returns>The instance for re-use, or <see langword="null"/> if none
has been stored.</returns>
- object TryGet(IContext context);
-
- /// <summary>
- /// Removes instances from the cache which should no longer be re-used.
- /// </summary>
- void Prune();
+ /// <param name="cache">The cache that will be pruned.</param>
+ void Register(ICache cache);
}
}
Modified: experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
(original)
+++ experiments/ninject2/src/Ninject/Components/ComponentContainer.cs Wed
Feb 18 20:10:57 2009
@@ -43,15 +43,18 @@
/// <summary>
/// Releases resources held by the object.
/// </summary>
- public override void Dispose()
+ public override void Dispose(bool disposing)
{
- foreach (INinjectComponent instance in _instances.Values)
- instance.Dispose();
+ if (disposing && !IsDisposed)
+ {
+ foreach (INinjectComponent instance in _instances.Values)
+ instance.Dispose();
- _mappings.Clear();
- _instances.Clear();
+ _mappings.Clear();
+ _instances.Clear();
+ }
- base.Dispose();
+ base.Dispose(disposing);
}
/// <summary>
Modified:
experiments/ninject2/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
(original)
+++
experiments/ninject2/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
Wed Feb 18 20:10:57 2009
@@ -32,13 +32,21 @@
public bool IsDisposed { get; private set; }
/// <summary>
+ /// Performs application-defined tasks associated with freeing,
releasing, or resetting unmanaged resources.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ /// <summary>
/// Releases resources held by the object.
/// </summary>
- public virtual void Dispose()
+ public virtual void Dispose(bool disposing)
{
lock (this)
{
- if (!IsDisposed)
+ if (disposing && !IsDisposed)
{
Disposed.Raise(this, EventArgs.Empty);
Disposed = null;
@@ -53,7 +61,7 @@
/// </summary>
~DisposableObject()
{
- Dispose();
+ Dispose(false);
}
/// <summary>
Modified:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionBasedInjector.cs
==============================================================================
---
/experiments/ninject2/src/Ninject/Injection/Linq/ExpressionBasedInjector.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionBasedInjector.cs
Wed Feb 18 20:10:57 2009
@@ -20,7 +20,7 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// An injector that uses a delegate generated from an expression tree to
inject values.
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionConstructorInjector.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/ConstructorInjector.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/ConstructorInjector.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionConstructorInjector.cs
Wed Feb 18 20:10:57 2009
@@ -21,18 +21,18 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// An expression-based injector that injects values into a constructor.
/// </summary>
- public class ConstructorInjector :
ExpressionBasedInjector<ConstructorInfo, Func<object[], object>>,
IConstructorInjector
+ public class ExpressionConstructorInjector :
ExpressionBasedInjector<ConstructorInfo, Func<object[], object>>,
IConstructorInjector
{
/// <summary>
- /// Initializes a new instance of the <see cref="ConstructorInjector"/>
class.
+ /// Initializes a new instance of the <see
cref="ExpressionConstructorInjector"/> class.
/// </summary>
/// <param name="constructor">The constructor.</param>
- public ConstructorInjector(ConstructorInfo constructor) :
base(constructor) { }
+ public ExpressionConstructorInjector(ConstructorInfo constructor) :
base(constructor) { }
/// <summary>
/// Calls the associated constructor, injecting the specified values.
Modified:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionHelper.cs
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/ExpressionHelper.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionHelper.cs
Wed Feb 18 20:10:57 2009
@@ -21,7 +21,7 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
internal static class ExpressionHelper
{
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionInjectorFactory.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/InjectorFactory.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/InjectorFactory.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionInjectorFactory.cs
Wed Feb 18 20:10:57 2009
@@ -20,14 +20,15 @@
using System.Reflection;
using Ninject.Components;
using Ninject.Infrastructure.Language;
+using Ninject.Injection.Expressions;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// Creates expression-based injectors from members.
/// </summary>
- public class InjectorFactory : NinjectComponent, IInjectorFactory
+ public class ExpressionInjectorFactory : NinjectComponent,
IInjectorFactory
{
private readonly Dictionary<ConstructorInfo, IConstructorInjector>
_constructorInjectors = new Dictionary<ConstructorInfo,
IConstructorInjector>();
private readonly Dictionary<MethodInfo, IMethodInjector>
_methodInjectors = new Dictionary<MethodInfo, IMethodInjector>();
@@ -40,7 +41,7 @@
/// <returns>The created injector.</returns>
public IConstructorInjector GetConstructorInjector(ConstructorInfo
constructor)
{
- return _constructorInjectors.GetOrAddNew(constructor, c => new
ConstructorInjector(c));
+ return _constructorInjectors.GetOrAddNew(constructor, c => new
ExpressionConstructorInjector(c));
}
/// <summary>
@@ -50,7 +51,7 @@
/// <returns>The created injector.</returns>
public IMethodInjector GetMethodInjector(MethodInfo method)
{
- return _methodInjectors.GetOrAddNew(method, m => method.ReturnType ==
typeof(void) ? (IMethodInjector)new VoidMethodInjector(m) :
(IMethodInjector)new MethodInjector(m));
+ return _methodInjectors.GetOrAddNew(method, m => method.ReturnType ==
typeof(void) ? (IMethodInjector)new ExpressionVoidMethodInjector(m) :
(IMethodInjector)new ExpressionMethodInjector(m));
}
/// <summary>
@@ -60,7 +61,7 @@
/// <returns>The created injector.</returns>
public IPropertyInjector GetPropertyInjector(PropertyInfo property)
{
- return _propertyInjectors.GetOrAddNew(property, p => new
PropertyInjector(p));
+ return _propertyInjectors.GetOrAddNew(property, p => new
ExpressionPropertyInjector(p));
}
}
}
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjector.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/MethodInjector.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/MethodInjector.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjector.cs
Wed Feb 18 20:10:57 2009
@@ -19,18 +19,18 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// An injector that injects values into methods.
/// </summary>
- public class MethodInjector : MethodInjectorBase<Func<object, object[],
object>>
+ public class ExpressionMethodInjector :
ExpressionMethodInjectorBase<Func<object, object[], object>>
{
/// <summary>
- /// Initializes a new instance of the <see cref="MethodInjector"/> class.
+ /// Initializes a new instance of the <see
cref="ExpressionMethodInjector"/> class.
/// </summary>
/// <param name="method">The method that will be injected.</param>
- public MethodInjector(MethodInfo method) : base(method) { }
+ public ExpressionMethodInjector(MethodInfo method) : base(method) { }
/// <summary>
/// Calls the associated method, injecting the specified values.
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjectorBase.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/MethodInjectorBase.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/MethodInjectorBase.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionMethodInjectorBase.cs
Wed Feb 18 20:10:57 2009
@@ -21,19 +21,19 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// An expression-based injector that can inject values into a
constructor or method.
/// </summary>
/// <typeparam name="TDelegate">The type of delegate resulting from the
expression tree.</typeparam>
- public abstract class MethodInjectorBase<TDelegate> :
ExpressionBasedInjector<MethodInfo, TDelegate>, IMethodInjector
+ public abstract class ExpressionMethodInjectorBase<TDelegate> :
ExpressionBasedInjector<MethodInfo, TDelegate>, IMethodInjector
{
/// <summary>
- /// Initializes a new instance of the <see
cref="MethodInjectorBase<TDelegate>"/> class.
+ /// Initializes a new instance of the <see
cref="ExpressionMethodInjectorBase{TDelegate}"/> class.
/// </summary>
/// <param name="method">The method that will be injected.</param>
- protected MethodInjectorBase(MethodInfo method) : base(method) { }
+ protected ExpressionMethodInjectorBase(MethodInfo method) : base(method)
{ }
/// <summary>
/// Calls the associated method, injecting the specified values.
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionPropertyInjector.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/PropertyInjector.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/PropertyInjector.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionPropertyInjector.cs
Wed Feb 18 20:10:57 2009
@@ -20,18 +20,18 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// An injector that injects values into a property.
/// </summary>
- public class PropertyInjector : ExpressionBasedInjector<PropertyInfo,
Action<object, object>>, IPropertyInjector
+ public class ExpressionPropertyInjector :
ExpressionBasedInjector<PropertyInfo, Action<object, object>>,
IPropertyInjector
{
/// <summary>
- /// Initializes a new instance of the <see cref="PropertyInjector"/>
class.
+ /// Initializes a new instance of the <see
cref="ExpressionPropertyInjector"/> class.
/// </summary>
/// <param name="property">The property that will be injected.</param>
- public PropertyInjector(PropertyInfo property) : base(property) { }
+ public ExpressionPropertyInjector(PropertyInfo property) :
base(property) { }
/// <summary>
/// Injects the specified value into the property.
Copied:
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionVoidMethodInjector.cs
(from r145,
/experiments/ninject2/src/Ninject/Injection/Linq/VoidMethodInjector.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Injection/Linq/VoidMethodInjector.cs
(original)
+++
experiments/ninject2/src/Ninject/Injection/Expressions/ExpressionVoidMethodInjector.cs
Wed Feb 18 20:10:57 2009
@@ -19,18 +19,18 @@
using System.Reflection;
#endregion
-namespace Ninject.Injection.Linq
+namespace Ninject.Injection.Expressions
{
/// <summary>
/// A method injector that injects methods that return <see type="void"/>.
/// </summary>
- public class VoidMethodInjector : MethodInjectorBase<Action<object,
object[]>>
+ public class ExpressionVoidMethodInjector :
ExpressionMethodInjectorBase<Action<object, object[]>>
{
/// <summary>
- /// Initializes a new instance of the <see cref="VoidMethodInjector"/>
class.
+ /// Initializes a new instance of the <see
cref="ExpressionVoidMethodInjector"/> class.
/// </summary>
/// <param name="method">The method that will be injected.</param>
- public VoidMethodInjector(MethodInfo method) : base(method) { }
+ public ExpressionVoidMethodInjector(MethodInfo method) : base(method) { }
/// <summary>
/// Calls the associated method, injecting the specified values.
Modified: experiments/ninject2/src/Ninject/KernelBase.cs
==============================================================================
--- experiments/ninject2/src/Ninject/KernelBase.cs (original)
+++ experiments/ninject2/src/Ninject/KernelBase.cs Wed Feb 18 20:10:57 2009
@@ -118,10 +118,12 @@
/// <summary>
/// Releases resources held by the object.
/// </summary>
- public override void Dispose()
+ public override void Dispose(bool disposing)
{
- if (Components != null) Components.Dispose();
- base.Dispose();
+ if (disposing && !IsDisposed && Components != null)
+ Components.Dispose();
+
+ base.Dispose(disposing);
}
/// <summary>
Modified: experiments/ninject2/src/Ninject/Ninject.csproj
==============================================================================
--- experiments/ninject2/src/Ninject/Ninject.csproj (original)
+++ experiments/ninject2/src/Ninject/Ninject.csproj Wed Feb 18 20:10:57 2009
@@ -58,16 +58,14 @@
<Compile Include="Activation\Caching\Cache.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Activation\Caching\ICachePruner.cs" />
<Compile Include="Attributes\OptionalAttribute.cs" />
- <Compile Include="Infrastructure\GarbageCollectionWatcher.cs">
+ <Compile Include="Activation\Caching\GarbageCollectionCachePruner.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Activation\Caching\ICache.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Infrastructure\IGarbageCollectionWatcher.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Activation\Context.cs">
<SubType>Code</SubType>
</Compile>
@@ -113,7 +111,7 @@
<Compile Include="Infrastructure\Introspection\ExceptionFormatter.cs"
/>
<Compile Include="Infrastructure\Introspection\FormatExtensions.cs" />
<Compile Include="Infrastructure\Language\ExtensionsForIDictionary.cs"
/>
- <Compile Include="Injection\Linq\ExpressionHelper.cs" />
+ <Compile Include="Injection\Expressions\ExpressionHelper.cs" />
<Compile Include="Syntax\ModuleLoadExtensions.cs" />
<Compile Include="Events\BindingEventArgs.cs" />
<Compile Include="Events\ModuleEventArgs.cs" />
@@ -132,8 +130,8 @@
<Compile
Include="Infrastructure\Language\ExtensionsForEventHandler.cs" />
<Compile Include="Syntax\IResolutionRoot.cs" />
<Compile Include="Activation\Scope\ActivationScope.cs" />
- <Compile Include="Injection\Linq\MethodInjectorBase.cs" />
- <Compile Include="Injection\Linq\VoidMethodInjector.cs" />
+ <Compile
Include="Injection\Expressions\ExpressionMethodInjectorBase.cs" />
+ <Compile
Include="Injection\Expressions\ExpressionVoidMethodInjector.cs" />
<Compile Include="NinjectSettings.cs" />
<Compile Include="Activation\Providers\StandardProvider.cs" />
<Compile Include="Activation\Provider.cs" />
@@ -145,12 +143,12 @@
<Compile Include="Components\IComponentContainer.cs" />
<Compile Include="Syntax\IBindingRoot.cs" />
<Compile Include="Activation\Providers\CallbackProvider.cs" />
- <Compile Include="Injection\Linq\InjectorFactory.cs" />
+ <Compile Include="Injection\Expressions\ExpressionInjectorFactory.cs"
/>
<Compile Include="Injection\IInjectorFactory.cs" />
- <Compile Include="Injection\Linq\ConstructorInjector.cs" />
- <Compile Include="Injection\Linq\MethodInjector.cs" />
- <Compile Include="Injection\Linq\ExpressionBasedInjector.cs" />
- <Compile Include="Injection\Linq\PropertyInjector.cs" />
+ <Compile
Include="Injection\Expressions\ExpressionConstructorInjector.cs" />
+ <Compile Include="Injection\Expressions\ExpressionMethodInjector.cs" />
+ <Compile Include="Injection\Expressions\ExpressionBasedInjector.cs" />
+ <Compile Include="Injection\Expressions\ExpressionPropertyInjector.cs"
/>
<Compile Include="Injection\IConstructorInjector.cs" />
<Compile Include="Injection\IMethodInjector.cs" />
<Compile Include="Injection\IPropertyInjector.cs" />
Modified: experiments/ninject2/src/Ninject/StandardKernel.cs
==============================================================================
--- experiments/ninject2/src/Ninject/StandardKernel.cs (original)
+++ experiments/ninject2/src/Ninject/StandardKernel.cs Wed Feb 18 20:10:57
2009
@@ -21,7 +21,7 @@
using Ninject.Activation.Strategies;
using Ninject.Infrastructure;
using Ninject.Injection;
-using Ninject.Injection.Linq;
+using Ninject.Injection.Expressions;
using Ninject.Modules;
using Ninject.Planning;
using Ninject.Planning.Strategies;
@@ -72,8 +72,9 @@
Components.Add<IActivationStrategy, BindingActionStrategy>();
Components.Add<IActivationStrategy, DisposableStrategy>();
- Components.Add<IInjectorFactory, InjectorFactory>();
+ Components.Add<IInjectorFactory, ExpressionInjectorFactory>();
Components.Add<ICache, Cache>();
+ Components.Add<ICachePruner, GarbageCollectionCachePruner>();
#if !SILVERLIGHT
Components.Add<IModuleLoader, ModuleLoader>();