[ninject commit] r146 - in experiments/ninject2/src: Ninject Ninject.Tests Ninject.Tests/Integration Ninject.Tests...

6 views
Skip to first unread message

codesite...@google.com

unread,
Feb 18, 2009, 12:54:55 AM2/18/09
to ninje...@googlegroups.com
Author: nkohari
Date: Tue Feb 17 21:51:04 2009
New Revision: 146

Added:
experiments/ninject2/src/Ninject.Tests/ExtensionsForWeakReference.cs
- copied, changed from r142,
/experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
- copied, changed from r142,
/experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
experiments/ninject2/src/Ninject.Tests/SpecExtensions.cs
- copied, changed from r142,
/experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs
experiments/ninject2/src/Ninject/Attributes/OptionalAttribute.cs
- copied, changed from r144,
/experiments/ninject2/src/Ninject/Attributes/InjectAttribute.cs

experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
- copied, changed from r144,
/experiments/ninject2/src/Ninject/Activation/Caching/CachePruner.cs

experiments/ninject2/src/Ninject/Infrastructure/IGarbageCollectionWatcher.cs
- copied, changed from r144,
/experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
experiments/ninject2/src/Ninject/Infrastructure/Introspection/

experiments/ninject2/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
- copied, changed from r144,
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs

experiments/ninject2/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
- copied, changed from r144,
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs
Removed:
experiments/ninject2/src/Ninject.Tests/Unit/CachePrunerTests.cs
experiments/ninject2/src/Ninject/Activation/Caching/CachePruner.cs
experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs

experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForIList.cs
experiments/ninject2/src/Ninject/Infrastructure/Tracing/
Modified:

experiments/ninject2/src/Ninject.Tests/Integration/ActivationScopeTests.cs

experiments/ninject2/src/Ninject.Tests/Integration/CircularDependenciesTests.cs

experiments/ninject2/src/Ninject.Tests/Integration/EnumerableDependenciesTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs

experiments/ninject2/src/Ninject.Tests/Integration/SpecialResolutionTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/StandardKernelTests.cs
experiments/ninject2/src/Ninject.Tests/Integration/ThreadScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Ninject.Tests.csproj
experiments/ninject2/src/Ninject.Tests/Unit/ActivationScopeTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/BindingActionStrategyTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/CacheTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/CallbackProviderTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ComponentContainerTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ConstantProviderTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/DisposableStrategyTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/InitializableStrategyTests.cs

experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectionDirectiveBaseTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/NamedAttributeTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/PipelineTests.cs

experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectionDirectiveTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/StartableStrategyTests.cs
experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
experiments/ninject2/src/Ninject/Activation/Caching/Cache.cs
experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs
experiments/ninject2/src/Ninject/Activation/Context.cs
experiments/ninject2/src/Ninject/Activation/Hooks/ContextHook.cs
experiments/ninject2/src/Ninject/Activation/IContext.cs
experiments/ninject2/src/Ninject/Activation/IRequest.cs
experiments/ninject2/src/Ninject/Activation/Providers/StandardProvider.cs
experiments/ninject2/src/Ninject/Activation/Request.cs
experiments/ninject2/src/Ninject/Activation/Scope/ActivationScope.cs
experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
experiments/ninject2/src/Ninject/Components/IComponentContainer.cs
experiments/ninject2/src/Ninject/Components/INinjectComponent.cs
experiments/ninject2/src/Ninject/Components/NinjectComponent.cs
experiments/ninject2/src/Ninject/INinjectSettings.cs
experiments/ninject2/src/Ninject/KernelBase.cs
experiments/ninject2/src/Ninject/Modules/ModuleLoader.cs
experiments/ninject2/src/Ninject/Ninject.csproj
experiments/ninject2/src/Ninject/NinjectSettings.cs
experiments/ninject2/src/Ninject/Parameters/ConstructorArgument.cs
experiments/ninject2/src/Ninject/Parameters/IParameter.cs
experiments/ninject2/src/Ninject/Parameters/Parameter.cs
experiments/ninject2/src/Ninject/Parameters/PropertyValue.cs
experiments/ninject2/src/Ninject/Planning/Bindings/Binding.cs
experiments/ninject2/src/Ninject/Planning/Bindings/BindingBuilder.cs
experiments/ninject2/src/Ninject/Planning/Bindings/BindingMetadata.cs
experiments/ninject2/src/Ninject/Planning/Bindings/IBinding.cs
experiments/ninject2/src/Ninject/Planning/Bindings/IBindingMetadata.cs
experiments/ninject2/src/Ninject/Planning/Targets/ITarget.cs
experiments/ninject2/src/Ninject/Planning/Targets/Target.cs

experiments/ninject2/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs

experiments/ninject2/src/Ninject/Selection/Heuristics/StandardMethodInjectionHeuristic.cs

experiments/ninject2/src/Ninject/Selection/Heuristics/StandardPropertyInjectionHeuristic.cs
experiments/ninject2/src/Ninject/StandardKernel.cs
experiments/ninject2/src/Ninject/Syntax/BindingSyntax.cs
experiments/ninject2/src/Ninject/Syntax/IResolutionRoot.cs
experiments/ninject2/src/Ninject/Syntax/ResolutionExtensions.cs

Log:


Copied:
experiments/ninject2/src/Ninject.Tests/ExtensionsForWeakReference.cs (from
r142, /experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/ExtensionsForWeakReference.cs
Tue Feb 17 21:51:04 2009
@@ -1,14 +1,14 @@
using System;
-using System.Collections.Generic;
+using System.Threading;

namespace Ninject.Tests
{
- public static class ExtensionsForIEnumerable
+ public static class ExtensionsForWeakReference
{
- public static void Map<T>(this IEnumerable<T> series, Action<T> action)
+ public static void WaitUntilGarbageCollected(this WeakReference
reference)
{
- foreach (T item in series)
- action(item);
+ while (reference.IsAlive)
+ Thread.Sleep(100);
}
}
}

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
Tue Feb 17 21:51:04 2009
@@ -28,7 +28,7 @@
var weapon1 = scope.Get<IWeapon>();
var weapon2 = scope.Get<IWeapon>();

- Assert.Same(weapon1, weapon2);
+ weapon1.ShouldBeSameAs(weapon2);
}

[Fact]
@@ -39,7 +39,7 @@
var weapon1 = scope.Get<IWeapon>();
var weapon2 = kernel.Get<IWeapon>();

- Assert.NotSame(weapon1, weapon2);
+ weapon1.ShouldNotBeSameAs(weapon2);
}

[Fact]
@@ -54,7 +54,7 @@

GC.Collect();

- Assert.False(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeFalse();
}
}

@@ -72,7 +72,7 @@

scope.Dispose();

- Assert.True(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeTrue();
}
}


Modified:
experiments/ninject2/src/Ninject.Tests/Integration/CircularDependenciesTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/CircularDependenciesTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/CircularDependenciesTests.cs
Tue Feb 17 21:51:04 2009
@@ -1,9 +1,6 @@
using System;
-using System.Collections;
-using System.Collections.Generic;
using System.Linq;
using Ninject.Activation;
-using Ninject.Activation.Hooks;
using Ninject.Parameters;
using Xunit;

@@ -19,70 +16,152 @@
}
}

- public class WhenDependenciesHaveCircularReferenceBetweenConstructors :
CircularDependenciesContext
+ public class
WhenDependenciesHaveTwoWayCircularReferenceBetweenConstructors :
CircularDependenciesContext
{
- public WhenDependenciesHaveCircularReferenceBetweenConstructors()
+ public WhenDependenciesHaveTwoWayCircularReferenceBetweenConstructors()
{
- kernel.Bind<ConstructorFoo>().ToSelf().InSingletonScope();
- kernel.Bind<ConstructorBar>().ToSelf().InSingletonScope();
+ kernel.Bind<TwoWayConstructorFoo>().ToSelf().InSingletonScope();
+ kernel.Bind<TwoWayConstructorBar>().ToSelf().InSingletonScope();
}

[Fact]
public void DoesNotThrowExceptionIfHookIsCreated()
{
- var request = new Request(typeof(ConstructorFoo), null,
Enumerable.Empty<IParameter>(), null);
+ var request = new Request(typeof(TwoWayConstructorFoo), null,
Enumerable.Empty<IParameter>(), null, false);
Assert.DoesNotThrow(() => kernel.Resolve(request));
}

[Fact]
public void ThrowsActivationExceptionWhenHookIsResolved()
{
- Assert.Throws<ActivationException>(() => kernel.Get<ConstructorFoo>());
+ Assert.Throws<ActivationException>(() =>
kernel.Get<TwoWayConstructorFoo>());
}
}

- public class WhenDependenciesHaveCircularReferenceBetweenProperties :
CircularDependenciesContext
+ public class
WhenDependenciesHaveTwoWayCircularReferenceBetweenProperties :
CircularDependenciesContext
{
- public WhenDependenciesHaveCircularReferenceBetweenProperties()
+ public WhenDependenciesHaveTwoWayCircularReferenceBetweenProperties()
{
- kernel.Bind<PropertyFoo>().ToSelf().InSingletonScope();
- kernel.Bind<PropertyBar>().ToSelf().InSingletonScope();
+ kernel.Bind<TwoWayPropertyFoo>().ToSelf().InSingletonScope();
+ kernel.Bind<TwoWayPropertyBar>().ToSelf().InSingletonScope();
}

[Fact]
public void DoesNotThrowException()
{
- Assert.DoesNotThrow(() => kernel.Get<PropertyFoo>());
+ Assert.DoesNotThrow(() => kernel.Get<TwoWayPropertyFoo>());
}

[Fact]
public void ScopeIsRespected()
{
- var foo = kernel.Get<PropertyFoo>();
- var bar = kernel.Get<PropertyBar>();
+ var foo = kernel.Get<TwoWayPropertyFoo>();
+ var bar = kernel.Get<TwoWayPropertyBar>();

- Assert.Same(bar, foo.Bar);
- Assert.Same(foo, bar.Foo);
+ foo.Bar.ShouldBeSameAs(bar);
+ bar.Foo.ShouldBeSameAs(foo);
}
}

- public class ConstructorFoo
+ public class
WhenDependenciesHaveThreeWayCircularReferenceBetweenConstructors :
CircularDependenciesContext
{
- public ConstructorFoo(ConstructorBar bar) { }
+ public WhenDependenciesHaveThreeWayCircularReferenceBetweenConstructors()
+ {
+ kernel.Bind<ThreeWayConstructorFoo>().ToSelf().InSingletonScope();
+ kernel.Bind<ThreeWayConstructorBar>().ToSelf().InSingletonScope();
+ kernel.Bind<ThreeWayConstructorBaz>().ToSelf().InSingletonScope();
+ }
+
+ [Fact]
+ public void DoesNotThrowExceptionIfHookIsCreated()
+ {
+ var request = new Request(typeof(ThreeWayConstructorFoo), null,
Enumerable.Empty<IParameter>(), null, false);
+ Assert.DoesNotThrow(() => kernel.Resolve(request));
+ }
+
+ [Fact]
+ public void ThrowsActivationExceptionWhenHookIsResolved()
+ {
+ Assert.Throws<ActivationException>(() =>
kernel.Get<ThreeWayConstructorFoo>());
+ }
}

- public class ConstructorBar
+ public class
WhenDependenciesHaveThreeWayCircularReferenceBetweenProperties :
CircularDependenciesContext
{
- public ConstructorBar(ConstructorFoo foo) { }
+ public WhenDependenciesHaveThreeWayCircularReferenceBetweenProperties()
+ {
+ kernel.Bind<ThreeWayPropertyFoo>().ToSelf().InSingletonScope();
+ kernel.Bind<ThreeWayPropertyBar>().ToSelf().InSingletonScope();
+ kernel.Bind<ThreeWayPropertyBaz>().ToSelf().InSingletonScope();
+ }
+
+ [Fact]
+ public void DoesNotThrowException()
+ {
+ Assert.DoesNotThrow(() => kernel.Get<ThreeWayPropertyFoo>());
+ }
+
+ [Fact]
+ public void ScopeIsRespected()
+ {
+ var foo = kernel.Get<ThreeWayPropertyFoo>();
+ var bar = kernel.Get<ThreeWayPropertyBar>();
+ var baz = kernel.Get<ThreeWayPropertyBaz>();
+
+ foo.Bar.ShouldBeSameAs(bar);
+ bar.Baz.ShouldBeSameAs(baz);
+ baz.Foo.ShouldBeSameAs(foo);
+ }
}

- public class PropertyFoo
+ public class TwoWayConstructorFoo
{
- [Inject] public PropertyBar Bar { get; set; }
+ public TwoWayConstructorFoo(TwoWayConstructorBar bar) { }
}

- public class PropertyBar
+ public class TwoWayConstructorBar
{
- [Inject] public PropertyFoo Foo { get; set; }
+ public TwoWayConstructorBar(TwoWayConstructorFoo foo) { }
}
+
+ public class TwoWayPropertyFoo
+ {
+ [Inject] public TwoWayPropertyBar Bar { get; set; }
+ }
+
+ public class TwoWayPropertyBar
+ {
+ [Inject] public TwoWayPropertyFoo Foo { get; set; }
+ }
+
+ public class ThreeWayConstructorFoo
+ {
+ public ThreeWayConstructorFoo(ThreeWayConstructorBar bar) { }
+ }
+
+ public class ThreeWayConstructorBar
+ {
+ public ThreeWayConstructorBar(ThreeWayConstructorBaz baz) { }
+ }
+
+ public class ThreeWayConstructorBaz
+ {
+ public ThreeWayConstructorBaz(TwoWayConstructorFoo foo) { }
+ }
+
+ public class ThreeWayPropertyFoo
+ {
+ [Inject] public ThreeWayPropertyBar Bar { get; set; }
+ }
+
+ public class ThreeWayPropertyBar
+ {
+ [Inject] public ThreeWayPropertyBaz Baz { get; set; }
+ }
+
+ public class ThreeWayPropertyBaz
+ {
+ [Inject] public ThreeWayPropertyFoo Foo { get; set; }
+ }
+
}

Modified:
experiments/ninject2/src/Ninject.Tests/Integration/EnumerableDependenciesTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/EnumerableDependenciesTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/EnumerableDependenciesTests.cs
Tue Feb 17 21:51:04 2009
@@ -26,11 +26,11 @@

var parent = kernel.Get<IParent>();

- Assert.NotNull(parent);
- Assert.NotNull(parent.Children);
- Assert.Equal(2, parent.Children.Length);
- Assert.IsType<ChildA>(parent.Children[0]);
- Assert.IsType<ChildB>(parent.Children[1]);
+ parent.ShouldNotBeNull();
+ parent.Children.ShouldNotBeNull();
+ parent.Children.Length.ShouldBe(2);
+ parent.Children[0].ShouldBeInstanceOf<ChildA>();
+ parent.Children[1].ShouldBeInstanceOf<ChildB>();
}
}

@@ -45,10 +45,10 @@

var parent = kernel.Get<IParent>();

- Assert.NotNull(parent);
- Assert.NotNull(parent.Children);
- Assert.Equal(1, parent.Children.Length);
- Assert.IsType<ChildB>(parent.Children[0]);
+ parent.ShouldNotBeNull();
+ parent.Children.ShouldNotBeNull();
+ parent.Children.Length.ShouldBe(1);
+ parent.Children[0].ShouldBeInstanceOf<ChildB>();
}
}


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
Tue Feb 17 21:51:04 2009
@@ -21,29 +21,26 @@
[Fact]
public void FirstActivatedInstanceIsReused()
{
-
kernel.Bind<INotifyWhenDisposed>().To<NotifiesWhenDisposed>().InSingletonScope();
+ kernel.Bind<IWeapon>().To<Sword>().InSingletonScope();

- var instance1 = kernel.Get<INotifyWhenDisposed>();
- var instance2 = kernel.Get<INotifyWhenDisposed>();
+ var instance1 = kernel.Get<IWeapon>();
+ var instance2 = kernel.Get<IWeapon>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldBeSameAs(instance2);
}

[Fact]
public void InstancesAreNotGarbageCollectedAsLongAsKernelRemainsAlive()
{
-
kernel.Bind<INotifyWhenDisposed>().To<NotifiesWhenDisposed>().InSingletonScope();
+ kernel.Bind<IWeapon>().To<Sword>().InSingletonScope();

- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var instance = kernel.Get<IWeapon>();
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
+ reference.IsAlive.ShouldBeTrue();
}

[Fact]
@@ -58,7 +55,7 @@

kernel.Dispose();

- Assert.True(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeTrue();
}
}

@@ -72,7 +69,7 @@
var sword1 = kernel.Get<Sword>();
var sword2 = kernel.Get<Sword>();

- Assert.Same(sword1, sword2);
+ sword1.ShouldBeSameAs(sword2);
}

[Fact]
@@ -80,16 +77,13 @@
{
kernel.Bind<NotifiesWhenDisposed>().ToSelf().InSingletonScope();

- bool instanceWasDisposed = false;
-
var instance = kernel.Get<NotifiesWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
+ reference.IsAlive.ShouldBeTrue();
}

[Fact]
@@ -104,7 +98,7 @@

kernel.Dispose();

- Assert.True(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeTrue();
}
}

@@ -118,7 +112,7 @@
var instance1 = kernel.Get<INotifyWhenDisposed>();
var instance2 = kernel.Get<INotifyWhenDisposed>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldBeSameAs(instance2);
}

[Fact]
@@ -126,16 +120,13 @@
{

kernel.Bind<INotifyWhenDisposed>().ToProvider<NotifiesWhenDisposedProvider>().InSingletonScope();

- bool instanceWasDisposed = false;
-
var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
+ reference.IsAlive.ShouldBeTrue();
}

[Fact]
@@ -150,7 +141,7 @@

kernel.Dispose();

- Assert.True(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeTrue();
}
}

@@ -164,7 +155,7 @@
var instance1 = kernel.Get<INotifyWhenDisposed>();
var instance2 = kernel.Get<INotifyWhenDisposed>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldBeSameAs(instance2);
}

[Fact]
@@ -172,16 +163,13 @@
{
kernel.Bind<INotifyWhenDisposed>().ToMethod(x => new
NotifiesWhenDisposed()).InSingletonScope();

- bool instanceWasDisposed = false;
-
var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
+ reference.IsAlive.ShouldBeTrue();
}

[Fact]
@@ -196,15 +184,15 @@

kernel.Dispose();

- Assert.True(instanceWasDisposed);
+ instanceWasDisposed.ShouldBeTrue();
}
}

public class NotifiesWhenDisposed : DisposableObject { }

- public class NotifiesWhenDisposedProvider : Provider<INotifyWhenDisposed>
+ public class NotifiesWhenDisposedProvider : Provider<NotifiesWhenDisposed>
{
- protected override INotifyWhenDisposed CreateInstance(IContext context)
+ protected override NotifiesWhenDisposed CreateInstance(IContext context)
{
return new NotifiesWhenDisposed();
}

Modified:
experiments/ninject2/src/Ninject.Tests/Integration/SpecialResolutionTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/SpecialResolutionTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/SpecialResolutionTests.cs
Tue Feb 17 21:51:04 2009
@@ -21,9 +21,9 @@
kernel.Bind<RequestsKernel>().ToSelf();
var instance = kernel.Get<RequestsKernel>();

- Assert.NotNull(instance);
- Assert.NotNull(instance.Kernel);
- Assert.Same(kernel, instance.Kernel);
+ instance.ShouldNotBeNull();
+ instance.Kernel.ShouldNotBeNull();
+ instance.Kernel.ShouldBeSameAs(kernel);
}
}


Modified:
experiments/ninject2/src/Ninject.Tests/Integration/StandardKernelTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Integration/StandardKernelTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/StandardKernelTests.cs
Tue Feb 17 21:51:04 2009
@@ -21,9 +21,11 @@
public void SingleInstanceIsReturnedWhenOneBindingIsRegistered()
{
kernel.Bind<IWeapon>().To<Sword>();
+
var weapon = kernel.Get<IWeapon>();
- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}

[Fact]
@@ -31,9 +33,11 @@
{
kernel.Bind<IWeapon>().To<Sword>();
kernel.Bind<IWeapon>().To<Shuriken>();
+
var weapon = kernel.Get<IWeapon>();
- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}

[Fact]
@@ -44,10 +48,10 @@

var warrior = kernel.Get<IWarrior>();

- Assert.NotNull(warrior);
- Assert.IsType<Samurai>(warrior);
- Assert.NotNull(warrior.Weapon);
- Assert.IsType<Sword>(warrior.Weapon);
+ warrior.ShouldNotBeNull();
+ warrior.ShouldBeInstanceOf<Samurai>();
+ warrior.Weapon.ShouldNotBeNull();
+ warrior.Weapon.ShouldBeInstanceOf<Sword>();
}
}

@@ -57,9 +61,11 @@
public void SingleInstanceIsReturnedWhenOneBindingIsRegistered()
{
kernel.Bind<Sword>().ToSelf();
+
var weapon = kernel.Get<Sword>();
- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}

[Fact]
@@ -70,9 +76,9 @@

var samurai = kernel.Get<Samurai>();

- Assert.NotNull(samurai);
- Assert.NotNull(samurai.Weapon);
- Assert.IsType<Sword>(samurai.Weapon);
+ samurai.ShouldNotBeNull();
+ samurai.Weapon.ShouldNotBeNull();
+ samurai.Weapon.ShouldBeInstanceOf<Sword>();
}
}

@@ -82,34 +88,36 @@
public void ImplicitSelfBindingIsRegisteredAndActivated()
{
var weapon = kernel.Get<Sword>();
- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}

[Fact]
public void ImplicitSelfBindingForGenericTypeIsRegisteredAndActivated()
{
var service = kernel.Get<GenericService<int>>();
- Assert.NotNull(service);
- Assert.IsType<GenericService<int>>(service);
+
+ service.ShouldNotBeNull();
+ service.ShouldBeInstanceOf<GenericService<int>>();
}

[Fact]
public void ThrowsExceptionIfAnUnboundInterfaceIsRequested()
{
- Assert.Throws<NotSupportedException>(() => kernel.Get<IWeapon>());
+ Assert.Throws<ActivationException>(() => kernel.Get<IWeapon>());
}

[Fact]
public void ThrowsExceptionIfAnUnboundAbstractClassIsRequested()
{
- Assert.Throws<NotSupportedException>(() =>
kernel.Get<AbstractWeapon>());
+ Assert.Throws<ActivationException>(() => kernel.Get<AbstractWeapon>());
}

[Fact]
public void ThrowsExceptionIfAnOpenGenericTypeIsRequested()
{
- Assert.Throws<NotSupportedException>(() =>
kernel.Get(typeof(IGeneric<>)));
+ Assert.Throws<ActivationException>(() =>
kernel.Get(typeof(IGeneric<>)));
}
}

@@ -119,9 +127,11 @@
public void GenericParametersAreInferred()
{
kernel.Bind(typeof(IGeneric<>)).To(typeof(GenericService<>));
+
var service = kernel.Get<IGeneric<int>>();
- Assert.NotNull(service);
- Assert.IsType<GenericService<int>>(service);
+
+ service.ShouldNotBeNull();
+ service.ShouldBeInstanceOf<GenericService<int>>();
}
}

@@ -135,10 +145,10 @@

var weapons = kernel.GetAll<IWeapon>().ToArray();

- Assert.NotNull(weapons);
- Assert.Equal(2, weapons.Length);
- Assert.IsType<Sword>(weapons[0]);
- Assert.IsType<Shuriken>(weapons[1]);
+ weapons.ShouldNotBeNull();
+ weapons.Length.ShouldBe(2);
+ weapons[0].ShouldBeInstanceOf<Sword>();
+ weapons[1].ShouldBeInstanceOf<Shuriken>();
}
}

@@ -152,10 +162,10 @@

var services = kernel.GetAll<IGeneric<int>>().ToArray();

- Assert.NotNull(services);
- Assert.Equal(2, services.Length);
- Assert.IsType<GenericService<int>>(services[0]);
- Assert.IsType<GenericService2<int>>(services[1]);
+ services.ShouldNotBeNull();
+ services.Length.ShouldBe(2);
+ services[0].ShouldBeInstanceOf<GenericService<int>>();
+ services[1].ShouldBeInstanceOf<GenericService2<int>>();
}
}

@@ -169,8 +179,8 @@

var weapon = kernel.Get<IWeapon>("sword");

- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}

[Fact]
@@ -181,8 +191,8 @@

var weapon = kernel.Get<IWeapon>(x => x.Get<string>("type") == "melee");

- Assert.NotNull(weapon);
- Assert.IsType<Sword>(weapon);
+ weapon.ShouldNotBeNull();
+ weapon.ShouldBeInstanceOf<Sword>();
}
}


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
Tue Feb 17 21:51:04 2009
@@ -1,5 +1,6 @@
using System;
using System.Threading;
+using Ninject.Activation.Caching;
using Ninject.Infrastructure.Disposal;
using Ninject.Tests.Fakes;
using Xunit;
@@ -12,7 +13,8 @@

public ThreadScopeContext()
{
- kernel = new StandardKernel();
+ var settings = new NinjectSettings { CachePruningIntervalMs =
Int32.MaxValue };
+ kernel = new StandardKernel(settings);
}
}

@@ -37,9 +39,9 @@
thread.Start();
thread.Join();

- Assert.NotNull(weapon1);
- Assert.NotNull(weapon2);
- Assert.Same(weapon1, weapon2);
+ weapon1.ShouldNotBeNull();
+ weapon2.ShouldNotBeNull();
+ weapon1.ShouldBeSameAs(weapon2);
}

[Fact]
@@ -57,21 +59,23 @@
thread.Start();
thread.Join();

- Assert.NotNull(weapon1);
- Assert.NotNull(weapon2);
- Assert.NotSame(weapon1, weapon2);
+ weapon1.ShouldNotBeNull();
+ weapon2.ShouldNotBeNull();
+ weapon1.ShouldNotBeSameAs(weapon2);
}

- [Fact(Skip = "Need to rethink time-based tests")]
- public void
InstancesActivatedWithinScopeAreDeactivatedWithinASecondOfThreadEnding()
+ [Fact]
+ public void
InstancesActivatedWithinScopeAreDeactivatedAfterThreadIsGarbageCollectedAndCacheIsPruned()
{
kernel.Bind<NotifiesWhenDisposed>().ToSelf().InThreadScope();
+ var cache = kernel.Components.Get<ICache>();

NotifiesWhenDisposed instance = null;

ThreadStart callback = () => instance =
kernel.Get<NotifiesWhenDisposed>();

var thread = new Thread(callback);
+ var threadReference = new WeakReference(thread);

thread.Start();
thread.Join();
@@ -79,10 +83,12 @@
thread = null;

GC.Collect();
- Thread.Sleep(1500);

- Assert.NotNull(instance);
- Assert.True(instance.IsDisposed);
+ threadReference.WaitUntilGarbageCollected();
+ cache.Prune();
+
+ instance.ShouldNotBeNull();
+ instance.IsDisposed.ShouldBeTrue();
}
}


Copied:
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
(from r142,
/experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs)
==============================================================================
---
/experiments/ninject2/src/Ninject.Tests/Integration/SingletonScopeTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Integration/TransientScopeTests.cs
Tue Feb 17 21:51:04 2009
@@ -1,212 +1,137 @@
using System;
using Ninject.Activation;
-using Ninject.Infrastructure.Disposal;
using Ninject.Tests.Fakes;
using Xunit;

-namespace Ninject.Tests.Integration.SingletonScopeTests
+namespace Ninject.Tests.Integration.TransientScopeTests
{
- public class SingletonScopeContext
+ public class TransientScopeContext
{
protected readonly StandardKernel kernel;

- public SingletonScopeContext()
+ public TransientScopeContext()
{
kernel = new StandardKernel();
}
}

- public class WhenServiceIsBoundToInterfaceInSingletonScope :
SingletonScopeContext
+ public class WhenServiceIsBoundToInterfaceInTransientScope :
TransientScopeContext
{
[Fact]
- public void FirstActivatedInstanceIsReused()
+ public void NewInstanceIsReturnedForEachRequest()
{
-
kernel.Bind<INotifyWhenDisposed>().To<NotifiesWhenDisposed>().InSingletonScope();
+ kernel.Bind<IWeapon>().To<Sword>().InTransientScope();

- var instance1 = kernel.Get<INotifyWhenDisposed>();
- var instance2 = kernel.Get<INotifyWhenDisposed>();
+ var instance1 = kernel.Get<IWeapon>();
+ var instance2 = kernel.Get<IWeapon>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldNotBeSameAs(instance2);
}

[Fact]
- public void InstancesAreNotGarbageCollectedAsLongAsKernelRemainsAlive()
+ public void
InstancesAreGarbageCollectedIfAllExternalReferencesAreDropped()
{
-
kernel.Bind<INotifyWhenDisposed>().To<NotifiesWhenDisposed>().InSingletonScope();
+ kernel.Bind<IWeapon>().To<Sword>().InTransientScope();

- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var instance = kernel.Get<IWeapon>();
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
- }
-
- [Fact]
- public void InstancesAreDeactivatedWhenKernelIsDisposed()
- {
-
kernel.Bind<INotifyWhenDisposed>().To<NotifiesWhenDisposed>().InSingletonScope();
-
- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
-
- kernel.Dispose();
-
- Assert.True(instanceWasDisposed);
+ reference.IsAlive.ShouldBeFalse();
}
}

- public class WhenServiceIsBoundToSelfInSingletonScope :
SingletonScopeContext
+ public class WhenServiceIsBoundToSelfInTransientScope :
TransientScopeContext
{
[Fact]
- public void FirstActivatedInstanceIsReused()
+ public void NewInstanceIsReturnedForEachRequest()
{
- kernel.Bind<Sword>().ToSelf().InSingletonScope();
+ kernel.Bind<Sword>().ToSelf().InTransientScope();

var sword1 = kernel.Get<Sword>();
var sword2 = kernel.Get<Sword>();

- Assert.Same(sword1, sword2);
+ sword1.ShouldNotBeSameAs(sword2);
}

[Fact]
- public void InstancesAreNotGarbageCollectedAsLongAsKernelRemainsAlive()
+ public void
InstancesAreGarbageCollectedIfAllExternalReferencesAreDropped()
{
- kernel.Bind<NotifiesWhenDisposed>().ToSelf().InSingletonScope();
-
- bool instanceWasDisposed = false;
+ kernel.Bind<Sword>().ToSelf().InTransientScope();

- var instance = kernel.Get<NotifiesWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var instance = kernel.Get<Sword>();
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
- }
-
- [Fact]
- public void InstancesAreDeactivatedWhenKernelIsDisposed()
- {
- kernel.Bind<NotifiesWhenDisposed>().ToSelf().InSingletonScope();
-
- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<NotifiesWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
-
- kernel.Dispose();
-
- Assert.True(instanceWasDisposed);
+ reference.IsAlive.ShouldBeFalse();
}
}

- public class WhenServiceIsBoundToProviderInSingletonScope :
SingletonScopeContext
+ public class WhenServiceIsBoundToProviderInTransientScope :
TransientScopeContext
{
[Fact]
- public void FirstActivatedInstanceIsReused()
+ public void NewInstanceIsReturnedForEachRequest()
{
-
kernel.Bind<INotifyWhenDisposed>().ToProvider<NotifiesWhenDisposedProvider>().InSingletonScope();
+ kernel.Bind<IWeapon>().ToProvider<SwordProvider>().InTransientScope();

- var instance1 = kernel.Get<INotifyWhenDisposed>();
- var instance2 = kernel.Get<INotifyWhenDisposed>();
+ var instance1 = kernel.Get<IWeapon>();
+ var instance2 = kernel.Get<IWeapon>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldNotBeSameAs(instance2);
}

[Fact]
- public void InstancesAreNotGarbageCollectedAsLongAsKernelRemainsAlive()
+ public void
InstancesAreGarbageCollectedIfAllExternalReferencesAreDropped()
{
-
kernel.Bind<INotifyWhenDisposed>().ToProvider<NotifiesWhenDisposedProvider>().InSingletonScope();
-
- bool instanceWasDisposed = false;
+ kernel.Bind<IWeapon>().ToProvider<SwordProvider>().InTransientScope();

- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var instance = kernel.Get<IWeapon>();
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
- }
-
- [Fact]
- public void InstancesAreDeactivatedWhenKernelIsDisposed()
- {
-
kernel.Bind<INotifyWhenDisposed>().ToProvider<NotifiesWhenDisposedProvider>().InSingletonScope();
-
- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
-
- kernel.Dispose();
-
- Assert.True(instanceWasDisposed);
+ reference.IsAlive.ShouldBeFalse();
}
}

- public class WhenServiceIsBoundToMethodInSingletonScope :
SingletonScopeContext
+ public class WhenServiceIsBoundToMethodInTransientScope :
TransientScopeContext
{
[Fact]
- public void FirstActivatedInstanceIsReused()
+ public void NewInstanceIsReturnedForEachRequest()
{
- kernel.Bind<INotifyWhenDisposed>().ToMethod(x => new
NotifiesWhenDisposed()).InSingletonScope();
+ kernel.Bind<IWeapon>().ToMethod(x => new Sword()).InTransientScope();

- var instance1 = kernel.Get<INotifyWhenDisposed>();
- var instance2 = kernel.Get<INotifyWhenDisposed>();
+ var instance1 = kernel.Get<IWeapon>();
+ var instance2 = kernel.Get<IWeapon>();

- Assert.Same(instance1, instance2);
+ instance1.ShouldNotBeSameAs(instance2);
}

[Fact]
- public void InstancesAreNotGarbageCollectedAsLongAsKernelRemainsAlive()
+ public void
InstancesAreGarbageCollectedIfAllExternalReferencesAreDropped()
{
- kernel.Bind<INotifyWhenDisposed>().ToMethod(x => new
NotifiesWhenDisposed()).InSingletonScope();
-
- bool instanceWasDisposed = false;
+ kernel.Bind<IWeapon>().ToMethod(x => new Sword()).InTransientScope();

- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
+ var instance = kernel.Get<IWeapon>();
+ var reference = new WeakReference(instance);

instance = null;
-
GC.Collect();

- Assert.False(instanceWasDisposed);
- }
-
- [Fact]
- public void InstancesAreDeactivatedWhenKernelIsDisposed()
- {
- kernel.Bind<INotifyWhenDisposed>().ToMethod(x => new
NotifiesWhenDisposed()).InSingletonScope();
-
- bool instanceWasDisposed = false;
-
- var instance = kernel.Get<INotifyWhenDisposed>();
- instance.Disposed += (o, e) => instanceWasDisposed = true;
-
- kernel.Dispose();
-
- Assert.True(instanceWasDisposed);
+ reference.IsAlive.ShouldBeFalse();
}
}

- public class NotifiesWhenDisposed : DisposableObject { }
-
- public class NotifiesWhenDisposedProvider : Provider<INotifyWhenDisposed>
+ public class SwordProvider : Provider<Sword>
{
- protected override INotifyWhenDisposed CreateInstance(IContext context)
+ protected override Sword CreateInstance(IContext context)
{
- return new NotifiesWhenDisposed();
+ return new Sword();
}
}
}

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 Tue Feb 17
21:51:04 2009
@@ -53,12 +53,14 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="SpecExtensions.cs" />
+ <Compile Include="ExtensionsForWeakReference.cs" />
<Compile Include="ExtensionsForIEnumerable.cs" />
<Compile Include="Integration\CircularDependenciesTests.cs" />
+ <Compile Include="Integration\TransientScopeTests.cs" />
<Compile Include="Integration\ThreadScopeTests.cs" />
<Compile Include="Integration\SpecialResolutionTests.cs" />
<Compile Include="Unit\ConstructorInjectorTests.cs" />
- <Compile Include="Unit\CachePrunerTests.cs" />
<Compile Include="Integration\SingletonScopeTests.cs" />
<Compile Include="Integration\EnumerableDependenciesTests.cs" />
<Compile Include="Integration\ActivationScopeTests.cs" />

Copied: experiments/ninject2/src/Ninject.Tests/SpecExtensions.cs (from
r142, /experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject.Tests/ExtensionsForIEnumerable.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/SpecExtensions.cs Tue Feb 17
21:51:04 2009
@@ -1,14 +1,136 @@
using System;
+using System.Collections;
using System.Collections.Generic;
+using Xunit;

namespace Ninject.Tests
{
- public static class ExtensionsForIEnumerable
+ public static class SpecExtensions
{
- public static void Map<T>(this IEnumerable<T> series, Action<T> action)
+ public static void ShouldContain(this string self, string str)
{
- foreach (T item in series)
- action(item);
+ Assert.Contains(str, self);
+ }
+
+ public static void ShouldContain(this string self, string str,
StringComparison comparison)
+ {
+ Assert.Contains(str, self, comparison);
+ }
+
+ public static void ShouldContain<T>(this IEnumerable<T> series, T item)
+ {
+ Assert.Contains(item, series);
+ }
+
+ public static void ShouldContain<T>(this IEnumerable<T> series, T item,
IComparer<T> comparer)
+ {
+ Assert.Contains(item, series, comparer);
+ }
+
+ public static void ShouldNotContain(this string self, string str)
+ {
+ Assert.DoesNotContain(str, self);
+ }
+
+ public static void ShouldNotContain(this string self, string str,
StringComparison comparison)
+ {
+ Assert.DoesNotContain(str, self, comparison);
+ }
+
+ public static void ShouldNotContain<T>(this IEnumerable<T> series, T
item)
+ {
+ Assert.DoesNotContain(item, series);
+ }
+
+ public static void ShouldNotContain<T>(this IEnumerable<T> series, T
item, IComparer<T> comparer)
+ {
+ Assert.DoesNotContain(item, series, comparer);
+ }
+
+ public static void ShouldBeEmpty(this IEnumerable series)
+ {
+ Assert.Empty(series);
+ }
+
+ public static void ShouldNotBeEmpty(this IEnumerable series)
+ {
+ Assert.NotEmpty(series);
+ }
+
+ public static void ShouldBe<T>(this T self, T other)
+ {
+ Assert.Equal(other, self);
+ }
+
+ public static void ShouldBe<T>(this T self, T other, IComparer<T>
comparer)
+ {
+ Assert.Equal(other, self, comparer);
+ }
+
+ public static void ShouldBeNull(this object self)
+ {
+ Assert.Null(self);
+ }
+
+ public static void ShouldNotBeNull(this object self)
+ {
+ Assert.NotNull(self);
+ }
+
+ public static void ShouldBeSameAs(this object self, object other)
+ {
+ Assert.Same(other, self);
+ }
+
+ public static void ShouldNotBeSameAs(this object self, object other)
+ {
+ Assert.NotSame(other, self);
+ }
+
+ public static void ShouldBeTrue(this bool self)
+ {
+ Assert.True(self);
+ }
+
+ public static void ShouldBeTrue(this bool self, string message)
+ {
+ Assert.True(self, message);
+ }
+
+ public static void ShouldBeFalse(this bool self)
+ {
+ Assert.False(self);
+ }
+
+ public static void ShouldBeFalse(this bool self, string message)
+ {
+ Assert.False(self, message);
+ }
+
+ public static void ShouldBeInstanceOf<T>(this object self)
+ {
+ Assert.IsType<T>(self);
+ }
+
+ public static void ShouldBeInstanceOf(this object self, Type type)
+ {
+ Assert.IsType(type, self);
+ }
+
+ public static void ShouldNotBeInstanceOf<T>(this object self)
+ {
+ Assert.IsNotType<T>(self);
+ }
+
+ public static void ShouldNotBeInstanceOf(this object self, Type type)
+ {
+ Assert.IsNotType(type, self);
+ }
+
+ public static void ShouldBeThrownBy<T>(this T self,
Assert.ThrowsDelegate method)
+ where T : Exception
+ {
+ Assert.Throws<T>(method);
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/ActivationScopeTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/ActivationScopeTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/ActivationScopeTests.cs Tue
Feb 17 21:51:04 2009
@@ -51,14 +51,14 @@
[Fact]
public void ScopeCreatesRequestAndDelegatesCallToParent()
{
- scope.Resolve(typeof(IWeapon), null, new IParameter[0]);
+ scope.Resolve(typeof(IWeapon), null, new IParameter[0], false);
parentMock.Verify(x => x.Resolve(It.Is<Request>(r => r.Service ==
typeof(IWeapon) && r.Constraint == null && r.Parameters.Count == 0)));
}

[Fact]
public void ScopeCreatesRequestWithItselfAsScope()
{
- scope.Resolve(typeof(IWeapon), null, new IParameter[0]);
+ scope.Resolve(typeof(IWeapon), null, new IParameter[0], false);
parentMock.Verify(x => x.Resolve(It.Is<Request>(r =>
ReferenceEquals(r.ScopeCallback(), scope))));
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/BindingActionStrategyTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Unit/BindingActionStrategyTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/BindingActionStrategyTests.cs
Tue Feb 17 21:51:04 2009
@@ -37,8 +37,8 @@
bindingMock.SetupGet(x => x.ActivationActions).Returns(actions);
strategy.Activate(contextMock.Object);

- Assert.True(action1WasCalled);
- Assert.True(action2WasCalled);
+ action1WasCalled.ShouldBeTrue();
+ action2WasCalled.ShouldBeTrue();
}
}

@@ -58,8 +58,8 @@
bindingMock.SetupGet(x => x.DeactivationActions).Returns(actions);
strategy.Deactivate(contextMock.Object);

- Assert.True(action1WasCalled);
- Assert.True(action2WasCalled);
+ action1WasCalled.ShouldBeTrue();
+ action2WasCalled.ShouldBeTrue();
}
}
}

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 Tue Feb 17
21:51:04 2009
@@ -2,6 +2,7 @@
using Moq;
using Ninject.Activation;
using Ninject.Activation.Caching;
+using Ninject.Infrastructure;
using Ninject.Planning.Bindings;
using Ninject.Tests.Fakes;
using Xunit;
@@ -11,43 +12,26 @@
public class CacheContext
{
protected Mock<IPipeline> activatorMock;
- protected Mock<ICachePruner> prunerMock;
+ protected Mock<IGarbageCollectionWatcher> gcWatcherMock;
protected Mock<IBinding> bindingMock;
protected Cache cache;

public CacheContext()
{
activatorMock = new Mock<IPipeline>();
- prunerMock = new Mock<ICachePruner>();
+ gcWatcherMock = new Mock<IGarbageCollectionWatcher>();
bindingMock = new Mock<IBinding>();
- cache = new Cache(activatorMock.Object, prunerMock.Object);
- }
- }
-
- public class WhenCacheIsCreated
- {
- [Fact]
- public void AsksPrunerToStartPruning()
- {
- var activatorMock = new Mock<IPipeline>();
- var prunerMock = new Mock<ICachePruner>();
-
- prunerMock.Setup(x => x.StartPruning(It.IsAny<Cache>())).AtMostOnce();
-
- var cache = new Cache(activatorMock.Object, prunerMock.Object);
-
- prunerMock.Verify(x => x.StartPruning(cache));
+ cache = new Cache(activatorMock.Object) { GCWatcher =
gcWatcherMock.Object };
}
}

public class WhenCacheIsDisposed : CacheContext
{
[Fact]
- public void AsksPrunerToStopPruning()
+ public void DisposesOfGCWatcher()
{
- prunerMock.Setup(x => x.StopPruning()).AtMostOnce();
cache.Dispose();
- prunerMock.Verify(x => x.StopPruning());
+ gcWatcherMock.Verify(x => x.Dispose());
}
}

@@ -64,7 +48,7 @@

object instance = cache.TryGet(contextMock.Object);

- Assert.Null(instance);
+ instance.ShouldBeNull();
}

[Fact]
@@ -86,7 +70,7 @@

object instance = cache.TryGet(contextMock2.Object);

- Assert.Same(sword, instance);
+ instance.ShouldBeSameAs(sword);
}

[Fact]
@@ -107,7 +91,7 @@

object instance = cache.TryGet(contextMock2.Object);

- Assert.Null(instance);
+ instance.ShouldBeNull();
}
}

@@ -136,7 +120,7 @@

object instance = cache.TryGet(contextMock2.Object);

- Assert.Same(sword, instance);
+ instance.ShouldBeSameAs(sword);
}

[Fact]
@@ -162,7 +146,7 @@

object instance = cache.TryGet(contextMock2.Object);

- Assert.Null(instance);
+ instance.ShouldBeNull();
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/CallbackProviderTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/CallbackProviderTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/CallbackProviderTests.cs
Tue Feb 17 21:51:04 2009
@@ -25,8 +25,10 @@
{
var sword = new Sword();
provider = new CallbackProvider<Sword>(c => sword);
+
var result = provider.Create(contextMock.Object);
- Assert.Same(sword, result);
+
+ result.ShouldBeSameAs(sword);
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/ComponentContainerTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/ComponentContainerTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/ComponentContainerTests.cs
Tue Feb 17 21:51:04 2009
@@ -34,10 +34,11 @@
public void ReturnsInstanceWhenOneImplementationIsRegistered()
{
container.Add<ITestService, TestServiceA>();
+
var service = container.Get<ITestService>();

- Assert.NotNull(service);
- Assert.IsType<TestServiceA>(service);
+ service.ShouldNotBeNull();
+ service.ShouldBeInstanceOf<TestServiceA>();
}

[Fact]
@@ -45,10 +46,11 @@
{
container.Add<ITestService, TestServiceA>();
container.Add<ITestService, TestServiceB>();
+
var service = container.Get<ITestService>();

- Assert.NotNull(service);
- Assert.IsType<TestServiceA>(service);
+ service.ShouldNotBeNull();
+ service.ShouldBeInstanceOf<TestServiceA>();
}

[Fact]
@@ -57,11 +59,12 @@
container.Add<ITestService, TestServiceA>();
container.Add<ITestService, TestServiceB>();
container.Add<IAsksForEnumerable, AsksForEnumerable>();
+
var asks = container.Get<IAsksForEnumerable>();

- Assert.NotNull(asks);
- Assert.NotNull(asks.SecondService);
- Assert.IsType<TestServiceB>(asks.SecondService);
+ asks.ShouldNotBeNull();
+ asks.SecondService.ShouldNotBeNull();
+ asks.SecondService.ShouldBeInstanceOf<TestServiceB>();
}
}

@@ -71,11 +74,12 @@
public void ReturnsSeriesWithSingleItem()
{
container.Add<ITestService, TestServiceA>();
+
var services = container.GetAll<ITestService>().ToList();

- Assert.NotNull(services);
- Assert.Equal(1, services.Count);
- Assert.IsType<TestServiceA>(services[0]);
+ services.ShouldNotBeNull();
+ services.Count.ShouldBe(1);
+ services[0].ShouldBeInstanceOf<TestServiceA>();
}

[Fact]
@@ -85,10 +89,10 @@
container.Add<ITestService, TestServiceB>();
var services = container.GetAll<ITestService>().ToList();

- Assert.NotNull(services);
- Assert.Equal(2, services.Count);
- Assert.IsType<TestServiceA>(services[0]);
- Assert.IsType<TestServiceB>(services[1]);
+ services.ShouldNotBeNull();
+ services.Count.ShouldBe(2);
+ services[0].ShouldBeInstanceOf<TestServiceA>();
+ services[1].ShouldBeInstanceOf<TestServiceB>();
}

[Fact]
@@ -99,9 +103,9 @@
var service1 = container.Get<ITestService>();
var service2 = container.Get<ITestService>();

- Assert.NotNull(service1);
- Assert.NotNull(service2);
- Assert.Same(service1, service2);
+ service1.ShouldNotBeNull();
+ service2.ShouldNotBeNull();
+ service1.ShouldBeSameAs(service2);
}
}

@@ -111,11 +115,11 @@
public void RemovesAllMappings()
{
container.Add<ITestService, TestServiceA>();
+
var service1 = container.Get<ITestService>();
- Assert.NotNull(service1);
+ service1.ShouldNotBeNull();

container.RemoveAll<ITestService>();
-
Assert.Throws<InvalidOperationException>(() =>
container.Get<ITestService>());
}

@@ -124,15 +128,15 @@
{
container.Add<ITestService, TestServiceA>();
container.Add<ITestService, TestServiceB>();
- var services = container.GetAll<ITestService>().ToList();

- Assert.NotNull(services);
- Assert.Equal(2, services.Count);
+ var services = container.GetAll<ITestService>().ToList();
+ services.ShouldNotBeNull();
+ services.Count.ShouldBe(2);

container.RemoveAll<ITestService>();

- Assert.True(services[0].IsDisposed);
- Assert.True(services[1].IsDisposed);
+ services[0].IsDisposed.ShouldBeTrue();
+ services[1].IsDisposed.ShouldBeTrue();
}
}


Modified:
experiments/ninject2/src/Ninject.Tests/Unit/ConstantProviderTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/ConstantProviderTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/ConstantProviderTests.cs
Tue Feb 17 21:51:04 2009
@@ -25,8 +25,10 @@
{
var sword = new Sword();
provider = new ConstantProvider<Sword>(sword);
+
var result = provider.Create(contextMock.Object);
- Assert.Same(sword, result);
+
+ result.ShouldBeSameAs(sword);
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/ConstructorInjectorTests.cs
Tue Feb 17 21:51:04 2009
@@ -23,7 +23,7 @@
[Fact]
public void CanGetCallback()
{
- Assert.NotNull(injector.Callback);
+ injector.Callback.ShouldNotBeNull();
}
}

@@ -33,15 +33,20 @@
public void CallsConstructor()
{
var sword = new Sword();
+
var samurai = injector.Invoke(new[] { sword }) as Samurai;
- Assert.Same(sword, samurai.Weapon);
+
+ samurai.ShouldNotBeNull();
+ samurai.Weapon.ShouldBeSameAs(sword);
}

[Fact]
public void CallsConstructorWithNullArgumentIfOneIsSpecified()
{
var samurai = injector.Invoke(new[] { (IWeapon)null }) as Samurai;
- Assert.NotNull(samurai);
+
+ samurai.ShouldNotBeNull();
+ samurai.Weapon.ShouldBeNull();
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/DisposableStrategyTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/DisposableStrategyTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/DisposableStrategyTests.cs
Tue Feb 17 21:51:04 2009
@@ -29,7 +29,7 @@
contextMock.SetupGet(x => x.Instance).Returns(instance);
strategy.Deactivate(contextMock.Object);

- Assert.True(instance.IsDisposed);
+ instance.IsDisposed.ShouldBeTrue();
}

[Fact]

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/InitializableStrategyTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Unit/InitializableStrategyTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/InitializableStrategyTests.cs
Tue Feb 17 21:51:04 2009
@@ -28,7 +28,7 @@
contextMock.SetupGet(x => x.Instance).Returns(instance);
strategy.Activate(contextMock.Object);

- Assert.True(instance.WasInitialized);
+ instance.WasInitialized.ShouldBeTrue();
}

[Fact]

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectionDirectiveBaseTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectionDirectiveBaseTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectionDirectiveBaseTests.cs
Tue Feb 17 21:51:04 2009
@@ -18,16 +18,17 @@
public void CreatesTargetsForMethodParameters()
{
var method = typeof(Dummy).GetMethod("MethodA");
+
directive = new FakeMethodInjectionDirective(method);
ITarget[] targets = directive.Targets;

- Assert.Equal(3, targets.Length);
- Assert.Equal(targets[0].Name, "foo");
- Assert.Equal(targets[0].Type, typeof(int));
- Assert.Equal(targets[1].Name, "bar");
- Assert.Equal(targets[1].Type, typeof(string));
- Assert.Equal(targets[2].Name, "baz");
- Assert.Equal(targets[2].Type, typeof(IWeapon));
+ targets.Length.ShouldBe(3);
+ targets[0].Name.ShouldBe("foo");
+ targets[0].Type.ShouldBe(typeof(int));
+ targets[1].Name.ShouldBe("bar");
+ targets[1].Type.ShouldBe(typeof(string));
+ targets[2].Name.ShouldBe("baz");
+ targets[2].Type.ShouldBe(typeof(IWeapon));
}
}


Modified: experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/MethodInjectorTests.cs Tue
Feb 17 21:51:04 2009
@@ -23,7 +23,7 @@
[Fact]
public void CanGetCallback()
{
- Assert.NotNull(injector.Callback);
+ injector.Callback.ShouldNotBeNull();
}
}

@@ -33,16 +33,20 @@
public void CallsMethod()
{
var samurai = new Samurai(new Sword());
+
injector.Invoke(samurai, new[] { "evildoer" });
- Assert.True(samurai.IsBattleHardened);
+
+ samurai.IsBattleHardened.ShouldBeTrue();
}

[Fact]
public void ReturnsValueFromMethod()
{
var samurai = new Samurai(new Sword());
+
var result = injector.Invoke(samurai, new[] { "evildoer" }) as string;
- Assert.Equal("Attacked evildoer with a sword", result);
+
+ result.ShouldBe("Attacked evildoer with a sword");
}
}
}

Modified: experiments/ninject2/src/Ninject.Tests/Unit/NamedAttributeTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/NamedAttributeTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/NamedAttributeTests.cs Tue
Feb 17 21:51:04 2009
@@ -23,14 +23,14 @@
public void ReturnsTrueIfTheNameMatches()
{
metadataMock.SetupGet(x => x.Name).Returns("foo");
- Assert.True(attribute.Matches(metadataMock.Object));
+ attribute.Matches(metadataMock.Object).ShouldBeTrue();
}

[Fact]
public void ReturnsFalseIfTheNameDoesNotMatch()
{
metadataMock.SetupGet(x => x.Name).Returns("bar");
- Assert.False(attribute.Matches(metadataMock.Object));
+ attribute.Matches(metadataMock.Object).ShouldBeFalse();
}
}
}

Modified: experiments/ninject2/src/Ninject.Tests/Unit/PipelineTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/PipelineTests.cs (original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/PipelineTests.cs Tue Feb 17
21:51:04 2009
@@ -27,10 +27,10 @@
[Fact]
public void HasListOfStrategies()
{
- Assert.NotNull(pipeline.Strategies);
+ pipeline.Strategies.ShouldNotBeNull();

for (int idx = 0; idx < strategyMocks.Count; idx++)
- Assert.Same(strategyMocks[idx].Object, pipeline.Strategies[idx]);
+ pipeline.Strategies[idx].ShouldBeSameAs(strategyMocks[idx].Object);
}
}


Modified:
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectionDirectiveTests.cs
==============================================================================
---
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectionDirectiveTests.cs
(original)
+++
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectionDirectiveTests.cs
Tue Feb 17 21:51:04 2009
@@ -15,10 +15,11 @@
public void CreatesTargetForProperty()
{
var method = typeof(Dummy).GetProperty("Foo");
+
directive = new PropertyInjectionDirective(method);

- Assert.Equal(directive.Target.Name, "Foo");
- Assert.Equal(directive.Target.Type, typeof(int));
+ directive.Target.Name.ShouldBe("Foo");
+ directive.Target.Type.ShouldBe(typeof(int));
}
}


Modified:
experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/PropertyInjectorTests.cs
Tue Feb 17 21:51:04 2009
@@ -23,7 +23,7 @@
[Fact]
public void CanGetCallback()
{
- Assert.NotNull(injector.Callback);
+ injector.Callback.ShouldNotBeNull();
}
}

@@ -34,16 +34,20 @@
{
var samurai = new Samurai(null);
var sword = new Sword();
+
injector.Invoke(samurai, sword);
- Assert.Same(sword, samurai.Weapon);
+
+ samurai.Weapon.ShouldBeSameAs(sword);
}

[Fact]
public void SetsPropertyValueToNullIfInvokedWithNullArgument()
{
var samurai = new Samurai(new Sword());
+
injector.Invoke(samurai, null);
- Assert.Null(samurai.Weapon);
+
+ samurai.Weapon.ShouldBeNull();
}
}
}

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/StartableStrategyTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/StartableStrategyTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/StartableStrategyTests.cs
Tue Feb 17 21:51:04 2009
@@ -28,7 +28,7 @@
contextMock.SetupGet(x => x.Instance).Returns(instance);
strategy.Activate(contextMock.Object);

- Assert.True(instance.WasStarted);
+ instance.WasStarted.ShouldBeTrue();
}

[Fact]
@@ -51,7 +51,7 @@
contextMock.SetupGet(x => x.Instance).Returns(instance);
strategy.Deactivate(contextMock.Object);

- Assert.True(instance.WasStopped);
+ instance.WasStopped.ShouldBeTrue();
}

[Fact]

Modified:
experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
==============================================================================
--- experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
(original)
+++ experiments/ninject2/src/Ninject.Tests/Unit/VoidMethodInjectorTests.cs
Tue Feb 17 21:51:04 2009
@@ -23,7 +23,7 @@
[Fact]
public void CanGetCallback()
{
- Assert.NotNull(injector.Callback);
+ injector.Callback.ShouldNotBeNull();
}
}

@@ -33,8 +33,10 @@
public void CallsMethod()
{
var samurai = new Samurai(new Sword());
+
injector.Invoke(samurai, new[] { "Bob" });
- Assert.Equal("Bob", samurai.Name);
+
+ samurai.Name.ShouldBe("Bob");
}

[Fact]
@@ -42,8 +44,10 @@
{
var samurai = new Samurai(new Sword());
samurai.Name = "Bob";
+
injector.Invoke(samurai, new[] { (string)null });
- Assert.Null(samurai.Name);
+
+ samurai.Name.ShouldBeNull();
}
}
}

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 Tue Feb 17
21:51:04 2009
@@ -34,27 +34,38 @@
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 cache pruner component.
+ /// Gets or sets the garbage collection watcher.
/// </summary>
- public ICachePruner Pruner { get; private set; }
+ 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>
- /// <param name="pruner">The pruner component.</param>
- public Cache(IPipeline pipeline, ICachePruner pruner)
+ public Cache(IPipeline pipeline)
{
- _entries = new Multimap<IBinding, CacheEntry>();
Pipeline = pipeline;
- Pruner = pruner;
- Pruner.StartPruning(this);
+ _entries = new Multimap<IBinding, CacheEntry>();
}

/// <summary>
@@ -62,11 +73,10 @@
/// </summary>
public override void Dispose()
{
- if (Pruner != null)
- {
- Pruner.StopPruning();
- Pruner = null;
- }
+ if (_initialized)
+ GCWatcher.GarbageCollected -= OnGarbageCollected;
+
+ GCWatcher.Dispose();

base.Dispose();
}
@@ -79,6 +89,12 @@
{
lock (_mutex)
{
+ if (!_initialized)
+ {
+ GCWatcher.GarbageCollected += OnGarbageCollected;
+ _initialized = true;
+ }
+
var entry = new CacheEntry(context);
_entries[context.Binding].Add(entry);

@@ -112,7 +128,7 @@
var cachedArguments = entry.Context.GenericArguments;
var arguments = context.GenericArguments;

- if (!cachedArguments.ElementsEqual(arguments))
+ if (!cachedArguments.SequenceEqual(arguments))
continue;
}

@@ -142,6 +158,11 @@
Pipeline.Deactivate(entry.Context);
_entries[entry.Context.Binding].Remove(entry);
}
+ }
+
+ private void OnGarbageCollected(object sender, EventArgs e)
+ {
+ Prune();
}

private class CacheEntry

Modified: experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/Caching/ICache.cs Tue Feb
17 21:51:04 2009
@@ -40,7 +40,7 @@
object TryGet(IContext context);

/// <summary>
- /// Removes instances from the cache whose scopes have been garbage
collected.
+ /// Removes instances from the cache which should no longer be re-used.
/// </summary>
void Prune();
}

Modified: experiments/ninject2/src/Ninject/Activation/Context.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Context.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/Context.cs Tue Feb 17
21:51:04 2009
@@ -18,7 +18,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Ninject.Infrastructure.Tracing;
using Ninject.Parameters;
using Ninject.Planning;
using Ninject.Planning.Bindings;
@@ -29,7 +28,7 @@
/// <summary>
/// Contains information about the activation of a single instance.
/// </summary>
- public class Context : TraceInfoProvider, IContext
+ public class Context : IContext
{
/// <summary>
/// Gets the kernel that is driving the activation.

Modified: experiments/ninject2/src/Ninject/Activation/Hooks/ContextHook.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Hooks/ContextHook.cs
(original)
+++ experiments/ninject2/src/Ninject/Activation/Hooks/ContextHook.cs Tue
Feb 17 21:51:04 2009
@@ -17,6 +17,7 @@
#region Using Directives
using System;
using Ninject.Activation.Caching;
+using Ninject.Infrastructure.Introspection;
using Ninject.Planning;
#endregion

@@ -71,9 +72,9 @@
lock (Context.Binding)
{
if (Context.Request.ActiveBindings.Contains(Context.Binding))
- throw new ActivationException();
+ throw new
ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(Context));

- Context.Request.ActiveBindings.Add(Context.Binding);
+ Context.Request.ActiveBindings.Push(Context.Binding);

Context.Instance = Cache.TryGet(Context);

@@ -81,12 +82,14 @@
return Context.Instance;

Context.Instance = Context.GetProvider().Create(Context);
- Cache.Remember(Context);

- Context.Request.ActiveBindings.Remove(Context.Binding);
+ if (Context.GetScope() != null)
+ Cache.Remember(Context);
+
+ Context.Request.ActiveBindings.Pop();

if (Context.Plan == null)
- Planner.GetPlan(Context.Instance.GetType());
+ Context.Plan = Planner.GetPlan(Context.Instance.GetType());

Pipeline.Activate(Context);


Modified: experiments/ninject2/src/Ninject/Activation/IContext.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/IContext.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/IContext.cs Tue Feb 17
21:51:04 2009
@@ -17,7 +17,6 @@
#region Using Directives
using System;
using System.Collections.Generic;
-using Ninject.Infrastructure.Tracing;
using Ninject.Parameters;
using Ninject.Planning;
using Ninject.Planning.Bindings;
@@ -28,7 +27,7 @@
/// <summary>
/// Contains information about the activation of a single instance.
/// </summary>
- public interface IContext : IHaveTraceInfo
+ public interface IContext
{
/// <summary>
/// Gets the kernel that is driving the activation.

Modified: experiments/ninject2/src/Ninject/Activation/IRequest.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/IRequest.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/IRequest.cs Tue Feb 17
21:51:04 2009
@@ -55,10 +55,19 @@
ICollection<IParameter> Parameters { get; }

/// <summary>
- /// Gets the collection of bindings which have been activated either by
this request or
- /// one of its ancestors.
+ /// Gets the stack of bindings which have been activated by either this
request or its ancestors.
/// </summary>
- ICollection<IBinding> ActiveBindings { get; }
+ Stack<IBinding> ActiveBindings { get; }
+
+ /// <summary>
+ /// Gets the recursive depth at which this request occurs.
+ /// </summary>
+ int Depth { get; }
+
+ /// <summary>
+ /// Gets or sets value indicating whether the request is optional.
+ /// </summary>
+ bool IsOptional { get; set; }

/// <summary>
/// Determines whether the specified binding satisfies the constraint
defined on this request.

Modified:
experiments/ninject2/src/Ninject/Activation/Providers/StandardProvider.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Activation/Providers/StandardProvider.cs
(original)
+++
experiments/ninject2/src/Ninject/Activation/Providers/StandardProvider.cs
Tue Feb 17 21:51:04 2009
@@ -17,6 +17,7 @@
#region Using Directives
using System;
using System.Linq;
+using Ninject.Infrastructure.Introspection;
using Ninject.Injection;
using Ninject.Parameters;
using Ninject.Planning;
@@ -72,7 +73,7 @@
var directive = context.Plan.GetOne<ConstructorInjectionDirective>();

if (directive == null)
- throw new ActivationException();
+ throw new
ActivationException(ExceptionFormatter.NoConstructorsAvailable(context));

var injector = InjectorFactory.GetConstructorInjector(directive.Member);
object[] arguments = directive.Targets.Select(target =>
GetValue(context, target)).ToArray();

Modified: experiments/ninject2/src/Ninject/Activation/Request.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Request.cs (original)
+++ experiments/ninject2/src/Ninject/Activation/Request.cs Tue Feb 17
21:51:04 2009
@@ -56,10 +56,19 @@
public ICollection<IParameter> Parameters { get; private set; }

/// <summary>
- /// Gets the collection of bindings which have been activated either by
this request or
- /// one of its ancestors.
+ /// Gets the stack of bindings which have been activated by either this
request or its ancestors.
/// </summary>
- public ICollection<IBinding> ActiveBindings { get; private set; }
+ public Stack<IBinding> ActiveBindings { get; private set; }
+
+ /// <summary>
+ /// Gets the recursive depth at which this request occurs.
+ /// </summary>
+ public int Depth { get; private set; }
+
+ /// <summary>
+ /// Gets or sets value indicating whether the request is optional.
+ /// </summary>
+ public bool IsOptional { get; set; }

/// <summary>
/// Gets the callback that resolves the scope for the request, if an
external scope was provided.
@@ -73,13 +82,16 @@
/// <param name="constraint">The constraint that will be applied to
filter the bindings used for the request.</param>
/// <param name="parameters">The parameters that affect the
resolution.</param>
/// <param name="scopeCallback">The scope callback, if an external scope
was specified.</param>
- public Request(Type service, Func<IBindingMetadata, bool> constraint,
IEnumerable<IParameter> parameters, Func<object> scopeCallback)
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
+ public Request(Type service, Func<IBindingMetadata, bool> constraint,
IEnumerable<IParameter> parameters, Func<object> scopeCallback, bool
isOptional)
{
Service = service;
Constraint = constraint;
Parameters = parameters == null ? new List<IParameter>() :
parameters.ToList();
- ActiveBindings = new List<IBinding>();
ScopeCallback = scopeCallback;
+ ActiveBindings = new Stack<IBinding>();
+ Depth = 0;
+ IsOptional = isOptional;
}

/// <summary>
@@ -95,9 +107,11 @@
Service = service;
Target = target;
Constraint = target.Constraint;
- Parameters = new List<IParameter>();
- ActiveBindings = new List<IBinding>(parent.ActiveBindings);
+ IsOptional = target.IsOptional;
+ Parameters = parent.Parameters.Where(p => p.ShouldInherit).ToList();
ScopeCallback = scopeCallback;
+ ActiveBindings = new Stack<IBinding>(parent.ActiveBindings);
+ Depth = parent.Depth + 1;
}

/// <summary>

Modified:
experiments/ninject2/src/Ninject/Activation/Scope/ActivationScope.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Activation/Scope/ActivationScope.cs
(original)
+++ experiments/ninject2/src/Ninject/Activation/Scope/ActivationScope.cs
Tue Feb 17 21:51:04 2009
@@ -62,10 +62,11 @@
/// <param name="service">The service to resolve.</param>
/// <param name="constraint">The constraint to apply to the bindings to
determine if they match the request.</param>
/// <param name="parameters">The parameters to pass to the
resolution.</param>
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
/// <returns>A series of hooks that can be used to resolve instances
that match the request.</returns>
- public IEnumerable<IHook> Resolve(Type service, Func<IBindingMetadata,
bool> constraint, IEnumerable<IParameter> parameters)
+ public IEnumerable<IHook> Resolve(Type service, Func<IBindingMetadata,
bool> constraint, IEnumerable<IParameter> parameters, bool isOptional)
{
- return Resolve(CreateDirectRequest(service, constraint, parameters));
+ return Resolve(CreateDirectRequest(service, constraint, parameters,
isOptional));
}

/// <summary>
@@ -84,10 +85,11 @@
/// <param name="service">The service to resolve.</param>
/// <param name="constraint">The constraints to apply to the bindings to
determine if they match the request.</param>
/// <param name="parameters">The parameters to pass to the
resolution.</param>
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
/// <returns>The created request.</returns>
- protected virtual IRequest CreateDirectRequest(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter> parameters)
+ protected virtual IRequest CreateDirectRequest(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter>
parameters, bool isOptional)
{
- return new Request(service, constraint, parameters, () => this);
+ return new Request(service, constraint, parameters, () => this,
isOptional);
}

object IServiceProvider.GetService(Type serviceType)

Copied: experiments/ninject2/src/Ninject/Attributes/OptionalAttribute.cs
(from r144, /experiments/ninject2/src/Ninject/Attributes/InjectAttribute.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Attributes/InjectAttribute.cs
(original)
+++ experiments/ninject2/src/Ninject/Attributes/OptionalAttribute.cs Tue
Feb 17 21:51:04 2009
@@ -21,9 +21,9 @@
namespace Ninject
{
/// <summary>
- /// Indicates that the decorated member should be injected.
+ /// Indicates that the decorated member represents an optional dependency.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method |
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false, Inherited = true)]
- public class InjectAttribute : Attribute { }
+ public class OptionalAttribute : Attribute { }
}

Modified: experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Components/ComponentContainer.cs
(original)
+++ experiments/ninject2/src/Ninject/Components/ComponentContainer.cs Tue
Feb 17 21:51:04 2009
@@ -21,6 +21,7 @@
using System.Reflection;
using Ninject.Infrastructure;
using Ninject.Infrastructure.Disposal;
+using Ninject.Infrastructure.Introspection;
using Ninject.Infrastructure.Language;
#endregion

@@ -54,21 +55,21 @@
}

/// <summary>
- /// Registers a service in the container.
+ /// Registers a component in the container.
/// </summary>
- /// <typeparam name="TService">The component's service type.</typeparam>
+ /// <typeparam name="TComponent">The component type.</typeparam>
/// <typeparam name="TImplementation">The component's implementation
type.</typeparam>
- public void Add<TService, TImplementation>()
- where TService : INinjectComponent
- where TImplementation : TService, INinjectComponent
+ public void Add<TComponent, TImplementation>()
+ where TComponent : INinjectComponent
+ where TImplementation : TComponent, INinjectComponent
{
- _mappings.Add(typeof(TService), typeof(TImplementation));
+ _mappings.Add(typeof(TComponent), typeof(TImplementation));
}

/// <summary>
- /// Removes all registrations for the specified service.
+ /// Removes all registrations for the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
public void RemoveAll<T>()
where T : INinjectComponent
{
@@ -76,12 +77,12 @@
}

/// <summary>
- /// Removes all registrations for the specified service.
+ /// Removes all registrations for the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
- public void RemoveAll(Type service)
+ /// <param name="component">The component type.</param>
+ public void RemoveAll(Type component)
{
- foreach (Type implementation in _mappings[service])
+ foreach (Type implementation in _mappings[component])
{
if (_instances.ContainsKey(implementation))
_instances[implementation].Dispose();
@@ -89,13 +90,13 @@
_instances.Remove(implementation);
}

- _mappings.RemoveAll(service);
+ _mappings.RemoveAll(component);
}

/// <summary>
/// Gets one instance of the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
/// <returns>The instance of the component.</returns>
public T Get<T>()
where T : INinjectComponent
@@ -106,7 +107,7 @@
/// <summary>
/// Gets all available instances of the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
/// <returns>A series of instances of the specified component.</returns>
public IEnumerable<T> GetAll<T>()
where T : INinjectComponent
@@ -117,58 +118,58 @@
/// <summary>
/// Gets one instance of the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
+ /// <param name="component">The component type.</param>
/// <returns>The instance of the component.</returns>
- public object Get(Type service)
+ public object Get(Type component)
{
- if (service == typeof(IKernel))
+ if (component == typeof(IKernel))
return Kernel;

- if (service.IsGenericType)
+ if (component.IsGenericType)
{
- Type gtd = service.GetGenericTypeDefinition();
- Type argument = service.GetGenericArguments()[0];
+ Type gtd = component.GetGenericTypeDefinition();
+ Type argument = component.GetGenericArguments()[0];

if (gtd.IsInterface && typeof(IEnumerable<>).IsAssignableFrom(gtd))
return LinqReflection.CastSlow(GetAll(argument), argument);
}

- Type implementation = _mappings[service].FirstOrDefault();
+ Type implementation = _mappings[component].FirstOrDefault();

if (implementation == null)
- throw new InvalidOperationException(String.Format("No component of
type {0} has been registered", service));
+ throw new
InvalidOperationException(ExceptionFormatter.NoSuchComponentRegistered(component));

- return ResolveInstance(implementation);
+ return ResolveInstance(component, implementation);
}

/// <summary>
/// Gets all available instances of the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
+ /// <param name="component">The component type.</param>
/// <returns>A series of instances of the specified component.</returns>
- public IEnumerable<object> GetAll(Type service)
+ public IEnumerable<object> GetAll(Type component)
{
- foreach (Type implementation in _mappings[service])
- yield return ResolveInstance(implementation);
+ foreach (Type implementation in _mappings[component])
+ yield return ResolveInstance(component, implementation);
}

- private object ResolveInstance(Type type)
+ private object ResolveInstance(Type component, Type implementation)
{
- return _instances.ContainsKey(type) ? _instances[type] :
CreateNewInstance(type);
+ return _instances.ContainsKey(implementation) ?
_instances[implementation] : CreateNewInstance(component, implementation);
}

- private object CreateNewInstance(Type type)
+ private object CreateNewInstance(Type component, Type implementation)
{
- ConstructorInfo constructor = SelectConstructor(type);
+ ConstructorInfo constructor = SelectConstructor(component,
implementation);
var arguments = constructor.GetParameters().Select(parameter =>
Get(parameter.ParameterType)).ToArray();

try
{
- var component = constructor.Invoke(arguments) as INinjectComponent;
- component.Kernel = Kernel;
- _instances.Add(type, component);
+ var instance = constructor.Invoke(arguments) as INinjectComponent;
+ instance.Settings = Kernel.Settings;
+ _instances.Add(implementation, instance);

- return component;
+ return instance;
}
catch (TargetInvocationException ex)
{
@@ -177,12 +178,12 @@
}
}

- private ConstructorInfo SelectConstructor(Type type)
+ private ConstructorInfo SelectConstructor(Type component, Type
implementation)
{
- var constructor = type.GetConstructors().OrderByDescending(c =>
c.GetParameters().Length).FirstOrDefault();
+ var constructor = implementation.GetConstructors().OrderByDescending(c
=> c.GetParameters().Length).FirstOrDefault();

if (constructor == null)
- throw new NotSupportedException(String.Format("Couldn't resolve a
constructor to create instance of type {0}", type));
+ throw new
InvalidOperationException(ExceptionFormatter.NoConstructorsAvailableForComponent(component,
implementation));

return constructor;
}

Modified: experiments/ninject2/src/Ninject/Components/IComponentContainer.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Components/IComponentContainer.cs
(original)
+++ experiments/ninject2/src/Ninject/Components/IComponentContainer.cs Tue
Feb 17 21:51:04 2009
@@ -32,52 +32,52 @@
IKernel Kernel { get; set; }

/// <summary>
- /// Registers a service in the container.
+ /// Registers a component in the container.
/// </summary>
- /// <typeparam name="TService">The component's service type.</typeparam>
+ /// <typeparam name="TComponent">The component type.</typeparam>
/// <typeparam name="TImplementation">The component's implementation
type.</typeparam>
- void Add<TService, TImplementation>()
- where TService : INinjectComponent
- where TImplementation : TService, INinjectComponent;
+ void Add<TComponent, TImplementation>()
+ where TComponent : INinjectComponent
+ where TImplementation : TComponent, INinjectComponent;

/// <summary>
- /// Removes all registrations for the specified service.
+ /// Removes all registrations for the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
void RemoveAll<T>() where T : INinjectComponent;

/// <summary>
- /// Removes all registrations for the specified service.
+ /// Removes all registrations for the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
- void RemoveAll(Type service);
+ /// <param name="component">The component's type.</param>
+ void RemoveAll(Type component);

/// <summary>
/// Gets one instance of the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
/// <returns>The instance of the component.</returns>
T Get<T>() where T : INinjectComponent;

/// <summary>
/// Gets all available instances of the specified component.
/// </summary>
- /// <typeparam name="T">The component's service type.</typeparam>
+ /// <typeparam name="T">The component type.</typeparam>
/// <returns>A series of instances of the specified component.</returns>
IEnumerable<T> GetAll<T>() where T : INinjectComponent;

/// <summary>
/// Gets one instance of the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
+ /// <param name="component">The component type.</param>
/// <returns>The instance of the component.</returns>
- object Get(Type service);
+ object Get(Type component);

/// <summary>
/// Gets all available instances of the specified component.
/// </summary>
- /// <param name="service">The component's service type.</param>
+ /// <param name="component">The component type.</param>
/// <returns>A series of instances of the specified component.</returns>
- IEnumerable<object> GetAll(Type service);
+ IEnumerable<object> GetAll(Type component);
}
}

Modified: experiments/ninject2/src/Ninject/Components/INinjectComponent.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Components/INinjectComponent.cs
(original)
+++ experiments/ninject2/src/Ninject/Components/INinjectComponent.cs Tue
Feb 17 21:51:04 2009
@@ -26,8 +26,8 @@
public interface INinjectComponent : IDisposable
{
/// <summary>
- /// Gets or sets the kernel that the component is attached to.
+ /// Gets or sets the settings that are being used.
/// </summary>
- IKernel Kernel { get; set; }
+ INinjectSettings Settings { get; set; }
}
}

Modified: experiments/ninject2/src/Ninject/Components/NinjectComponent.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Components/NinjectComponent.cs
(original)
+++ experiments/ninject2/src/Ninject/Components/NinjectComponent.cs Tue Feb
17 21:51:04 2009
@@ -27,8 +27,8 @@
public abstract class NinjectComponent : DisposableObject,
INinjectComponent
{
/// <summary>
- /// Gets or sets the kernel that the component is attached to.
+ /// Gets or sets the settings that are being used.
/// </summary>
- public IKernel Kernel { get; set; }
+ public INinjectSettings Settings { get; set; }
}
}

Modified: experiments/ninject2/src/Ninject/INinjectSettings.cs
==============================================================================
--- experiments/ninject2/src/Ninject/INinjectSettings.cs (original)
+++ experiments/ninject2/src/Ninject/INinjectSettings.cs Tue Feb 17
21:51:04 2009
@@ -31,8 +31,8 @@
Type InjectAttribute { get; }

/// <summary>
- /// Gets the cache prune timeout, in milliseconds.
+ /// Gets or sets the interval at the cache should be pruned, in
milliseconds.
/// </summary>
- int CachePruneTimeoutMs { get; }
+ int CachePruningIntervalMs { get; }
}
}

Copied:
experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
(from r144,
/experiments/ninject2/src/Ninject/Activation/Caching/CachePruner.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Activation/Caching/CachePruner.cs
(original)
+++
experiments/ninject2/src/Ninject/Infrastructure/GarbageCollectionWatcher.cs
Tue Feb 17 21:51:04 2009
@@ -17,51 +17,56 @@
#region Using Directives
using System;
using System.Threading;
-using Ninject.Components;
+using Ninject.Infrastructure.Disposal;
+using Ninject.Infrastructure.Language;
#endregion

-namespace Ninject.Activation.Caching
+namespace Ninject.Infrastructure
{
/// <summary>
- /// Periodically prunes an <see cref="ICache"/>.
+ /// Uses a <see cref="Timer"/> to poll the garbage collector to see if it
has run.
/// </summary>
- public class CachePruner : NinjectComponent, ICachePruner
+ public class GarbageCollectionWatcher : DisposableObject,
IGarbageCollectionWatcher
{
- private static readonly WeakReference _indicator = new WeakReference(new
object());
+ private readonly WeakReference _indicator = new WeakReference(new
object());
private Timer _timer;

/// <summary>
- /// Starts periodically pruning the specified cache.
+ /// Occurs when the garbage collector has run. Since the GC operation
may be concurrent,
+ /// collection may not be complete when this event is fired.
/// </summary>
- /// <param name="cache">The cache to prune.</param>
- public void StartPruning(ICache cache)
- {
- if (_timer != null)
- StopPruning();
+ public event EventHandler GarbageCollected;

- int timeoutMs = Kernel.Settings.CachePruneTimeoutMs;
- _timer = new Timer(PruneCache, cache, timeoutMs, timeoutMs);
+ /// <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);
}

/// <summary>
- /// Stops the periodic pruning operation.
+ /// Releases resources held by the object.
/// </summary>
- public void StopPruning()
+ public override void Dispose()
{
- if (_timer != null)
- {
- _timer.Dispose();
- _timer = null;
- }
+ _timer.Change(Timeout.Infinite, Timeout.Infinite);
+ _timer.Dispose();
+ _timer = null;
+
+ GarbageCollected = null;
+
+ base.Dispose();
}

- private static void PruneCache(object cache)
+ private void RaiseEventIfGarbageCollectorHasRun(object state)
{
- if (!_indicator.IsAlive)
- {
- ((ICache)cache).Prune();
- _indicator.Target = new object();
- }
+ if (_indicator.IsAlive)
+ return;
+
+ GarbageCollected.Raise(this, EventArgs.Empty);
+ _indicator.Target = new object();
}
}
}

Copied:
experiments/ninject2/src/Ninject/Infrastructure/IGarbageCollectionWatcher.cs
(from r144,
/experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs)
==============================================================================
--- /experiments/ninject2/src/Ninject/Activation/Caching/ICachePruner.cs
(original)
+++
experiments/ninject2/src/Ninject/Infrastructure/IGarbageCollectionWatcher.cs
Tue Feb 17 21:51:04 2009
@@ -16,25 +16,19 @@
#endregion
#region Using Directives
using System;
-using Ninject.Components;
#endregion

-namespace Ninject.Activation.Caching
+namespace Ninject.Infrastructure
{
/// <summary>
- /// Periodically prunes an <see cref="ICache"/>.
+ /// Watches the garbage collector, and signals when it has been run.
/// </summary>
- public interface ICachePruner : INinjectComponent
+ public interface IGarbageCollectionWatcher : IDisposable
{
/// <summary>
- /// Starts periodically pruning the specified cache.
+ /// Occurs when the garbage collector has run. Since the GC operation
may be concurrent,
+ /// collection may not be complete when this event is fired.
/// </summary>
- /// <param name="cache">The cache to prune.</param>
- void StartPruning(ICache cache);
-
- /// <summary>
- /// Stops the periodic pruning operation.
- /// </summary>
- void StopPruning();
+ event EventHandler GarbageCollected;
}
}

Copied:
experiments/ninject2/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
(from r144,
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs)
==============================================================================
---
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs
(original)
+++
experiments/ninject2/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
Tue Feb 17 21:51:04 2009
@@ -16,21 +16,131 @@
#endregion
#region Using Directives
using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using Ninject.Activation;
+using Ninject.Planning.Bindings;
+using Ninject.Planning.Targets;
#endregion

-namespace Ninject.Infrastructure.Language
+namespace Ninject.Infrastructure.Introspection
{
- internal static class ExtensionsForEventHandler
+ internal static class ExceptionFormatter
{
- public static void Raise<T>(this EventHandler<T> evt, object sender, T
args)
- where T : EventArgs
+ public static string CouldNotResolveBinding(IRequest request)
{
- if (evt != null) evt(sender, args);
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error activating {0}", request.Service.Format());
+ sw.WriteLine("No matching bindings are available, and the type is not
self-bindable.");
+
+ sw.WriteLine("Activation path:");
+ sw.WriteLine(request.FormatActivationPath());
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that you have defined a binding for {0}.",
request.Service.Format());
+ sw.WriteLine(" 2) If the binding was defined in a module, ensure that
the module has been loaded into the kernel.");
+ sw.WriteLine(" 3) Ensure you have not accidentally created more than
one kernel.");
+ #if !SILVERLIGHT
+ sw.WriteLine(" 4) If you are using automatic module loading, ensure
the search path and filters are correct.");
+ #endif
+
+ return sw.ToString();
+ }
+ }
+
+ public static string CyclicalDependenciesDetected(IContext context)
+ {
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error activating {0} using {1}",
context.Request.Service.Format(), context.Binding.Format(context));
+ sw.WriteLine("A cyclical dependency was detected between the
constructors of two services.");
+ sw.WriteLine();
+
+ sw.WriteLine("Activation path:");
+ sw.WriteLine(context.Request.FormatActivationPath());
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that you have not declared a dependency for
{0} on any implementations of the service.",
context.Request.Service.Format());
+ sw.WriteLine(" 2) Consider combining the services into a single one
to remove the cycle.");
+ sw.WriteLine(" 3) Use property injection instead of constructor
injection, and implement IInitializable");
+ sw.WriteLine(" if you need initialization logic to be run after
property values have been injected.");
+
+ return sw.ToString();
+ }
+ }
+
+ public static string InvalidAttributeTypeUsedInBindingCondition(IBinding
binding, string methodName, Type type)
+ {
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error registering binding for {0}",
binding.Service.Format());
+ sw.WriteLine("The type {0} used in a call to {1}() is not a valid
attribute.", type.Format(), methodName);
+ sw.WriteLine();
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that you have passed the correct type.");
+ sw.WriteLine(" 2) If you have defined your own attribute type, ensure
that it extends System.Attribute.");
+ sw.WriteLine(" 3) To avoid problems with type-safety, use the generic
version of the the method instead,");
+ sw.WriteLine(" such as {0}<SomeAttribute>().", methodName);
+
+ return sw.ToString();
+ }
}

- public static void Raise(this EventHandler evt, object sender, EventArgs
args)
+ public static string NoConstructorsAvailable(IContext context)
{
- if (evt != null) evt(sender, args);
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error activating {0} using {1}",
context.Request.Service.Format(), context.Binding.Format(context));
+ sw.WriteLine("No constructor was available to create an instance of
the implementation type.");
+ sw.WriteLine();
+
+ sw.WriteLine("Activation path:");
+ sw.WriteLine(context.Request.FormatActivationPath());
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that the implementation type has a public
constructor.");
+ sw.WriteLine(" 2) If you have implemented the Singleton pattern, use
a binding with InSingletonScope() instead.");
+
+ return sw.ToString();
+ }
+ }
+
+ public static string NoConstructorsAvailableForComponent(Type component,
Type implementation)
+ {
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error loading Ninject component {0}",
component.Format());
+ sw.WriteLine("No constructor was available to create an instance of
the registered implementation type {0}.", implementation.Format());
+ sw.WriteLine();
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that the implementation type has a public
constructor.");
+
+ return sw.ToString();
+ }
+ }
+
+ public static string NoSuchComponentRegistered(Type component)
+ {
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error loading Ninject component {0}",
component.Format());
+ sw.WriteLine("No such component has been registered in the kernel's
component container.");
+ sw.WriteLine();
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) If you have created a custom subclass for
KernelBase, ensure that you have properly");
+ sw.WriteLine(" implemented the AddComponents() method.");
+ sw.WriteLine(" 2) Ensure that you have not removed the component from
the container via a call to RemoveAll().");
+ sw.WriteLine(" 3) Ensure you have not accidentally created more than
one kernel.");
+
+ return sw.ToString();
+ }
}
}
}

Copied:
experiments/ninject2/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
(from r144,
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs)
==============================================================================
---
/experiments/ninject2/src/Ninject/Infrastructure/Language/ExtensionsForEventHandler.cs
(original)
+++
experiments/ninject2/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
Tue Feb 17 21:51:04 2009
@@ -16,21 +16,148 @@
#endregion
#region Using Directives
using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using Ninject.Activation;
+using Ninject.Activation.Providers;
+using Ninject.Planning.Bindings;
+using Ninject.Planning.Targets;
#endregion

-namespace Ninject.Infrastructure.Language
+namespace Ninject.Infrastructure.Introspection
{
- internal static class ExtensionsForEventHandler
+ internal static class FormatExtensions
{
- public static void Raise<T>(this EventHandler<T> evt, object sender, T
args)
- where T : EventArgs
+ public static string FormatActivationPath(this IRequest request)
{
- if (evt != null) evt(sender, args);
+ var stack = new Stack<IRequest>();
+ IRequest current = request;
+
+ while (current != null)
+ {
+ stack.Push(current);
+ current = current.Parent;
+ }
+
+ var sb = new StringBuilder();
+
+ foreach (var req in stack)
+ sb.AppendFormat("{0,3}) {1}{2}", req.Depth + 1, req.Format(),
Environment.NewLine);
+
+ return sb.ToString();
}

- public static void Raise(this EventHandler evt, object sender, EventArgs
args)
+ public static string Format(this IBinding binding, IContext context)
{
- if (evt != null) evt(sender, args);
+ using (var sw = new StringWriter())
+ {
+ if (binding.Condition != null)
+ sw.Write("conditional ");
+
+ if (binding.Metadata.IsImplicit)
+ sw.Write("implicit ");
+
+ IProvider provider = binding.GetProvider(context);
+
+ if (binding.Service == provider.Type)
+ sw.Write("self-binding of {0}", binding.Service.Format());
+ else
+ sw.Write("binding from {0} to {1}", binding.Service.Format(),
provider.Type.Format());
+
+ Type providerType = provider.GetType();
+
+ if (providerType != typeof(StandardProvider))
+ sw.Write(" (via {0})", providerType.Format());
+
+ return sw.ToString();
+ }
+ }
+
+ public static string Format(this IRequest request)
+ {
+ using (var sw = new StringWriter())
+ {
+ if (request.Target == null)
+ sw.Write("Request for {0}", request.Service.Format());
+ else
+ sw.Write("Injection of dependency {0} into {1}",
request.Service.Format(), request.Target.Format());
+
+ return sw.ToString();
+ }
+ }
+
+ public static string Format(this ITarget target)
+ {
+ using (var sw = new StringWriter())
+ {
+ switch (target.Member.MemberType)
+ {
+ case MemberTypes.Constructor:
+ sw.Write("parameter {0} of constructor", target.Name);
+ break;
+
+ case MemberTypes.Method:
+ sw.Write("parameter {0} of method {1}", target.Name,
target.Member.Name);
+ break;
+
+ case MemberTypes.Property:
+ sw.Write("property {0}", target.Name);
+ break;
+
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ sw.Write(" of type {0}", target.Member.ReflectedType.Format());
+
+ return sw.ToString();
+ }
+ }
+
+ public static string Format(this Type type)
+ {
+ if (type.IsGenericType)
+ {
+ var sb = new StringBuilder();
+
+ sb.Append(type.Name.Substring(0, type.Name.LastIndexOf('`')));
+ sb.Append("[");
+
+ foreach (Type genericArgument in type.GetGenericArguments())
+ {
+ sb.Append(genericArgument.Format());
+ sb.Append(", ");
+ }
+
+ sb.Remove(sb.Length - 2, 2);
+ sb.Append("]");
+
+ return sb.ToString();
+ }
+ else
+ {
+ switch (Type.GetTypeCode(type))
+ {
+ case TypeCode.Boolean: return "bool";
+ case TypeCode.Char: return "char";
+ case TypeCode.SByte: return "sbyte";
+ case TypeCode.Byte: return "byte";
+ case TypeCode.Int16: return "short";
+ case TypeCode.UInt16: return "ushort";
+ case TypeCode.Int32: return "int";
+ case TypeCode.UInt32: return "uint";
+ case TypeCode.Int64: return "long";
+ case TypeCode.UInt64: return "ulong";
+ case TypeCode.Single: return "float";
+ case TypeCode.Double: return "double";
+ case TypeCode.Decimal: return "decimal";
+ case TypeCode.DateTime: return "DateTime";
+ case TypeCode.String: return "string";
+ default: return type.Name;
+ }
+ }
}
}
}

Modified: experiments/ninject2/src/Ninject/KernelBase.cs
==============================================================================
--- experiments/ninject2/src/Ninject/KernelBase.cs (original)
+++ experiments/ninject2/src/Ninject/KernelBase.cs Tue Feb 17 21:51:04 2009
@@ -27,6 +27,7 @@
using Ninject.Events;
using Ninject.Infrastructure;
using Ninject.Infrastructure.Disposal;
+using Ninject.Infrastructure.Introspection;
using Ninject.Infrastructure.Language;
using Ninject.Modules;
using Ninject.Parameters;
@@ -229,10 +230,11 @@
/// <param name="service">The service to resolve.</param>
/// <param name="constraint">The constraint to apply to the bindings to
determine if they match the request.</param>
/// <param name="parameters">The parameters to pass to the
resolution.</param>
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
/// <returns>A series of hooks that can be used to resolve instances
that match the request.</returns>
- public virtual IEnumerable<IHook> Resolve(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter> parameters)
+ public virtual IEnumerable<IHook> Resolve(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter>
parameters, bool isOptional)
{
- return Resolve(CreateDirectRequest(service, constraint, parameters));
+ return Resolve(CreateDirectRequest(service, constraint, parameters,
isOptional));
}

/// <summary>
@@ -242,13 +244,15 @@
/// <returns>A series of hooks that can be used to resolve instances
that match the request.</returns>
public virtual IEnumerable<IHook> Resolve(IRequest request)
{
- if (request.Service.IsAssignableFrom(GetType()))
+ if (request.Service == typeof(IKernel))
return new[] { new ConstantHook(this) };

- if (!CanResolve(request))
+ if (!CanResolve(request)
&& !TryRegisterImplicitSelfBinding(request.Service))
{
- if (!TryRegisterImplicitSelfBinding(request.Service))
- throw new NotSupportedException(String.Format("No binding registered
for {0}", request.Service));
+ if (request.IsOptional)
+ return Enumerable.Empty<IHook>();
+ else
+ throw new
ActivationException(ExceptionFormatter.CouldNotResolveBinding(request));
}

return GetBindings(request)
@@ -300,6 +304,8 @@
return false;

var binding = new Binding(service) { ProviderCallback =
StandardProvider.GetCreationCallback(service) };
+ binding.Metadata.IsImplicit = true;
+
AddBinding(binding);

return true;
@@ -324,10 +330,11 @@
/// <param name="service">The service to resolve.</param>
/// <param name="constraint">The constraint to apply to the bindings to
determine if they match the request.</param>
/// <param name="parameters">The parameters to pass to the
resolution.</param>
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
/// <returns>The created request.</returns>
- protected virtual IRequest CreateDirectRequest(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter> parameters)
+ protected virtual IRequest CreateDirectRequest(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter>
parameters, bool isOptional)
{
- return new Request(service, constraint, parameters, null);
+ return new Request(service, constraint, parameters, null, isOptional);
}

/// <summary>

Modified: experiments/ninject2/src/Ninject/Modules/ModuleLoader.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Modules/ModuleLoader.cs (original)
+++ experiments/ninject2/src/Ninject/Modules/ModuleLoader.cs Tue Feb 17
21:51:04 2009
@@ -33,6 +33,20 @@
public class ModuleLoader : NinjectComponent, IModuleLoader
{
/// <summary>
+ /// Gets or sets the kernel into which modules will be loaded.
+ /// </summary>
+ public IKernel Kernel { get; private set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ModuleLoader"/> class.
+ /// </summary>
+ /// <param name="kernel">The kernel into which modules will be
loaded.</param>
+ public ModuleLoader(IKernel kernel)
+ {
+ Kernel = kernel;
+ }
+
+ /// <summary>
/// Loads all loadable modules defined in the specified assembly.
/// </summary>
/// <param name="assembly">The assembly.</param>

Modified: experiments/ninject2/src/Ninject/Ninject.csproj
==============================================================================
--- experiments/ninject2/src/Ninject/Ninject.csproj (original)
+++ experiments/ninject2/src/Ninject/Ninject.csproj Tue Feb 17 21:51:04 2009
@@ -58,13 +58,14 @@
<Compile Include="Activation\Caching\Cache.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Activation\Caching\CachePruner.cs">
+ <Compile Include="Attributes\OptionalAttribute.cs" />
+ <Compile Include="Infrastructure\GarbageCollectionWatcher.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Activation\Caching\ICache.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Activation\Caching\ICachePruner.cs">
+ <Compile Include="Infrastructure\IGarbageCollectionWatcher.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Activation\Context.cs">
@@ -109,8 +110,9 @@
<Compile Include="Attributes\InjectAttribute.cs" />
<Compile Include="Activation\Hooks\ConstantHook.cs" />
<Compile Include="ActivationException.cs" />
+ <Compile Include="Infrastructure\Introspection\ExceptionFormatter.cs"
/>
+ <Compile Include="Infrastructure\Introspection\FormatExtensions.cs" />
<Compile Include="Infrastructure\Language\ExtensionsForIDictionary.cs"
/>
- <Compile Include="Infrastructure\Language\ExtensionsForIList.cs" />
<Compile Include="Injection\Linq\ExpressionHelper.cs" />
<Compile Include="Syntax\ModuleLoadExtensions.cs" />
<Compile Include="Events\BindingEventArgs.cs" />
@@ -123,7 +125,6 @@
<Compile Include="Planning\Bindings\BindingMetadata.cs" />
<Compile Include="Planning\Bindings\IBindingMetadata.cs" />
<Compile Include="Components\NinjectComponent.cs" />
- <Compile Include="Infrastructure\Tracing\TraceInfoProvider.cs" />
<Compile Include="INinjectSettings.cs" />
<Compile Include="Infrastructure\Disposal\DisposableObject.cs" />
<Compile Include="Activation\Scope\IActivationScope.cs" />
@@ -131,8 +132,6 @@
<Compile
Include="Infrastructure\Language\ExtensionsForEventHandler.cs" />
<Compile Include="Syntax\IResolutionRoot.cs" />
<Compile Include="Activation\Scope\ActivationScope.cs" />
- <Compile Include="Infrastructure\Tracing\IHaveTraceInfo.cs" />
- <Compile Include="Infrastructure\Tracing\TraceInfo.cs" />
<Compile Include="Injection\Linq\MethodInjectorBase.cs" />
<Compile Include="Injection\Linq\VoidMethodInjector.cs" />
<Compile Include="NinjectSettings.cs" />

Modified: experiments/ninject2/src/Ninject/NinjectSettings.cs
==============================================================================
--- experiments/ninject2/src/Ninject/NinjectSettings.cs (original)
+++ experiments/ninject2/src/Ninject/NinjectSettings.cs Tue Feb 17 21:51:04
2009
@@ -31,9 +31,9 @@
public Type InjectAttribute { get; set; }

/// <summary>
- /// Gets or sets the cache prune timeout, in milliseconds.
+ /// Gets or sets the interval at which the GC should be polled, in
milliseconds.
/// </summary>
- public int CachePruneTimeoutMs { get; set; }
+ public int CachePruningIntervalMs { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="NinjectSettings"/>
class with the default values.
@@ -41,7 +41,7 @@
public NinjectSettings()
{
InjectAttribute = typeof(InjectAttribute);
- CachePruneTimeoutMs = 1000;
+ CachePruningIntervalMs = 1000;
}
}
}

Modified: experiments/ninject2/src/Ninject/Parameters/ConstructorArgument.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Parameters/ConstructorArgument.cs
(original)
+++ experiments/ninject2/src/Ninject/Parameters/ConstructorArgument.cs Tue
Feb 17 21:51:04 2009
@@ -31,13 +31,13 @@
/// </summary>
/// <param name="name">The name of the argument to override.</param>
/// <param name="value">The value to inject into the property.</param>
- public ConstructorArgument(string name, object value) : base(name,
value) { }
+ public ConstructorArgument(string name, object value) : base(name,
value, false) { }

/// <summary>
/// Initializes a new instance of the <see cref="ConstructorArgument"/>
class.
/// </summary>
/// <param name="name">The name of the argument to override.</param>
/// <param name="valueCallback">The callback to invoke to get the value
that should be injected.</param>
- public ConstructorArgument(string name, Func<IContext, object>
valueCallback) : base(name, valueCallback) { }
+ public ConstructorArgument(string name, Func<IContext, object>
valueCallback) : base(name, valueCallback, false) { }
}
}

Modified: experiments/ninject2/src/Ninject/Parameters/IParameter.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Parameters/IParameter.cs (original)
+++ experiments/ninject2/src/Ninject/Parameters/IParameter.cs Tue Feb 17
21:51:04 2009
@@ -32,6 +32,11 @@
string Name { get; }

/// <summary>
+ /// Gets a value indicating whether the parameter should be inherited
into child requests.
+ /// </summary>
+ bool ShouldInherit { get; }
+
+ /// <summary>
/// Gets the value for the parameter within the specified context.
/// </summary>
/// <param name="context">The context.</param>

Modified: experiments/ninject2/src/Ninject/Parameters/Parameter.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Parameters/Parameter.cs (original)
+++ experiments/ninject2/src/Ninject/Parameters/Parameter.cs Tue Feb 17
21:51:04 2009
@@ -32,6 +32,11 @@
public string Name { get; private set; }

/// <summary>
+ /// Gets a value indicating whether the parameter should be inherited
into child requests.
+ /// </summary>
+ public bool ShouldInherit { get; private set; }
+
+ /// <summary>
/// Gets or sets the callback that will be triggered to get the
parameter's value.
/// </summary>
public Func<IContext, object> ValueCallback { get; private set; }
@@ -41,17 +46,20 @@
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter.</param>
- public Parameter(string name, object value) : this(name, ctx => value) {
}
+ /// <param name="shouldInherit">Whether the parameter should be
inherited into child requests.</param>
+ public Parameter(string name, object value, bool shouldInherit) :
this(name, ctx => value, shouldInherit) { }

/// <summary>
/// Initializes a new instance of the <see cref="Parameter"/> class.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="valueCallback">The callback that will be triggered to
get the parameter's value.</param>
- public Parameter(string name, Func<IContext, object> valueCallback)
+ /// <param name="shouldInherit">Whether the parameter should be
inherited into child requests.</param>
+ public Parameter(string name, Func<IContext, object> valueCallback, bool
shouldInherit)
{
Name = name;
ValueCallback = valueCallback;
+ ShouldInherit = shouldInherit;
}

/// <summary>

Modified: experiments/ninject2/src/Ninject/Parameters/PropertyValue.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Parameters/PropertyValue.cs (original)
+++ experiments/ninject2/src/Ninject/Parameters/PropertyValue.cs Tue Feb 17
21:51:04 2009
@@ -31,13 +31,13 @@
/// </summary>
/// <param name="name">The name of the property to override.</param>
/// <param name="value">The value to inject into the property.</param>
- public PropertyValue(string name, object value) : base(name, value) { }
+ public PropertyValue(string name, object value) : base(name, value,
false) { }

/// <summary>
/// Initializes a new instance of the <see cref="PropertyValue"/> class.
/// </summary>
/// <param name="name">The name of the property to override.</param>
/// <param name="valueCallback">The callback to invoke to get the value
that should be injected.</param>
- public PropertyValue(string name, Func<IContext, object>
valueCallback) : base(name, valueCallback) { }
+ public PropertyValue(string name, Func<IContext, object>
valueCallback) : base(name, valueCallback, false) { }
}
}

Modified: experiments/ninject2/src/Ninject/Planning/Bindings/Binding.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Bindings/Binding.cs (original)
+++ experiments/ninject2/src/Ninject/Planning/Bindings/Binding.cs Tue Feb
17 21:51:04 2009
@@ -17,10 +17,7 @@
#region Using Directives
using System;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
using Ninject.Activation;
-using Ninject.Infrastructure.Tracing;
using Ninject.Parameters;
#endregion

@@ -29,11 +26,8 @@
/// <summary>
/// Contains information about a service registration.
/// </summary>
- [DebuggerDisplay("{IntrospectionInfo} from {TraceInfo}")]
- public class Binding : TraceInfoProvider, IBinding
+ public class Binding : IBinding
{
- private IProvider _provider;
-
/// <summary>
/// Gets the service type that is controlled by the binding.
/// </summary>
@@ -75,11 +69,6 @@
public Func<IContext, object> ScopeCallback { get; set; }

/// <summary>
- /// Gets or sets the introspection information for the binding.
- /// </summary>
- public string IntrospectionInfo { get; set; }
-
- /// <summary>
/// Initializes a new instance of the <see cref="Binding"/> class.
/// </summary>
/// <param name="service">The service that is controlled by the
binding.</param>
@@ -97,7 +86,6 @@
Parameters = new List<IParameter>();
ActivationActions = new List<Action<IContext>>();
DeactivationActions = new List<Action<IContext>>();
- IntrospectionInfo = "Binding from " + service;
}

/// <summary>
@@ -107,10 +95,7 @@
/// <returns>The provider to use.</returns>
public IProvider GetProvider(IContext context)
{
- if (_provider == null)
- _provider = ProviderCallback(context);
-
- return _provider;
+ return ProviderCallback(context);
}

/// <summary>

Modified:
experiments/ninject2/src/Ninject/Planning/Bindings/BindingBuilder.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Bindings/BindingBuilder.cs
(original)
+++ experiments/ninject2/src/Ninject/Planning/Bindings/BindingBuilder.cs
Tue Feb 17 21:51:04 2009
@@ -22,6 +22,7 @@
#endif
using Ninject.Activation;
using Ninject.Activation.Providers;
+using Ninject.Infrastructure.Introspection;
using Ninject.Infrastructure.Language;
using Ninject.Parameters;
using Ninject.Syntax;
@@ -54,7 +55,6 @@
public IBindingWhenInNamedWithOrOnSyntax<T> ToSelf()
{
Binding.ProviderCallback =
StandardProvider.GetCreationCallback(Binding.Service);
- Binding.IntrospectionInfo += " to self";
return this;
}

@@ -66,7 +66,6 @@
where TImplementation : T
{
Binding.ProviderCallback =
StandardProvider.GetCreationCallback(typeof(TImplementation));
- Binding.IntrospectionInfo += " to " + typeof(TImplementation);
return this;
}

@@ -77,7 +76,6 @@
public IBindingWhenInNamedWithOrOnSyntax<T> To(Type implementation)
{
Binding.ProviderCallback =
StandardProvider.GetCreationCallback(implementation);
- Binding.IntrospectionInfo += " to " + implementation;
return this;
}

@@ -90,7 +88,6 @@
where TProvider : IProvider
{
Binding.ProviderCallback = ctx => ctx.Kernel.Get<TProvider>();
- Binding.IntrospectionInfo += " to provider " + typeof(TProvider);
return this;
}

@@ -101,7 +98,6 @@
public IBindingWhenInNamedWithOrOnSyntax<T> ToProvider(IProvider
provider)
{
Binding.ProviderCallback = ctx => provider;
- Binding.IntrospectionInfo += " to external instance of provider " +
provider.GetType();
return this;
}

@@ -112,7 +108,6 @@
public IBindingWhenInNamedWithOrOnSyntax<T> ToMethod(Func<IContext, T>
method)
{
Binding.ProviderCallback = ctx => new CallbackProvider<T>(method);
- Binding.IntrospectionInfo += " to method " + method.Method;
return this;
}

@@ -123,7 +118,6 @@
public IBindingWhenInNamedWithOrOnSyntax<T> ToConstant(T value)
{
Binding.ProviderCallback = ctx => new ConstantProvider<T>(value);
- Binding.IntrospectionInfo += " to constant " + value;
return this;
}

@@ -134,7 +128,6 @@
public IBindingInNamedWithOrOnSyntax<T> When(Func<IRequest, bool>
condition)
{
Binding.Condition = condition;
- Binding.IntrospectionInfo += " (conditionally)";
return this;
}

@@ -154,11 +147,20 @@
public IBindingInNamedWithOrOnSyntax<T> WhenInjectedInto(Type parent)
{
Binding.Condition = r => r.Target.Member.ReflectedType == parent;
- Binding.IntrospectionInfo += " (conditionally)";
return this;
}

/// <summary>
+ /// Indicates that the binding should be used only when the class being
injected has
+ /// an attribute of the specified type.
+ /// </summary>
+ /// <typeparam name="TAttribute">The type of attribute.</typeparam>
+ public IBindingInNamedWithOrOnSyntax<T> WhenClassHas<TAttribute>() where
TAttribute : Attribute
+ {
+ return WhenClassHas(typeof(TAttribute));
+ }
+
+ /// <summary>
/// Indicates that the binding should be used only when the member being
injected has
/// an attribute of the specified type.
/// </summary>
@@ -169,29 +171,43 @@
}

/// <summary>
- /// Indicates that the binding should be used only when the member being
injected has
+ /// Indicates that the binding should be used only when the target being
injected has
+ /// an attribute of the specified type.
+ /// </summary>
+ /// <typeparam name="TAttribute">The type of attribute.</typeparam>
+ public IBindingInNamedWithOrOnSyntax<T> WhenTargetHas<TAttribute>()
where TAttribute : Attribute
+ {
+ return WhenTargetHas(typeof(TAttribute));
+ }
+
+ /// <summary>
+ /// Indicates that the binding should be used only when the class being
injected has
/// an attribute of the specified type.
/// </summary>
/// <param name="attributeType">The type of attribute.</param>
- public IBindingInNamedWithOrOnSyntax<T> WhenMemberHas(Type attributeType)
+ public IBindingInNamedWithOrOnSyntax<T> WhenClassHas(Type attributeType)
{
if (!typeof(Attribute).IsAssignableFrom(attributeType))
- throw new InvalidOperationException();
+ throw new
InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(Binding, "WhenClassHas",
attributeType));

- Binding.Condition = r => r.Target.Member.HasAttribute(attributeType);
- Binding.IntrospectionInfo += " (conditionally)";
+ Binding.Condition = r =>
r.Target.Member.ReflectedType.HasAttribute(attributeType);

return this;
}

/// <summary>
- /// Indicates that the binding should be used only when the target being
injected has
+ /// Indicates that the binding should be used only when the member being
injected has
/// an attribute of the specified type.
/// </summary>
- /// <typeparam name="TAttribute">The type of attribute.</typeparam>
- public IBindingInNamedWithOrOnSyntax<T> WhenTargetHas<TAttribute>()
where TAttribute : Attribute
+ /// <param name="attributeType">The type of attribute.</param>
+ public IBindingInNamedWithOrOnSyntax<T> WhenMemberHas(Type attributeType)
{
- return WhenTargetHas(typeof(TAttribute));
+ if (!typeof(Attribute).IsAssignableFrom(attributeType))
+ throw new
InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(Binding, "WhenMemberHas",
attributeType));
+
+ Binding.Condition = r => r.Target.Member.HasAttribute(attributeType);
+
+ return this;
}

/// <summary>
@@ -202,10 +218,9 @@
public IBindingInNamedWithOrOnSyntax<T> WhenTargetHas(Type attributeType)
{
if (!typeof(Attribute).IsAssignableFrom(attributeType))
- throw new InvalidOperationException();
+ throw new
InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(Binding, "WhenTargetHas",
attributeType));

Binding.Condition = r => r.Target.HasAttribute(attributeType);
- Binding.IntrospectionInfo += " (conditionally)";

return this;
}
@@ -219,7 +234,6 @@
{
String.Intern(name);
Binding.Metadata.Name = name;
- Binding.IntrospectionInfo += " with name '" + name + "'";
return this;
}

@@ -230,7 +244,6 @@
public IBindingNamedWithOrOnSyntax<T> InSingletonScope()
{
Binding.ScopeCallback = ctx => ctx.Kernel;
- Binding.IntrospectionInfo += " in singleton scope";
return this;
}

@@ -241,7 +254,6 @@
public IBindingNamedWithOrOnSyntax<T> InTransientScope()
{
Binding.ScopeCallback = null;
- Binding.IntrospectionInfo += " in transient scope";
return this;
}

@@ -251,7 +263,6 @@
public IBindingNamedWithOrOnSyntax<T> InThreadScope()
{
Binding.ScopeCallback = ctx => Thread.CurrentThread;
- Binding.IntrospectionInfo += " in thread scope";
return this;
}

@@ -263,7 +274,6 @@
public IBindingNamedWithOrOnSyntax<T> InRequestScope()
{
Binding.ScopeCallback = ctx => HttpContext.Current;
- Binding.IntrospectionInfo += " in request scope";
return this;
}
#endif
@@ -276,7 +286,6 @@
public IBindingNamedWithOrOnSyntax<T> InScope(Func<IContext, object>
scope)
{
Binding.ScopeCallback = scope;
- Binding.IntrospectionInfo += " in custom scope";
return this;
}

@@ -342,7 +351,6 @@
public IBindingWithOrOnSyntax<T> WithMetadata(string key, object value)
{
Binding.Metadata.Set(key, value);
- Binding.IntrospectionInfo += " with metadata " + key + " = " + value;
return this;
}


Modified:
experiments/ninject2/src/Ninject/Planning/Bindings/BindingMetadata.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Bindings/BindingMetadata.cs
(original)
+++ experiments/ninject2/src/Ninject/Planning/Bindings/BindingMetadata.cs
Tue Feb 17 21:51:04 2009
@@ -35,6 +35,11 @@
public string Name { get; set; }

/// <summary>
+ /// Gets or sets a value indicating whether the binding was implicitly
registered.
+ /// </summary>
+ public bool IsImplicit { get; set; }
+
+ /// <summary>
/// Determines whether a piece of metadata with the specified key has
been defined.
/// </summary>
/// <param name="key">The metadata key.</param>

Modified: experiments/ninject2/src/Ninject/Planning/Bindings/IBinding.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Bindings/IBinding.cs
(original)
+++ experiments/ninject2/src/Ninject/Planning/Bindings/IBinding.cs Tue Feb
17 21:51:04 2009
@@ -18,7 +18,6 @@
using System;
using System.Collections.Generic;
using Ninject.Activation;
-using Ninject.Infrastructure.Tracing;
using Ninject.Parameters;
#endregion

@@ -27,7 +26,7 @@
/// <summary>
/// Contains information about a service registration.
/// </summary>
- public interface IBinding : IHaveTraceInfo
+ public interface IBinding
{
/// <summary>
/// Gets the service type that is controlled by the binding.

Modified:
experiments/ninject2/src/Ninject/Planning/Bindings/IBindingMetadata.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Bindings/IBindingMetadata.cs
(original)
+++ experiments/ninject2/src/Ninject/Planning/Bindings/IBindingMetadata.cs
Tue Feb 17 21:51:04 2009
@@ -32,6 +32,11 @@
string Name { get; set; }

/// <summary>
+ /// Gets or sets a value indicating whether the binding was implicitly
registered.
+ /// </summary>
+ bool IsImplicit { get; set; }
+
+ /// <summary>
/// Determines whether a piece of metadata with the specified key has
been defined.
/// </summary>
/// <param name="key">The metadata key.</param>

Modified: experiments/ninject2/src/Ninject/Planning/Targets/ITarget.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Targets/ITarget.cs (original)
+++ experiments/ninject2/src/Ninject/Planning/Targets/ITarget.cs Tue Feb 17
21:51:04 2009
@@ -25,7 +25,7 @@
namespace Ninject.Planning.Targets
{
/// <summary>
- /// Represents a site on a type where a value can be injected.
+ /// Represents a site on a type where a value will be injected.
/// </summary>
public interface ITarget : ICustomAttributeProvider
{
@@ -48,6 +48,11 @@
/// Gets the constraint defined on the target.
/// </summary>
Func<IBindingMetadata, bool> Constraint { get; }
+
+ /// <summary>
+ /// Gets a value indicating whether the target represents an optional
dependency.
+ /// </summary>
+ bool IsOptional { get; }

/// <summary>
/// Resolves a value for the target within the specified parent context.

Modified: experiments/ninject2/src/Ninject/Planning/Targets/Target.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Planning/Targets/Target.cs (original)
+++ experiments/ninject2/src/Ninject/Planning/Targets/Target.cs Tue Feb 17
21:51:04 2009
@@ -69,6 +69,14 @@
}

/// <summary>
+ /// Gets a value indicating whether the target represents an optional
dependency.
+ /// </summary>
+ public bool IsOptional
+ {
+ get { return Site.HasAttribute<OptionalAttribute>(); }
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="Target&lt;T&gt;"/>
class.
/// </summary>
/// <param name="member">The member that contains the target.</param>

Modified:
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs
(original)
+++
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs
Tue Feb 17 21:51:04 2009
@@ -36,7 +36,7 @@
/// <returns>The constructor's score.</returns>
public int Score(ConstructorInfo constructor)
{
- return constructor.HasAttribute(Kernel.Settings.InjectAttribute) ?
Int32.MaxValue : constructor.GetParameters().Length;
+ return constructor.HasAttribute(Settings.InjectAttribute) ?
Int32.MaxValue : constructor.GetParameters().Length;
}
}
}

Modified:
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardMethodInjectionHeuristic.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardMethodInjectionHeuristic.cs
(original)
+++
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardMethodInjectionHeuristic.cs
Tue Feb 17 21:51:04 2009
@@ -36,7 +36,7 @@
/// <returns><c>True</c> if the method should be injected; otherwise
<c>false</c>.</returns>
public bool ShouldInject(MethodInfo method)
{
- return method.HasAttribute(Kernel.Settings.InjectAttribute);
+ return method.HasAttribute(Settings.InjectAttribute);
}
}
}

Modified:
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardPropertyInjectionHeuristic.cs
==============================================================================
---
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardPropertyInjectionHeuristic.cs
(original)
+++
experiments/ninject2/src/Ninject/Selection/Heuristics/StandardPropertyInjectionHeuristic.cs
Tue Feb 17 21:51:04 2009
@@ -36,7 +36,7 @@
/// <returns><c>True</c> if the property should be injected; otherwise
<c>false</c>.</returns>
public bool ShouldInject(PropertyInfo property)
{
- return property.HasAttribute(Kernel.Settings.InjectAttribute);
+ return property.HasAttribute(Settings.InjectAttribute);
}
}
}

Modified: experiments/ninject2/src/Ninject/StandardKernel.cs
==============================================================================
--- experiments/ninject2/src/Ninject/StandardKernel.cs (original)
+++ experiments/ninject2/src/Ninject/StandardKernel.cs Tue Feb 17 21:51:04
2009
@@ -19,6 +19,7 @@
using Ninject.Activation;
using Ninject.Activation.Caching;
using Ninject.Activation.Strategies;
+using Ninject.Infrastructure;
using Ninject.Injection;
using Ninject.Injection.Linq;
using Ninject.Modules;
@@ -53,17 +54,6 @@
/// </summary>
protected override void AddComponents()
{
- Components.Add<IPipeline, Pipeline>();
- Components.Add<IActivationStrategy, PropertyInjectionStrategy>();
- Components.Add<IActivationStrategy, MethodInjectionStrategy>();
- Components.Add<IActivationStrategy, InitializableStrategy>();
- Components.Add<IActivationStrategy, StartableStrategy>();
- Components.Add<IActivationStrategy, BindingActionStrategy>();
- Components.Add<IActivationStrategy, DisposableStrategy>();
-
- Components.Add<ICache, Cache>();
- Components.Add<ICachePruner, CachePruner>();
-
Components.Add<IPlanner, Planner>();
Components.Add<IPlanningStrategy, ConstructorReflectionStrategy>();
Components.Add<IPlanningStrategy, PropertyReflectionStrategy>();
@@ -74,7 +64,16 @@
Components.Add<IPropertyInjectionHeuristic,
StandardPropertyInjectionHeuristic>();
Components.Add<IMethodInjectionHeuristic,
StandardMethodInjectionHeuristic>();

+ Components.Add<IPipeline, Pipeline>();
+ Components.Add<IActivationStrategy, PropertyInjectionStrategy>();
+ Components.Add<IActivationStrategy, MethodInjectionStrategy>();
+ Components.Add<IActivationStrategy, InitializableStrategy>();
+ Components.Add<IActivationStrategy, StartableStrategy>();
+ Components.Add<IActivationStrategy, BindingActionStrategy>();
+ Components.Add<IActivationStrategy, DisposableStrategy>();
+
Components.Add<IInjectorFactory, InjectorFactory>();
+ Components.Add<ICache, Cache>();

#if !SILVERLIGHT
Components.Add<IModuleLoader, ModuleLoader>();

Modified: experiments/ninject2/src/Ninject/Syntax/BindingSyntax.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Syntax/BindingSyntax.cs (original)
+++ experiments/ninject2/src/Ninject/Syntax/BindingSyntax.cs Tue Feb 17
21:51:04 2009
@@ -96,6 +96,13 @@
IBindingInNamedWithOrOnSyntax<T> WhenInjectedInto(Type parent);

/// <summary>
+ /// Indicates that the binding should be used only when the class being
injected has
+ /// an attribute of the specified type.
+ /// </summary>
+ /// <typeparam name="TAttribute">The type of attribute.</typeparam>
+ IBindingInNamedWithOrOnSyntax<T> WhenClassHas<TAttribute>() where
TAttribute : Attribute;
+
+ /// <summary>
/// Indicates that the binding should be used only when the member being
injected has
/// an attribute of the specified type.
/// </summary>
@@ -108,6 +115,13 @@
/// </summary>
/// <typeparam name="TAttribute">The type of attribute.</typeparam>
IBindingInNamedWithOrOnSyntax<T> WhenTargetHas<TAttribute>() where
TAttribute : Attribute;
+
+ /// <summary>
+ /// Indicates that the binding should be used only when the class being
injected has
+ /// an attribute of the specified type.
+ /// </summary>
+ /// <param name="attributeType">The type of attribute.</param>
+ IBindingInNamedWithOrOnSyntax<T> WhenClassHas(Type attributeType);

/// <summary>
/// Indicates that the binding should be used only when the member being
injected has

Modified: experiments/ninject2/src/Ninject/Syntax/IResolutionRoot.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Syntax/IResolutionRoot.cs (original)
+++ experiments/ninject2/src/Ninject/Syntax/IResolutionRoot.cs Tue Feb 17
21:51:04 2009
@@ -43,8 +43,9 @@
/// <param name="service">The service to resolve.</param>
/// <param name="constraint">The constraint to apply to the bindings to
determine if they match the request.</param>
/// <param name="parameters">The parameters to pass to the
resolution.</param>
+ /// <param name="isOptional"><c>True</c> if the request is optional;
otherwise, <c>false</c>.</param>
/// <returns>A series of hooks that can be used to resolve instances
that match the request.</returns>
- IEnumerable<IHook> Resolve(Type service, Func<IBindingMetadata, bool>
constraint, IEnumerable<IParameter> parameters);
+ IEnumerable<IHook> Resolve(Type service, Func<IBindingMetadata, bool>
constraint, IEnumerable<IParameter> parameters, bool isOptional);

/// <summary>
/// Resolves the specified request.

Modified: experiments/ninject2/src/Ninject/Syntax/ResolutionExtensions.cs
==============================================================================
--- experiments/ninject2/src/Ninject/Syntax/ResolutionExtensions.cs
(original)
+++ experiments/ninject2/src/Ninject/Syntax/ResolutionExtensions.cs Tue Feb
17 21:51:04 2009
@@ -39,7 +39,7 @@
/// <returns>An instance of the service.</returns>
public static T Get<T>(this IResolutionRoot root, params IParameter[]
parameters)
{
- return root.Resolve(typeof(T), null, parameters).Select(hook =>
hook.Resolve()).Cast<T>().FirstOrDefault();
+ return (T)root.Get(typeof(T), parameters);
}

/// <summary>
@@ -52,7 +52,7 @@
/// <returns>An instance of the service.</returns>
public static T Get<T>(this IResolutionRoot root, string name, params
IParameter[] parameters)
{
- return root.Get<T>(m => m.Name == name, parameters);
+ return (T)root.Get(typeof(T), m => m.Name == name, parameters);
}

/// <summary>
@@ -65,7 +65,7 @@
/// <returns>An instance of the service.</returns>
public static T Get<T>(this IResolutionRoot root, Func<IBindingMetadata,
bool> constraint, params IParameter[] parameters)
{
- return (T)root.Resolve(typeof(T), constraint, parameters).Select(hook
=> hook.Resolve()).FirstOrDefault();
+ return (T)root.Get(typeof(T), constraint, parameters);
}

/// <summary>
@@ -77,7 +77,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<T> GetAll<T>(this IResolutionRoot root, params
IParameter[] parameters)
{
- return root.Resolve(typeof(T), null, parameters).Select(hook =>
hook.Resolve()).Cast<T>();
+ return root.GetAll(typeof(T), parameters).Cast<T>();
}

/// <summary>
@@ -90,7 +90,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<T> GetAll<T>(this IResolutionRoot root, string
name, params IParameter[] parameters)
{
- return root.GetAll<T>(m => m.Name == name, parameters);
+ return root.GetAll(typeof(T), m => m.Name == name,
parameters).Cast<T>();
}

/// <summary>
@@ -103,7 +103,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<T> GetAll<T>(this IResolutionRoot root,
Func<IBindingMetadata, bool> constraint, params IParameter[] parameters)
{
- return root.Resolve(typeof(T), constraint, parameters).Select(hook =>
hook.Resolve()).Cast<T>();
+ return root.GetAll(typeof(T), constraint, parameters).Cast<T>();
}

/// <summary>
@@ -115,7 +115,7 @@
/// <returns>An instance of the service.</returns>
public static object Get(this IResolutionRoot root, Type service, params
IParameter[] parameters)
{
- return root.Resolve(service, null, parameters).Select(hook =>
hook.Resolve()).FirstOrDefault();
+ return root.GetAll(service, parameters).FirstOrDefault();
}

/// <summary>
@@ -128,7 +128,7 @@
/// <returns>An instance of the service.</returns>
public static object Get(this IResolutionRoot root, Type service, string
name, params IParameter[] parameters)
{
- return root.Get(service, m => m.Name == name, parameters);
+ return root.GetAll(service, m => m.Name == name,
parameters).FirstOrDefault();
}

/// <summary>
@@ -141,7 +141,7 @@
/// <returns>An instance of the service.</returns>
public static object Get(this IResolutionRoot root, Type service,
Func<IBindingMetadata, bool> constraint, params IParameter[] parameters)
{
- return root.Resolve(service, constraint, parameters).Select(hook =>
hook.Resolve()).FirstOrDefault();
+ return root.GetAll(service, constraint, parameters).FirstOrDefault();
}

/// <summary>
@@ -153,7 +153,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<object> GetAll(this IResolutionRoot root, Type
service, params IParameter[] parameters)
{
- return root.Resolve(service, null, parameters).Select(hook =>
hook.Resolve());
+ return root.Resolve(service, null, parameters, false).Select(hook =>
hook.Resolve());
}

/// <summary>
@@ -166,7 +166,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<object> GetAll(this IResolutionRoot root, Type
service, string name, params IParameter[] parameters)
{
- return root.GetAll(service, m => m.Name == name, parameters);
+ return root.Resolve(service, m => m.Name == name, parameters,
false).Select(hook => hook.Resolve());
}

/// <summary>
@@ -179,7 +179,7 @@
/// <returns>A series of instances of the service.</returns>
public static IEnumerable<object> GetAll(this IResolutionRoot root, Type
service, Func<IBindingMetadata, bool> constraint, params IParameter[]
parameters)
{
- return root.Resolve(service, constraint, parameters).Select(hook =>
hook.Resolve());
+ return root.Resolve(service, constraint, parameters, false).Select(hook
=> hook.Resolve());
}
}
}
Reply all
Reply to author
Forward
0 new messages