diff --git a/Telerik.JustMock/AutoMock/MockingContainer.cs b/Telerik.JustMock/AutoMock/MockingContainer.cs
index f4b8f048..595f250b 100644
--- a/Telerik.JustMock/AutoMock/MockingContainer.cs
+++ b/Telerik.JustMock/AutoMock/MockingContainer.cs
@@ -54,23 +54,23 @@ public MockingContainer(AutoMockSettings settings = null)
{
}
- ///
- /// Implementation detail.
- ///
- protected override bool ShouldAddComponent(Type component, Type implementation)
- {
- if (implementation == typeof(SelfBindingResolver))
- {
- return false;
- }
-
- return base.ShouldAddComponent(component, implementation);
- }
-
- ///
- /// Implementation detail.
- ///
- protected override void AddComponents()
+ ///
+ /// Implementation detail.
+ ///
+ protected override bool ShouldAddComponent(Type component, Type implementation)
+ {
+ if (implementation == typeof(SelfBindingResolver))
+ {
+ return false;
+ }
+
+ return base.ShouldAddComponent(component, implementation);
+ }
+
+ ///
+ /// Implementation detail.
+ ///
+ protected override void AddComponents()
{
base.AddComponents();
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/ActivationBlock.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/ActivationBlock.cs
index 3b109700..0bc6fe27 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/ActivationBlock.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/ActivationBlock.cs
@@ -1,40 +1,41 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-using Telerik.JustMock.AutoMock.Ninject.Syntax;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Blocks
{
+ using System;
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Syntax;
+
///
/// A block used for deterministic disposal of activated instances. When the block is
/// disposed, all instances activated via it will be deactivated.
///
public class ActivationBlock : DisposableObject, IActivationBlock
{
- ///
- /// Gets or sets the parent resolution root (usually the kernel).
- ///
- public IResolutionRoot Parent { get; private set; }
-
- ///
- /// Occurs when the object is disposed.
- ///
- public event EventHandler Disposed;
-
///
/// Initializes a new instance of the class.
///
@@ -42,25 +43,23 @@ public class ActivationBlock : DisposableObject, IActivationBlock
public ActivationBlock(IResolutionRoot parent)
{
Ensure.ArgumentNotNull(parent, "parent");
- Parent = parent;
+
+ this.Parent = parent;
}
///
- /// Releases resources held by the object.
+ /// Gets the parent resolution root (usually the kernel).
///
- public override void Dispose(bool disposing)
- {
- lock (this)
- {
- if (disposing && !IsDisposed)
- {
- var evt = Disposed;
- if (evt != null) evt(this, EventArgs.Empty);
- Disposed = null;
- }
+ public IResolutionRoot Parent { get; private set; }
- base.Dispose(disposing);
- }
+ ///
+ /// Injects the specified existing instance, without managing its lifecycle.
+ ///
+ /// The instance to inject.
+ /// The parameters to pass to the request.
+ public void Inject(object instance, params IParameter[] parameters)
+ {
+ this.Parent.Inject(instance, parameters);
}
///
@@ -71,6 +70,7 @@ public override void Dispose(bool disposing)
public bool CanResolve(IRequest request)
{
Ensure.ArgumentNotNull(request, "request");
+
return this.Parent.CanResolve(request);
}
@@ -85,6 +85,7 @@ public bool CanResolve(IRequest request)
public bool CanResolve(IRequest request, bool ignoreImplicitBindings)
{
Ensure.ArgumentNotNull(request, "request");
+
return this.Parent.CanResolve(request, ignoreImplicitBindings);
}
@@ -97,7 +98,8 @@ public bool CanResolve(IRequest request, bool ignoreImplicitBindings)
public IEnumerable Resolve(IRequest request)
{
Ensure.ArgumentNotNull(request, "request");
- return Parent.Resolve(request);
+
+ return this.Parent.Resolve(request);
}
///
@@ -113,6 +115,7 @@ public virtual IRequest CreateRequest(Type service, Func
{
Ensure.ArgumentNotNull(service, "service");
Ensure.ArgumentNotNull(parameters, "parameters");
+
return new Request(service, constraint, parameters, () => this, isOptional, isUnique);
}
@@ -121,10 +124,9 @@ public virtual IRequest CreateRequest(Type service, Func
///
/// The instance to release.
/// if the instance was found and released; otherwise .
- ///
public bool Release(object instance)
{
- return Parent.Release(instance);
+ return this.Parent.Release(instance);
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/IActivationBlock.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/IActivationBlock.cs
index 7c229e91..6c09c50b 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/IActivationBlock.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Blocks/IActivationBlock.cs
@@ -1,23 +1,34 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
-using Telerik.JustMock.AutoMock.Ninject.Syntax;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Blocks
{
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
+ using Telerik.JustMock.AutoMock.Ninject.Syntax;
+
///
/// A block used for deterministic disposal of activated instances. When the block is
/// disposed, all instances activated via it will be deactivated.
///
- public interface IActivationBlock : IResolutionRoot, INotifyWhenDisposed { }
+ public interface IActivationBlock : IResolutionRoot, INotifyWhenDisposed
+ {
+ }
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ActivationCache.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ActivationCache.cs
index b4da23b1..22ad78d6 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ActivationCache.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ActivationCache.cs
@@ -1,8 +1,28 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
- using System;
using System.Collections.Generic;
- using System.Linq;
+
using Telerik.JustMock.AutoMock.Ninject.Components;
using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
@@ -11,17 +31,6 @@ namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
///
public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
{
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- ///
- /// The objects that were activated as reference equal weak references.
- ///
- private readonly IDictionary activatedObjects = new Dictionary(new WeakReferenceEqualityComparer());
-
- ///
- /// The objects that were activated as reference equal weak references.
- ///
- private readonly IDictionary deactivatedObjects = new Dictionary(new WeakReferenceEqualityComparer());
-#else
///
/// The objects that were activated as reference equal weak references.
///
@@ -31,7 +40,6 @@ public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
/// The objects that were activated as reference equal weak references.
///
private readonly HashSet deactivatedObjects = new HashSet(new WeakReferenceEqualityComparer());
-#endif
///
/// Initializes a new instance of the class.
@@ -39,9 +47,10 @@ public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
/// The cache pruner.
public ActivationCache(ICachePruner cachePruner)
{
+ Ensure.ArgumentNotNull(cachePruner, "cachePruner");
cachePruner.Start(this);
}
-
+
///
/// Gets the activated object count.
///
@@ -65,7 +74,7 @@ public int DeactivatedObjectCount
return this.deactivatedObjects.Count;
}
}
-
+
///
/// Clears the cache.
///
@@ -90,11 +99,7 @@ public void AddActivatedInstance(object instance)
{
lock (this.activatedObjects)
{
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- this.activatedObjects.Add(new ReferenceEqualWeakReference(instance), true);
-#else
this.activatedObjects.Add(new ReferenceEqualWeakReference(instance));
-#endif
}
}
@@ -106,11 +111,7 @@ public void AddDeactivatedInstance(object instance)
{
lock (this.deactivatedObjects)
{
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- this.deactivatedObjects.Add(new ReferenceEqualWeakReference(instance), true);
-#else
this.deactivatedObjects.Add(new ReferenceEqualWeakReference(instance));
-#endif
}
}
@@ -123,11 +124,7 @@ public void AddDeactivatedInstance(object instance)
///
public bool IsActivated(object instance)
{
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- return this.activatedObjects.ContainsKey(instance);
-#else
return this.activatedObjects.Contains(instance);
-#endif
}
///
@@ -139,11 +136,7 @@ public bool IsActivated(object instance)
///
public bool IsDeactivated(object instance)
{
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- return this.deactivatedObjects.ContainsKey(instance);
-#else
return this.deactivatedObjects.Contains(instance);
-#endif
}
///
@@ -162,20 +155,6 @@ public void Prune()
}
}
-#if SILVERLIGHT_20 || SILVERLIGHT_30 || WINDOWS_PHONE || NETCF || MONO
- ///
- /// Removes all dead objects.
- ///
- /// The objects collection to be freed of dead objects.
- private static void RemoveDeadObjects(IDictionary objects)
- {
- var deadObjects = objects.Where(entry => !((ReferenceEqualWeakReference)entry.Key).IsAlive).ToList();
- foreach (var deadObject in deadObjects)
- {
- objects.Remove(deadObject.Key);
- }
- }
-#else
///
/// Removes all dead objects.
///
@@ -184,6 +163,5 @@ private static void RemoveDeadObjects(HashSet objects)
{
objects.RemoveWhere(reference => !((ReferenceEqualWeakReference)reference).IsAlive);
}
-#endif
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/Cache.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/Cache.cs
index 25a0857c..c2f603a5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/Cache.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/Cache.cs
@@ -1,12 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
@@ -60,10 +71,10 @@ public int Count
///
/// Releases resources held by the object.
///
- ///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
this.Clear();
}
@@ -89,8 +100,7 @@ public void Remember(IContext context, InstanceReference reference)
if (!this.entries.ContainsKey(weakScopeReference))
{
this.entries[weakScopeReference] = new Multimap();
- var notifyScope = scope as INotifyWhenDisposed;
- if (notifyScope != null)
+ if (scope is INotifyWhenDisposed notifyScope)
{
notifyScope.Disposed += (o, e) => this.Clear(weakScopeReference);
}
@@ -108,6 +118,7 @@ public void Remember(IContext context, InstanceReference reference)
public object TryGet(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
+
var scope = context.GetScope();
if (scope == null)
{
@@ -116,8 +127,7 @@ public object TryGet(IContext context)
lock (this.entries)
{
- Multimap bindings;
- if (!this.entries.TryGetValue(scope, out bindings))
+ if (!this.entries.TryGetValue(scope, out Multimap bindings))
{
return null;
}
@@ -149,7 +159,7 @@ public object TryGet(IContext context)
/// if the instance was found and released; otherwise .
public bool Release(object instance)
{
- lock(this.entries)
+ lock (this.entries)
{
var instanceFound = false;
foreach (var bindingEntry in this.entries.Values.SelectMany(bindingEntries => bindingEntries.Values).ToList())
@@ -177,8 +187,8 @@ public void Prune()
var disposedScopes = this.entries.Where(scope => !((ReferenceEqualWeakReference)scope.Key).IsAlive).Select(scope => scope).ToList();
foreach (var disposedScope in disposedScopes)
{
- this.Forget(GetAllBindingEntries(disposedScope.Value));
this.entries.Remove(disposedScope.Key);
+ this.Forget(GetAllBindingEntries(disposedScope.Value));
}
}
}
@@ -192,11 +202,10 @@ public void Clear(object scope)
{
lock (this.entries)
{
- Multimap bindings;
- if (this.entries.TryGetValue(scope, out bindings))
+ if (this.entries.TryGetValue(scope, out Multimap bindings))
{
- this.Forget(GetAllBindingEntries(bindings));
this.entries.Remove(scope);
+ this.Forget(GetAllBindingEntries(bindings));
}
}
}
@@ -214,13 +223,13 @@ public void Clear()
}
///
- /// Gets all entries for a binding withing the selected scope.
+ /// Gets all entries for a binding within the selected scope.
///
/// The bindings.
/// All bindings of a binding.
- private static IEnumerable GetAllBindingEntries(IEnumerable>> bindings)
+ private static IEnumerable GetAllBindingEntries(Multimap bindings)
{
- return bindings.SelectMany(bindingEntries => bindingEntries.Value);
+ return bindings.Values.SelectMany(bindingEntries => bindingEntries);
}
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
index 60e4a588..a4f3b748 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
using System;
using System.Collections.Generic;
using System.Threading;
+
using Telerik.JustMock.AutoMock.Ninject.Components;
using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
@@ -27,25 +39,29 @@ public class GarbageCollectionCachePruner : NinjectComponent, ICachePruner
/// indicator for if GC has been run.
///
private readonly WeakReference indicator = new WeakReference(new object());
-
+
///
/// The caches that are being pruned.
///
private readonly List caches = new List();
///
- /// The timer used to trigger the cache pruning
+ /// The timer used to trigger the cache pruning.
///
private Timer timer;
+ ///
+ /// The flag to indicate whether the cache pruning is stopped or not.
+ ///
private bool stop;
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed && this.timer != null)
+ if (disposing && !this.IsDisposed && this.timer != null)
{
this.Stop();
}
@@ -80,13 +96,8 @@ public void Stop()
using (var signal = new ManualResetEvent(false))
{
-#if !NETCF
this.timer.Dispose(signal);
signal.WaitOne();
-#else
- this.timer.Dispose();
-#endif
-
this.timer = null;
this.caches.Clear();
}
@@ -120,7 +131,7 @@ private void PruneCacheIfGarbageCollectorHasRun(object state)
private int GetTimeoutInMilliseconds()
{
- TimeSpan interval = Settings.CachePruningInterval;
+ var interval = this.Settings.CachePruningInterval;
return interval == TimeSpan.MaxValue ? -1 : (int)interval.TotalMilliseconds;
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IActivationCache.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IActivationCache.cs
index 728363ad..c1729b5e 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IActivationCache.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IActivationCache.cs
@@ -1,4 +1,25 @@
-namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
+namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
using Telerik.JustMock.AutoMock.Ninject.Components;
@@ -23,7 +44,7 @@ public interface IActivationCache : INinjectComponent
///
/// The instance to be added.
void AddDeactivatedInstance(object instance);
-
+
///
/// Determines whether the specified instance is activated.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICache.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICache.cs
index 2f74f6d0..83c0c24d 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICache.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICache.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Tracks instances for re-use in certain scopes.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICachePruner.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICachePruner.cs
index a3be302d..7d6b1349 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICachePruner.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/ICachePruner.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Prunes instances from an based on environmental information.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IPruneable.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IPruneable.cs
index dc5e2fd0..df233b8f 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IPruneable.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/IPruneable.cs
@@ -1,7 +1,28 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
///
- /// An object that is prunealble.
+ /// An object that is pruneable.
///
public interface IPruneable
{
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
index 865e002f..13e79874 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
@@ -1,3 +1,24 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
{
using System.Collections.Generic;
@@ -11,7 +32,7 @@ namespace Telerik.JustMock.AutoMock.Ninject.Activation.Caching
public class WeakReferenceEqualityComparer : IEqualityComparer
{
///
- /// Returns if the specifed objects are equal.
+ /// Returns if the specified objects are equal.
///
/// The first object.
/// The second object.
@@ -29,12 +50,7 @@ public class WeakReferenceEqualityComparer : IEqualityComparer
public int GetHashCode(object obj)
{
var weakReference = obj as ReferenceEqualWeakReference;
- return weakReference != null ? weakReference.GetHashCode() :
-#if !NETCF
- RuntimeHelpers.GetHashCode(obj);
-#else
- obj.GetHashCode();
-#endif
+ return weakReference != null ? weakReference.GetHashCode() : RuntimeHelpers.GetHashCode(obj);
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Context.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Context.cs
index 7fe83c69..790c2099 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Context.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Context.cs
@@ -1,45 +1,91 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+
///
/// Contains information about the activation of a single instance.
///
public class Context : IContext
{
- private WeakReference cachedScope;
+ private object cachedScope;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The kernel managing the resolution.
+ /// The context's request.
+ /// The context's binding.
+ /// The cache component.
+ /// The planner component.
+ /// The pipeline component.
+ public Context(IKernel kernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)
+ {
+ Ensure.ArgumentNotNull(kernel, "kernel");
+ Ensure.ArgumentNotNull(request, "request");
+ Ensure.ArgumentNotNull(binding, "binding");
+ Ensure.ArgumentNotNull(cache, "cache");
+ Ensure.ArgumentNotNull(planner, "planner");
+ Ensure.ArgumentNotNull(pipeline, "pipeline");
+
+ this.Kernel = kernel;
+ this.Request = request;
+ this.Binding = binding;
+ this.Parameters = request.Parameters.Union(binding.Parameters).ToList();
+
+ this.Cache = cache;
+ this.Planner = planner;
+ this.Pipeline = pipeline;
+
+ if (binding.Service.IsGenericTypeDefinition)
+ {
+ this.HasInferredGenericArguments = true;
+ this.GenericArguments = request.Service.GenericTypeArguments;
+ }
+ }
///
- /// Gets the kernel that is driving the activation.
+ /// Gets or sets the kernel that is driving the activation.
///
public IKernel Kernel { get; set; }
///
- /// Gets the request.
+ /// Gets or sets the request.
///
public IRequest Request { get; set; }
///
- /// Gets the binding.
+ /// Gets or sets the binding.
///
public IBinding Binding { get; set; }
@@ -49,7 +95,7 @@ public class Context : IContext
public IPlan Plan { get; set; }
///
- /// Gets the parameters that were passed to manipulate the activation process.
+ /// Gets or sets the parameters that were passed to manipulate the activation process.
///
public ICollection Parameters { get; set; }
@@ -64,67 +110,27 @@ public class Context : IContext
public bool HasInferredGenericArguments { get; private set; }
///
- /// Gets or sets the cache component.
+ /// Gets the cache component.
///
public ICache Cache { get; private set; }
///
- /// Gets or sets the planner component.
+ /// Gets the planner component.
///
public IPlanner Planner { get; private set; }
///
- /// Gets or sets the pipeline component.
+ /// Gets the pipeline component.
///
public IPipeline Pipeline { get; private set; }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The kernel managing the resolution.
- /// The context's request.
- /// The context's binding.
- /// The cache component.
- /// The planner component.
- /// The pipeline component.
- public Context(IKernel kernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)
- {
- Ensure.ArgumentNotNull(kernel, "kernel");
- Ensure.ArgumentNotNull(request, "request");
- Ensure.ArgumentNotNull(binding, "binding");
- Ensure.ArgumentNotNull(cache, "cache");
- Ensure.ArgumentNotNull(planner, "planner");
- Ensure.ArgumentNotNull(pipeline, "pipeline");
-
- Kernel = kernel;
- Request = request;
- Binding = binding;
- Parameters = request.Parameters.Union(binding.Parameters).ToList();
-
- Cache = cache;
- Planner = planner;
- Pipeline = pipeline;
-
- if (binding.Service.IsGenericTypeDefinition)
- {
- HasInferredGenericArguments = true;
- GenericArguments = request.Service.GetGenericArguments();
- }
- }
-
///
/// Gets the scope for the context that "owns" the instance activated therein.
///
/// The object that acts as the scope.
public object GetScope()
{
- if (this.cachedScope == null)
- {
- var scope = this.Request.GetScope() ?? this.Binding.GetScope(this);
- this.cachedScope = new WeakReference(scope);
- }
-
- return this.cachedScope.Target;
+ return this.cachedScope ?? this.Request.GetScope() ?? this.Binding.GetScope(this);
}
///
@@ -133,7 +139,7 @@ public object GetScope()
/// The provider that should be used.
public IProvider GetProvider()
{
- return Binding.GetProvider(this);
+ return this.Binding.GetProvider(this);
}
///
@@ -142,47 +148,112 @@ public IProvider GetProvider()
/// The resolved instance.
public object Resolve()
{
- lock (Binding)
+ if (this.Request.ActiveBindings.Contains(this.Binding) &&
+ this.IsCyclical(this.Request.ParentContext))
+ {
+ throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
+ }
+
+ try
+ {
+ this.cachedScope = this.Request.GetScope() ?? this.Binding.GetScope(this);
+
+ if (this.cachedScope != null)
+ {
+ lock (this.cachedScope)
+ {
+ return this.ResolveInternal(this.cachedScope);
+ }
+ }
+ else
+ {
+ return this.ResolveInternal(null);
+ }
+ }
+ finally
{
- if (Request.ActiveBindings.Contains(Binding))
- throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
+ this.cachedScope = null;
+ }
+ }
- var cachedInstance = Cache.TryGet(this);
+ private object ResolveInternal(object scope)
+ {
+ var cachedInstance = this.Cache.TryGet(this);
- if (cachedInstance != null)
- return cachedInstance;
+ if (cachedInstance != null)
+ {
+ return cachedInstance;
+ }
- Request.ActiveBindings.Push(Binding);
+ this.Request.ActiveBindings.Push(this.Binding);
- var reference = new InstanceReference { Instance = GetProvider().Create(this) };
+ var reference = new InstanceReference { Instance = this.GetProvider().Create(this) };
- Request.ActiveBindings.Pop();
+ this.Request.ActiveBindings.Pop();
- if (reference.Instance == null)
+ if (reference.Instance == null)
+ {
+ if (!this.Kernel.Settings.AllowNullInjection)
{
- if (!this.Kernel.Settings.AllowNullInjection)
- {
- throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));
- }
+ throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));
+ }
- if (this.Plan == null)
- {
- this.Plan = this.Planner.GetPlan(this.Request.Service);
- }
+ if (this.Plan == null)
+ {
+ this.Plan = this.Planner.GetPlan(this.Request.Service);
+ }
+
+ return null;
+ }
- return null;
+ if (scope != null)
+ {
+ this.Cache.Remember(this, reference);
+ }
+
+ if (this.Plan == null)
+ {
+ this.Plan = this.Planner.GetPlan(reference.Instance.GetType());
+ }
+
+ try
+ {
+ this.Pipeline.Activate(this, reference);
+ }
+ catch (ActivationException)
+ {
+ if (scope != null)
+ {
+ this.Cache.Release(reference.Instance);
}
- if (GetScope() != null)
- Cache.Remember(this, reference);
+ throw;
+ }
+
+ return reference.Instance;
+ }
- if (Plan == null)
- Plan = Planner.GetPlan(reference.Instance.GetType());
+ private bool IsCyclical(IContext targetContext)
+ {
+ if (targetContext == null)
+ {
+ return false;
+ }
- Pipeline.Activate(this, reference);
+ if (targetContext.Request.Service == this.Request.Service)
+ {
+ if ((this.Request.Target is ParameterTarget && targetContext.Request.Target is ParameterTarget) || targetContext.GetScope() != this.GetScope() || this.GetScope() == null)
+ {
+ return true;
+ }
+ }
- return reference.Instance;
+ if (this.IsCyclical(targetContext.Request.ParentContext))
+ {
+ return true;
}
+
+ return false;
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/IContext.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/IContext.cs
index e8d4a22c..e3577d3f 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/IContext.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/IContext.cs
@@ -1,22 +1,34 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+
///
/// Contains information about the activation of a single instance.
///
@@ -42,6 +54,11 @@ public interface IContext
///
IPlan Plan { get; set; }
+ ///
+ /// Gets the cache component.
+ ///
+ ICache Cache { get; }
+
///
/// Gets the parameters that were passed to manipulate the activation process.
///
@@ -75,4 +92,4 @@ public interface IContext
/// The resolved instance.
object Resolve();
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/IPipeline.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/IPipeline.cs
index 7205b292..c6f21dfe 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/IPipeline.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/IPipeline.cs
@@ -1,21 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Activation.Strategies;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation.Strategies;
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Drives the activation (injection, etc.) of an instance.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider.cs
index b553fe3a..64dd4d5c 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider.cs
@@ -1,18 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+
///
/// Creates instances of services.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider{T}.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider{T}.cs
index 4eb8ab7b..e4353729 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider{T}.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/IProvider{T}.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
@@ -26,6 +26,6 @@ namespace Telerik.JustMock.AutoMock.Ninject.Activation
///
/// The type provides by this implementation.
public interface IProvider : IProvider
- {
+ {
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/IRequest.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/IRequest.cs
index eaeebfbf..bde0e574 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/IRequest.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/IRequest.cs
@@ -1,23 +1,33 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
-using Telerik.JustMock.AutoMock.Ninject.Syntax;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+
///
/// Describes the request for a service resolution.
///
@@ -64,15 +74,22 @@ public interface IRequest
int Depth { get; }
///
- /// Gets or sets value indicating whether the request is optional.
+ /// Gets or sets a value indicating whether the request is optional.
///
bool IsOptional { get; set; }
///
- /// Gets or sets value indicating whether the request should return a unique result.
+ /// Gets or sets a value indicating whether the request should return a unique result.
///
bool IsUnique { get; set; }
+ ///
+ /// Gets or sets a value indicating whether the request should force to return a unique value even if the request is optional.
+ /// If this value is set true the request will throw an ActivationException if there are multiple satisfying bindings rather
+ /// than returning null for the request is optional. For none optional requests this parameter does not change anything.
+ ///
+ bool ForceUnique { get; set; }
+
///
/// Determines whether the specified binding satisfies the constraint defined on this request.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/InstanceReference.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/InstanceReference.cs
index a94cfec9..4a732533 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/InstanceReference.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/InstanceReference.cs
@@ -1,22 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+ using System.Security;
+
///
/// Holds an instance during activation or after it has been cached.
///
@@ -32,9 +39,17 @@ public class InstanceReference
///
/// The type in question.
/// if the instance is of the specified type, otherwise .
+ [SecuritySafeCritical]
public bool Is()
{
- return Instance is T;
+#if !NO_REMOTING
+ if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(this.Instance)
+ && System.Runtime.Remoting.RemotingServices.GetRealProxy(this.Instance).GetType().Name == "RemotingProxy")
+ {
+ return typeof(T).IsAssignableFrom(this.Instance.GetType());
+ }
+#endif
+ return this.Instance is T;
}
///
@@ -44,7 +59,7 @@ public bool Is()
/// The instance.
public T As()
{
- return (T)Instance;
+ return (T)this.Instance;
}
///
@@ -54,8 +69,10 @@ public T As()
/// The action to execute.
public void IfInstanceIs(Action action)
{
- if (Instance is T)
- action((T)Instance);
+ if (this.Is())
+ {
+ action((T)this.Instance);
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Pipeline.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Pipeline.cs
index fde8a8ae..13ca8a10 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Pipeline.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Pipeline.cs
@@ -1,17 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
using System.Collections.Generic;
using System.Linq;
+
using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
using Telerik.JustMock.AutoMock.Ninject.Activation.Strategies;
using Telerik.JustMock.AutoMock.Ninject.Components;
@@ -36,6 +48,8 @@ public class Pipeline : NinjectComponent, IPipeline
public Pipeline(IEnumerable strategies, IActivationCache activationCache)
{
Ensure.ArgumentNotNull(strategies, "strategies");
+ Ensure.ArgumentNotNull(activationCache, "activationCache");
+
this.Strategies = strategies.ToList();
this.activationCache = activationCache;
}
@@ -53,6 +67,8 @@ public Pipeline(IEnumerable strategies, IActivationCache ac
public void Activate(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
+ Ensure.ArgumentNotNull(reference, "reference");
+
if (!this.activationCache.IsActivated(reference.Instance))
{
this.Strategies.Map(s => s.Activate(context, reference));
@@ -67,6 +83,8 @@ public void Activate(IContext context, InstanceReference reference)
public void Deactivate(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
+ Ensure.ArgumentNotNull(reference, "reference");
+
if (!this.activationCache.IsDeactivated(reference.Instance))
{
this.Strategies.Map(s => s.Deactivate(context, reference));
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Provider.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Provider.cs
index a67889a1..6e61ac36 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Provider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Provider.cs
@@ -1,16 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
using System;
+
using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
///
@@ -35,6 +47,7 @@ public virtual Type Type
public object Create(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
+
return this.CreateInstance(context);
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/CallbackProvider.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/CallbackProvider.cs
index 58cba4de..7b022b11 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/CallbackProvider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/CallbackProvider.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Providers
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+
///
/// A provider that delegates to a callback method to create instances.
///
@@ -21,20 +32,21 @@ namespace Telerik.JustMock.AutoMock.Ninject.Activation.Providers
public class CallbackProvider : Provider
{
///
- /// Gets the callback method used by the provider.
- ///
- public Func Method { get; private set; }
-
- ///
- /// Initializes a new instance of the CallbackProvider<T> class.
+ /// Initializes a new instance of the class.
///
/// The callback method that will be called to create instances.
public CallbackProvider(Func method)
{
Ensure.ArgumentNotNull(method, "method");
- Method = method;
+
+ this.Method = method;
}
+ ///
+ /// Gets the callback method used by the provider.
+ ///
+ public Func Method { get; private set; }
+
///
/// Invokes the callback method to create an instance.
///
@@ -42,7 +54,7 @@ public CallbackProvider(Func method)
/// The created instance.
protected override T CreateInstance(IContext context)
{
- return Method(context);
+ return this.Method(context);
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/ConstantProvider.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/ConstantProvider.cs
index 908a4ebf..ff6a4ec6 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/ConstantProvider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/ConstantProvider.cs
@@ -1,16 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Providers
{
@@ -21,19 +28,19 @@ namespace Telerik.JustMock.AutoMock.Ninject.Activation.Providers
public class ConstantProvider : Provider
{
///
- /// Gets the value that the provider will return.
- ///
- public T Value { get; private set; }
-
- ///
- /// Initializes a new instance of the ConstantProvider<T> class.
+ /// Initializes a new instance of the class.
///
/// The value that the provider should return.
public ConstantProvider(T value)
{
- Value = value;
+ this.Value = value;
}
+ ///
+ /// Gets the value that the provider will return.
+ ///
+ public T Value { get; private set; }
+
///
/// Creates an instance within the specified context.
///
@@ -41,7 +48,7 @@ public ConstantProvider(T value)
/// The constant value this provider returns.
protected override T CreateInstance(IContext context)
{
- return Value;
+ return this.Value;
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/StandardProvider.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/StandardProvider.cs
index 90179d26..c5f963e3 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/StandardProvider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Providers/StandardProvider.cs
@@ -1,67 +1,103 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Linq;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
-using Telerik.JustMock.AutoMock.Ninject.Selection;
-
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Providers
{
+ using System;
+ using System.Linq;
using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+ using Telerik.JustMock.AutoMock.Ninject.Selection;
using Telerik.JustMock.AutoMock.Ninject.Selection.Heuristics;
- using Telerik.JustMock.Core;
+ using Telerik.JustMock.Core;
///
/// The standard provider for types, which activates instances via a .
///
public class StandardProvider : IProvider
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type (or prototype) of instances the provider creates.
+ /// The planner component.
+ /// The constructor scorer component.
+ public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer)
+ {
+ Ensure.ArgumentNotNull(type, "type");
+ Ensure.ArgumentNotNull(planner, "planner");
+ Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");
+
+ this.Type = type;
+ this.Planner = planner;
+ this.ConstructorScorer = constructorScorer;
+ }
+
///
/// Gets the type (or prototype) of instances the provider creates.
///
public Type Type { get; private set; }
///
- /// Gets or sets the planner component.
+ /// Gets the planner component.
///
public IPlanner Planner { get; private set; }
///
- /// Gets or sets the selector component.
+ /// Gets the constructor scorer component.
///
public IConstructorScorer ConstructorScorer { get; private set; }
///
- /// Initializes a new instance of the class.
+ /// Gets a callback that creates an instance of the
+ /// for the specified type.
///
- /// The type (or prototype) of instances the provider creates.
- /// The planner component.
- /// The constructor scorer component.
- public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer
- )
+ /// The prototype the provider instance will create.
+ /// The created callback.
+ public static Func GetCreationCallback(Type prototype)
{
- Ensure.ArgumentNotNull(type, "type");
- Ensure.ArgumentNotNull(planner, "planner");
- Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");
+ Ensure.ArgumentNotNull(prototype, "prototype");
- Type = type;
- Planner = planner;
- ConstructorScorer = constructorScorer;
+ return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get(), ctx.Kernel.Components.Get().ConstructorScorer);
+ }
+
+ ///
+ /// Gets a callback that creates an instance of the
+ /// for the specified type and constructor.
+ ///
+ /// The prototype the provider instance will create.
+ /// The constructor.
+ /// The created callback.
+ public static Func GetCreationCallback(Type prototype, ConstructorInfo constructor)
+ {
+ Ensure.ArgumentNotNull(prototype, "prototype");
+
+ return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get(), new SpecificConstructorSelector(constructor));
}
///
@@ -78,25 +114,18 @@ public virtual object Create(IContext context)
context.Plan = this.Planner.GetPlan(this.GetImplementationType(context.Request.Service));
}
- if (!context.Plan.Has())
- {
- throw new ActivationException(ExceptionFormatter.NoConstructorsAvailable(context));
- }
+ var directive = this.DetermineConstructorInjectionDirective(context);
+
+ var arguments = directive.Targets.Select(target => this.GetValue(context, target)).ToArray();
- var directives = context.Plan.GetAll();
- var bestDirectives = directives
- .GroupBy(option => this.ConstructorScorer.Score(context, option))
- .OrderByDescending(g => g.Key)
- .First();
- if (bestDirectives.Skip(1).Any())
+ var cachedInstance = context.Cache.TryGet(context);
+
+ if (cachedInstance != null)
{
- throw new ActivationException(ExceptionFormatter.ConstructorsAmbiguous(context, bestDirectives));
+ return cachedInstance;
}
- var directive = bestDirectives.Single();
- var arguments = directive.Targets.Select(target => this.GetValue(context, target)).ToArray();
- var injector = directive.Injector;
- return ProfilerInterceptor.GuardExternal(() => injector(arguments));
+ return ProfilerInterceptor.GuardExternal(() => directive.Injector(arguments));
}
///
@@ -112,7 +141,7 @@ public object GetValue(IContext context, ITarget target)
var parameter = context
.Parameters.OfType()
- .Where(p => p.AppliesToTarget(context, target)).SingleOrDefault();
+ .SingleOrDefault(p => p.AppliesToTarget(context, target));
return parameter != null ? parameter.GetValue(context, target) : target.ResolveWithin(context);
}
@@ -125,32 +154,30 @@ public object GetValue(IContext context, ITarget target)
public Type GetImplementationType(Type service)
{
Ensure.ArgumentNotNull(service, "service");
- return Type.ContainsGenericParameters ? Type.MakeGenericType(service.GetGenericArguments()) : Type;
- }
- ///
- /// Gets a callback that creates an instance of the
- /// for the specified type.
- ///
- /// The prototype the provider instance will create.
- /// The created callback.
- public static Func GetCreationCallback(Type prototype)
- {
- Ensure.ArgumentNotNull(prototype, "prototype");
- return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get(), ctx.Kernel.Components.Get().ConstructorScorer);
+ return this.Type.ContainsGenericParameters ? this.Type.MakeGenericType(service.GetGenericArguments()) : this.Type;
}
- ///
- /// Gets a callback that creates an instance of the
- /// for the specified type and constructor.
- ///
- /// The prototype the provider instance will create.
- /// The constructor.
- /// The created callback.
- public static Func GetCreationCallback(Type prototype, ConstructorInfo constructor)
+ private ConstructorInjectionDirective DetermineConstructorInjectionDirective(IContext context)
{
- Ensure.ArgumentNotNull(prototype, "prototype");
- return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get(), new SpecificConstructorSelector(constructor));
+ var directives = context.Plan.ConstructorInjectionDirectives;
+ if (directives.Count == 1)
+ {
+ return directives[0];
+ }
+
+ var bestDirectives =
+ directives
+ .GroupBy(option => this.ConstructorScorer.Score(context, option))
+ .OrderByDescending(g => g.Key)
+ .FirstOrDefault();
+ if (bestDirectives == null)
+ {
+ throw new ActivationException(ExceptionFormatter.NoConstructorsAvailable(context));
+ }
+
+ return bestDirectives.SingleOrThrowException(
+ () => new ActivationException(ExceptionFormatter.ConstructorsAmbiguous(context, bestDirectives)));
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Request.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Request.cs
index 0330c786..0ab68685 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Request.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Request.cs
@@ -1,29 +1,82 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+
///
/// Describes the request for a service resolution.
///
public class Request : IRequest
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The service that was requested.
+ /// The constraint that will be applied to filter the bindings used for the request.
+ /// The parameters that affect the resolution.
+ /// The scope callback, if an external scope was specified.
+ /// True if the request is optional; otherwise, false .
+ /// True if the request should return a unique result; otherwise, false .
+ public Request(Type service, Func constraint, IEnumerable parameters, Func scopeCallback, bool isOptional, bool isUnique)
+ {
+ this.Service = service;
+ this.Constraint = constraint;
+ this.Parameters = parameters.ToList();
+ this.ScopeCallback = scopeCallback;
+ this.ActiveBindings = new Stack();
+ this.Depth = 0;
+ this.IsOptional = isOptional;
+ this.IsUnique = isUnique;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The parent context.
+ /// The service that was requested.
+ /// The target that will receive the injection.
+ /// The scope callback, if an external scope was specified.
+ public Request(IContext parentContext, Type service, ITarget target, Func scopeCallback)
+ {
+ this.ParentContext = parentContext;
+ this.ParentRequest = parentContext.Request;
+ this.Service = service;
+ this.Target = target;
+ this.Constraint = target.Constraint;
+ this.IsOptional = target.IsOptional;
+ this.Parameters = parentContext.Parameters.Where(p => p.ShouldInherit).ToList();
+ this.ScopeCallback = scopeCallback;
+ this.ActiveBindings = new Stack(this.ParentRequest.ActiveBindings);
+ this.Depth = this.ParentRequest.Depth + 1;
+ }
+
///
/// Gets the service that was requested.
///
@@ -65,12 +118,12 @@ public class Request : IRequest
public int Depth { get; private set; }
///
- /// Gets or sets value indicating whether the request is optional.
+ /// Gets or sets a value indicating whether the request is optional.
///
public bool IsOptional { get; set; }
///
- /// Gets or sets value indicating whether the request is for a single service.
+ /// Gets or sets a value indicating whether the request is for a single service.
///
public bool IsUnique
{
@@ -78,58 +131,19 @@ public bool IsUnique
}
///
- /// Gets the callback that resolves the scope for the request, if an external scope was provided.
+ /// Gets or sets a value indicating whether the request should force to return a unique value even if the request is optional.
+ /// If this value is set true the request will throw an ActivationException if there are multiple satisfying bindings rather
+ /// than returning null for the request is optional. For none optional requests this parameter does not change anything.
///
- public Func ScopeCallback { get; private set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The service that was requested.
- /// The constraint that will be applied to filter the bindings used for the request.
- /// The parameters that affect the resolution.
- /// The scope callback, if an external scope was specified.
- /// True if the request is optional; otherwise, false .
- /// True if the request should return a unique result; otherwise, false .
- public Request(Type service, Func constraint, IEnumerable parameters, Func scopeCallback, bool isOptional, bool isUnique)
+ public bool ForceUnique
{
- Ensure.ArgumentNotNull(service, "service");
- Ensure.ArgumentNotNull(parameters, "parameters");
-
- Service = service;
- Constraint = constraint;
- Parameters = parameters.ToList();
- ScopeCallback = scopeCallback;
- ActiveBindings = new Stack();
- Depth = 0;
- IsOptional = isOptional;
- IsUnique = isUnique;
+ get; set;
}
///
- /// Initializes a new instance of the class.
+ /// Gets the callback that resolves the scope for the request, if an external scope was provided.
///
- /// The parent context.
- /// The service that was requested.
- /// The target that will receive the injection.
- /// The scope callback, if an external scope was specified.
- public Request(IContext parentContext, Type service, ITarget target, Func scopeCallback)
- {
- Ensure.ArgumentNotNull(parentContext, "parentContext");
- Ensure.ArgumentNotNull(service, "service");
- Ensure.ArgumentNotNull(target, "target");
-
- ParentContext = parentContext;
- ParentRequest = parentContext.Request;
- Service = service;
- Target = target;
- Constraint = target.Constraint;
- IsOptional = target.IsOptional;
- Parameters = parentContext.Parameters.Where(p => p.ShouldInherit).ToList();
- ScopeCallback = scopeCallback;
- ActiveBindings = new Stack(ParentRequest.ActiveBindings);
- Depth = ParentRequest.Depth + 1;
- }
+ public Func ScopeCallback { get; private set; }
///
/// Determines whether the specified binding satisfies the constraints defined on this request.
@@ -138,7 +152,7 @@ public Request(IContext parentContext, Type service, ITarget target, FuncTrue if the binding satisfies the constraints; otherwise false .
public bool Matches(IBinding binding)
{
- return Constraint == null || Constraint(binding.Metadata);
+ return this.Constraint == null || this.Constraint(binding.Metadata);
}
///
@@ -147,7 +161,7 @@ public bool Matches(IBinding binding)
/// The object that acts as the scope.
public object GetScope()
{
- return ScopeCallback == null ? null : ScopeCallback();
+ return this.ScopeCallback == null ? null : this.ScopeCallback();
}
///
@@ -159,7 +173,16 @@ public object GetScope()
/// The child request.
public IRequest CreateChild(Type service, IContext parentContext, ITarget target)
{
- return new Request(parentContext, service, target, ScopeCallback);
+ return new Request(parentContext, service, target, this.ScopeCallback);
+ }
+
+ ///
+ /// Formats this object into a meaningful string representation.
+ ///
+ /// The request formatted as string.
+ public override string ToString()
+ {
+ return this.Format();
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationCacheStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
index 35a3e244..07ec230b 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
@@ -1,11 +1,34 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
///
/// Adds all activated instances to the activation cache.
///
- public class ActivationCacheStrategy : IActivationStrategy
+ public class ActivationCacheStrategy : NinjectComponent, IActivationStrategy
{
///
/// The activation cache.
@@ -18,20 +41,9 @@ public class ActivationCacheStrategy : IActivationStrategy
/// The activation cache.
public ActivationCacheStrategy(IActivationCache activationCache)
{
- this.activationCache = activationCache;
- }
+ Ensure.ArgumentNotNull(activationCache, "activationCache");
- ///
- /// Gets or sets the settings.
- ///
- /// The ninject settings.
- public INinjectSettings Settings { get; set; }
-
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///
- public void Dispose()
- {
+ this.activationCache = activationCache;
}
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationStrategy.cs
index 67d2dea8..f62ebc13 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/ActivationStrategy.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Contributes to a , and is called during the activation
/// and deactivation of an instance.
@@ -25,13 +34,17 @@ public abstract class ActivationStrategy : NinjectComponent, IActivationStrategy
///
/// The context.
/// A reference to the instance being activated.
- public virtual void Activate(IContext context, InstanceReference reference) { }
+ public virtual void Activate(IContext context, InstanceReference reference)
+ {
+ }
///
/// Contributes to the deactivation of the instance in the specified context.
///
/// The context.
/// A reference to the instance being deactivated.
- public virtual void Deactivate(IContext context, InstanceReference reference) { }
+ public virtual void Deactivate(IContext context, InstanceReference reference)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/BindingActionStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/BindingActionStrategy.cs
index a8c4d50a..4e9caabe 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/BindingActionStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/BindingActionStrategy.cs
@@ -1,20 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
+
///
/// Executes actions defined on the binding during activation and deactivation.
///
@@ -28,6 +37,7 @@ public class BindingActionStrategy : ActivationStrategy
public override void Activate(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
+
context.Binding.ActivationActions.Map(action => action(context, reference.Instance));
}
@@ -39,6 +49,7 @@ public override void Activate(IContext context, InstanceReference reference)
public override void Deactivate(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
+
context.Binding.DeactivationActions.Map(action => action(context, reference.Instance));
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/DisposableStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/DisposableStrategy.cs
index 66f70d61..7713f62d 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/DisposableStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/DisposableStrategy.cs
@@ -1,18 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using System;
+
///
/// During deactivation, disposes instances that implement .
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/IActivationStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/IActivationStrategy.cs
index f2777588..032d052a 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/IActivationStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/IActivationStrategy.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Contributes to a , and is called during the activation
/// and deactivation of an instance.
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/InitializableStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/InitializableStrategy.cs
index a87a6f3c..51c05631 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/InitializableStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/InitializableStrategy.cs
@@ -1,15 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/MethodInjectionStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
index 3f9a2eaa..c9098e66 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
@@ -1,22 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Linq;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Injection;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using System.Linq;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
+
///
/// Injects methods on an instance during activation.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
index e9be9bbf..309985e5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
@@ -1,28 +1,38 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
-using Telerik.JustMock.AutoMock.Ninject.Injection;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
+ using Telerik.JustMock.AutoMock.Ninject.Injection;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Directives;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+
///
/// Injects properties on an instance during activation.
///
@@ -30,30 +40,30 @@ public class PropertyInjectionStrategy : ActivationStrategy
{
private const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance;
- private BindingFlags Flags
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The injector factory component.
+ public PropertyInjectionStrategy(IInjectorFactory injectorFactory)
{
- get
- {
- #if !NO_LCG && !SILVERLIGHT
- return Settings.InjectNonPublic ? (DefaultFlags | BindingFlags.NonPublic) : DefaultFlags;
- #else
- return DefaultFlags;
- #endif
- }
+ this.InjectorFactory = injectorFactory;
}
///
- /// Gets the injector factory component.
+ /// Gets or sets the injector factory component.
///
public IInjectorFactory InjectorFactory { get; set; }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The injector factory component.
- public PropertyInjectionStrategy(IInjectorFactory injectorFactory)
+ private BindingFlags Flags
{
- this.InjectorFactory = injectorFactory;
+ get
+ {
+#if !NO_LCG
+ return this.Settings.InjectNonPublic ? (DefaultFlags | BindingFlags.NonPublic) : DefaultFlags;
+#else
+ return DefaultFlags;
+#endif
+ }
}
///
@@ -71,11 +81,11 @@ public override void Activate(IContext context, InstanceReference reference)
foreach (var directive in context.Plan.GetAll())
{
- object value = this.GetValue(context, directive.Target, propertyValues);
+ var value = this.GetValue(context, directive.Target, propertyValues);
directive.Injector(reference.Instance, value);
}
- this.AssignProperyOverrides(context, reference, propertyValues);
+ this.AssignPropertyOverrides(context, reference, propertyValues);
}
///
@@ -84,12 +94,13 @@ public override void Activate(IContext context, InstanceReference reference)
/// The context.
/// A reference to the instance being activated.
/// The parameter override value accessors.
- private void AssignProperyOverrides(IContext context, InstanceReference reference, IList propertyValues)
+ private void AssignPropertyOverrides(IContext context, InstanceReference reference, IList propertyValues)
{
var properties = reference.Instance.GetType().GetProperties(this.Flags);
+
foreach (var propertyValue in propertyValues)
{
- string propertyName = propertyValue.Name;
+ var propertyName = propertyValue.Name;
var propertyInfo = properties.FirstOrDefault(property => string.Equals(property.Name, propertyName, StringComparison.Ordinal));
if (propertyInfo == null)
@@ -98,7 +109,7 @@ private void AssignProperyOverrides(IContext context, InstanceReference referenc
}
var target = new PropertyInjectionDirective(propertyInfo, this.InjectorFactory.Create(propertyInfo));
- object value = this.GetValue(context, target.Target, propertyValues);
+ var value = this.GetValue(context, target.Target, propertyValues);
target.Injector(reference.Instance, value);
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/StartableStrategy.cs b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/StartableStrategy.cs
index d0b53fd2..da0eea35 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/StartableStrategy.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Activation/Strategies/StartableStrategy.cs
@@ -1,15 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Activation.Strategies
{
diff --git a/Telerik.JustMock/AutoMock/Ninject/ActivationException.cs b/Telerik.JustMock/AutoMock/Ninject/ActivationException.cs
index 20c1a37d..9129a1aa 100644
--- a/Telerik.JustMock/AutoMock/Ninject/ActivationException.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/ActivationException.cs
@@ -1,54 +1,69 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#if !NO_EXCEPTION_SERIALIZATION
-using System.Runtime.Serialization;
-#endif
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+ using System.Runtime.Serialization;
+
///
- /// Indicates that an error occured during activation of an instance.
+ /// Indicates that an error occurred during activation of an instance.
///
- #if !NO_EXCEPTION_SERIALIZATION
[Serializable]
- #endif
public class ActivationException : Exception
{
///
/// Initializes a new instance of the class.
///
- public ActivationException() { }
+ public ActivationException()
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The exception message.
- public ActivationException(string message) : base(message) { }
+ public ActivationException(string message)
+ : base(message)
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The inner exception.
- public ActivationException(string message, Exception innerException) : base(message, innerException) { }
+ public ActivationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
- #if !NO_EXCEPTION_SERIALIZATION
///
/// Initializes a new instance of the class.
///
/// The serialized object data.
/// The serialization context.
- protected ActivationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- #endif
+ protected ActivationException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Attributes/ConstraintAttribute.cs b/Telerik.JustMock/AutoMock/Ninject/Attributes/ConstraintAttribute.cs
index 3910717e..08a98bca 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Attributes/ConstraintAttribute.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Attributes/ConstraintAttribute.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+
///
/// Defines a constraint on the decorated member.
///
@@ -27,4 +38,4 @@ public abstract class ConstraintAttribute : Attribute
/// True if the metadata matches; otherwise false .
public abstract bool Matches(IBindingMetadata metadata);
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Attributes/InjectAttribute.cs b/Telerik.JustMock/AutoMock/Ninject/Attributes/InjectAttribute.cs
index d15fe88a..d89cc870 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Attributes/InjectAttribute.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Attributes/InjectAttribute.cs
@@ -1,22 +1,36 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+
///
/// Indicates that the decorated member should be injected.
///
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field,
- AllowMultiple = false, Inherited = true)]
- public class InjectAttribute : Attribute { }
-}
+ [AttributeUsage(
+ AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field,
+ AllowMultiple = false,
+ Inherited = true)]
+ public class InjectAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Attributes/NamedAttribute.cs b/Telerik.JustMock/AutoMock/Ninject/Attributes/NamedAttribute.cs
index f704bad7..c8e0a635 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Attributes/NamedAttribute.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Attributes/NamedAttribute.cs
@@ -1,31 +1,35 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+
///
/// Indicates that the decorated member should only be injected using binding(s) registered
/// with the specified name.
///
public class NamedAttribute : ConstraintAttribute
{
- ///
- /// Gets the binding name.
- ///
- public string Name { get; private set; }
-
///
/// Initializes a new instance of the class.
///
@@ -33,9 +37,15 @@ public class NamedAttribute : ConstraintAttribute
public NamedAttribute(string name)
{
Ensure.ArgumentNotNullOrEmpty(name, "name");
- Name = name;
+
+ this.Name = name;
}
+ ///
+ /// Gets the binding name.
+ ///
+ public string Name { get; private set; }
+
///
/// Determines whether the specified binding metadata matches the constraint.
///
@@ -44,7 +54,8 @@ public NamedAttribute(string name)
public override bool Matches(IBindingMetadata metadata)
{
Ensure.ArgumentNotNull(metadata, "metadata");
- return metadata.Name == Name;
+
+ return metadata.Name == this.Name;
}
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Attributes/OptionalAttribute.cs b/Telerik.JustMock/AutoMock/Ninject/Attributes/OptionalAttribute.cs
index 9f7c63d2..aaf00a21 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Attributes/OptionalAttribute.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Attributes/OptionalAttribute.cs
@@ -1,22 +1,36 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+
///
/// Indicates that the decorated member represents an optional dependency.
///
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
- AllowMultiple = false, Inherited = true)]
- public class OptionalAttribute : Attribute { }
-}
+ [AttributeUsage(
+ AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
+ AllowMultiple = false,
+ Inherited = true)]
+ public class OptionalAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Components/ComponentContainer.cs b/Telerik.JustMock/AutoMock/Ninject/Components/ComponentContainer.cs
index 90aed720..dc6bfac7 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Components/ComponentContainer.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Components/ComponentContainer.cs
@@ -1,32 +1,43 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Components
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
+
///
/// An internal container that manages and resolves components that contribute to Ninject.
///
public class ComponentContainer : DisposableObject, IComponentContainer
{
- private readonly Multimap _mappings = new Multimap();
- private readonly Dictionary _instances = new Dictionary();
+ private readonly Multimap mappings = new Multimap();
+ private readonly Dictionary instances = new Dictionary();
private readonly HashSet> transients = new HashSet>();
///
@@ -37,15 +48,18 @@ public class ComponentContainer : DisposableObject, IComponentContainer
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
- foreach (INinjectComponent instance in _instances.Values)
+ foreach (INinjectComponent instance in this.instances.Values)
+ {
instance.Dispose();
+ }
- _mappings.Clear();
- _instances.Clear();
+ this.mappings.Clear();
+ this.instances.Clear();
}
base.Dispose(disposing);
@@ -60,7 +74,7 @@ public void Add()
where TComponent : INinjectComponent
where TImplementation : TComponent, INinjectComponent
{
- _mappings.Add(typeof(TComponent), typeof(TImplementation));
+ this.mappings.Add(typeof(TComponent), typeof(TImplementation));
}
///
@@ -75,7 +89,7 @@ public void AddTransient()
this.Add();
this.transients.Add(new KeyValuePair(typeof(TComponent), typeof(TImplementation)));
}
-
+
///
/// Removes all registrations for the specified component.
///
@@ -83,7 +97,27 @@ public void AddTransient()
public void RemoveAll()
where T : INinjectComponent
{
- RemoveAll(typeof(T));
+ this.RemoveAll(typeof(T));
+ }
+
+ ///
+ /// Removes the specified registration.
+ ///
+ /// The component type.
+ /// The implementation type.
+ public void Remove()
+ where T : INinjectComponent
+ where TImplementation : T
+ {
+ var implementation = typeof(TImplementation);
+ if (this.instances.ContainsKey(implementation))
+ {
+ this.instances[implementation].Dispose();
+ }
+
+ this.instances.Remove(implementation);
+
+ this.mappings.Remove(typeof(T), typeof(TImplementation));
}
///
@@ -94,15 +128,17 @@ public void RemoveAll(Type component)
{
Ensure.ArgumentNotNull(component, "component");
- foreach (Type implementation in _mappings[component])
+ foreach (Type implementation in this.mappings[component])
{
- if (_instances.ContainsKey(implementation))
- _instances[implementation].Dispose();
+ if (this.instances.ContainsKey(implementation))
+ {
+ this.instances[implementation].Dispose();
+ }
- _instances.Remove(implementation);
+ this.instances.Remove(implementation);
}
- _mappings.RemoveAll(component);
+ this.mappings.RemoveAll(component);
}
///
@@ -113,7 +149,7 @@ public void RemoveAll(Type component)
public T Get()
where T : INinjectComponent
{
- return (T) Get(typeof(T));
+ return (T)this.Get(typeof(T));
}
///
@@ -124,7 +160,7 @@ public T Get()
public IEnumerable GetAll()
where T : INinjectComponent
{
- return GetAll(typeof(T)).Cast();
+ return this.GetAll(typeof(T)).Cast();
}
///
@@ -137,29 +173,29 @@ public object Get(Type component)
Ensure.ArgumentNotNull(component, "component");
if (component == typeof(IKernel))
- return Kernel;
+ {
+ return this.Kernel;
+ }
if (component.IsGenericType)
{
- Type gtd = component.GetGenericTypeDefinition();
- Type argument = component.GetGenericArguments()[0];
-
-#if WINDOWS_PHONE
- Type discreteGenericType =
- typeof (IEnumerable<>).MakeGenericType(argument);
- if (gtd.IsInterface && discreteGenericType.IsAssignableFrom(component))
- return GetAll(argument).CastSlow(argument);
-#else
- if (gtd.IsInterface && typeof (IEnumerable<>).IsAssignableFrom(gtd))
- return GetAll(argument).CastSlow(argument);
-#endif
+ var gtd = component.GetGenericTypeDefinition();
+ var argument = component.GenericTypeArguments[0];
+
+ if (gtd.IsInterface && typeof(IEnumerable<>).IsAssignableFrom(gtd))
+ {
+ return this.GetAll(argument).CastSlow(argument);
+ }
}
- Type implementation = _mappings[component].FirstOrDefault();
+
+ var implementation = this.mappings[component].FirstOrDefault();
if (implementation == null)
+ {
throw new InvalidOperationException(ExceptionFormatter.NoSuchComponentRegistered(component));
+ }
- return ResolveInstance(component, implementation);
+ return this.ResolveInstance(component, implementation);
}
///
@@ -171,29 +207,44 @@ public IEnumerable GetAll(Type component)
{
Ensure.ArgumentNotNull(component, "component");
- return _mappings[component]
- .Select(implementation => ResolveInstance(component, implementation));
+ return this.mappings[component]
+ .Select(implementation => this.ResolveInstance(component, implementation));
+ }
+
+ private static ConstructorInfo SelectConstructor(Type component, Type implementation)
+ {
+ var constructor = implementation.GetConstructors().OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();
+
+ if (constructor == null)
+ {
+ throw new InvalidOperationException(ExceptionFormatter.NoConstructorsAvailableForComponent(component, implementation));
+ }
+
+ return constructor;
}
private object ResolveInstance(Type component, Type implementation)
{
- lock (_instances)
- return _instances.ContainsKey(implementation) ? _instances[implementation] : CreateNewInstance(component, implementation);
+ lock (this.instances)
+ {
+ return this.instances.ContainsKey(implementation) ? this.instances[implementation] : this.CreateNewInstance(component, implementation);
+ }
}
private object CreateNewInstance(Type component, Type implementation)
{
- ConstructorInfo constructor = SelectConstructor(component, implementation);
- var arguments = constructor.GetParameters().Select(parameter => Get(parameter.ParameterType)).ToArray();
+ var constructor = SelectConstructor(component, implementation);
+ var arguments = constructor.GetParameters().Select(parameter => this.Get(parameter.ParameterType)).ToArray();
try
{
var instance = constructor.Invoke(arguments) as INinjectComponent;
- instance.Settings = Kernel.Settings;
+
+ instance.Settings = this.Kernel.Settings;
if (!this.transients.Contains(new KeyValuePair(component, implementation)))
{
- _instances.Add(implementation, instance);
+ this.instances.Add(implementation, instance);
}
return instance;
@@ -204,32 +255,5 @@ private object CreateNewInstance(Type component, Type implementation)
return null;
}
}
-
- private static ConstructorInfo SelectConstructor(Type component, Type implementation)
- {
- var constructor = implementation.GetConstructors().OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();
-
- if (constructor == null)
- throw new InvalidOperationException(ExceptionFormatter.NoConstructorsAvailableForComponent(component, implementation));
-
- return constructor;
- }
-
-#if SILVERLIGHT_30 || SILVERLIGHT_20 || WINDOWS_PHONE || NETCF_35
- private class HashSet
- {
- private IDictionary data = new Dictionary();
-
- public void Add(T o)
- {
- this.data.Add(o, null);
- }
-
- public bool Contains(T o)
- {
- return this.data.ContainsKey(o);
- }
- }
-#endif
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Components/IComponentContainer.cs b/Telerik.JustMock/AutoMock/Ninject/Components/IComponentContainer.cs
index c5702614..077769e0 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Components/IComponentContainer.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Components/IComponentContainer.cs
@@ -1,19 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Components
{
+ using System;
+ using System.Collections.Generic;
+
///
/// An internal container that manages and resolves components that contribute to Ninject.
///
@@ -37,7 +47,8 @@ void Add()
/// Removes all registrations for the specified component.
///
/// The component type.
- void RemoveAll() where T : INinjectComponent;
+ void RemoveAll()
+ where T : INinjectComponent;
///
/// Removes all registrations for the specified component.
@@ -45,19 +56,30 @@ void Add()
/// The component's type.
void RemoveAll(Type component);
+ ///
+ /// Removes the specified registration.
+ ///
+ /// The component type.
+ /// The implementation type.
+ void Remove()
+ where T : INinjectComponent
+ where TImplementation : T;
+
///
/// Gets one instance of the specified component.
///
/// The component type.
/// The instance of the component.
- T Get() where T : INinjectComponent;
+ T Get()
+ where T : INinjectComponent;
///
/// Gets all available instances of the specified component.
///
/// The component type.
/// A series of instances of the specified component.
- IEnumerable GetAll() where T : INinjectComponent;
+ IEnumerable GetAll()
+ where T : INinjectComponent;
///
/// Gets one instance of the specified component.
diff --git a/Telerik.JustMock/AutoMock/Ninject/Components/INinjectComponent.cs b/Telerik.JustMock/AutoMock/Ninject/Components/INinjectComponent.cs
index cd9488c8..c54fcad4 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Components/INinjectComponent.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Components/INinjectComponent.cs
@@ -1,18 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Components
{
+ using System;
+
///
/// A component that contributes to the internals of Ninject.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Components/NinjectComponent.cs b/Telerik.JustMock/AutoMock/Ninject/Components/NinjectComponent.cs
index efce03a4..2d2eb499 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Components/NinjectComponent.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Components/NinjectComponent.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Components
{
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
+
///
/// A component that contributes to the internals of Ninject.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistration.cs b/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistration.cs
index 9796a5dd..e6a1e586 100644
--- a/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistration.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistration.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
@@ -32,23 +32,36 @@ namespace Telerik.JustMock.AutoMock.Ninject
///
public abstract class GlobalKernelRegistration
{
- private static readonly ReaderWriterLock kernelRegistrationsLock = new ReaderWriterLock();
- private static readonly IDictionary kernelRegistrations = new Dictionary();
+ private static readonly ReaderWriterLockSlim KernelRegistrationsLock = new ReaderWriterLockSlim();
+
+ private static readonly IDictionary KernelRegistrations = new Dictionary();
+ ///
+ /// Registers the kernel for the specified type.
+ ///
+ /// The .
+ /// The service type.
internal static void RegisterKernelForType(IKernel kernel, Type type)
{
var registration = GetRegistrationForType(type);
- registration.KernelLock.AcquireWriterLock(Timeout.Infinite);
+
+ registration.KernelLock.EnterWriteLock();
+
try
{
registration.Kernels.Add(new WeakReference(kernel));
}
finally
{
- registration.KernelLock.ReleaseWriterLock();
+ registration.KernelLock.ExitWriteLock();
}
}
+ ///
+ /// Un-registers the kernel for the specified type.
+ ///
+ /// The .
+ /// The service type.
internal static void UnregisterKernelForType(IKernel kernel, Type type)
{
var registration = GetRegistrationForType(type);
@@ -61,16 +74,16 @@ internal static void UnregisterKernelForType(IKernel kernel, Type type)
/// The action.
protected void MapKernels(Action action)
{
- bool requiresCleanup = false;
+ var requiresCleanup = false;
var registration = GetRegistrationForType(this.GetType());
- registration.KernelLock.AcquireReaderLock(Timeout.Infinite);
+
+ registration.KernelLock.EnterReadLock();
try
{
foreach (var weakReference in registration.Kernels)
{
- var kernel = weakReference.Target as IKernel;
- if (kernel != null)
+ if (weakReference.Target is IKernel kernel)
{
action(kernel);
}
@@ -82,7 +95,7 @@ protected void MapKernels(Action action)
}
finally
{
- registration.KernelLock.ReleaseReaderLock();
+ registration.KernelLock.ExitReadLock();
}
if (requiresCleanup)
@@ -90,10 +103,11 @@ protected void MapKernels(Action action)
RemoveKernels(registration, registration.Kernels.Where(reference => !reference.IsAlive));
}
}
-
+
private static void RemoveKernels(Registration registration, IEnumerable references)
{
- registration.KernelLock.AcquireWriterLock(Timeout.Infinite);
+ registration.KernelLock.EnterWriteLock();
+
try
{
foreach (var reference in references.ToArray())
@@ -103,47 +117,46 @@ private static void RemoveKernels(Registration registration, IEnumerable();
}
- public ReaderWriterLock KernelLock { get; private set; }
+ public ReaderWriterLockSlim KernelLock { get; private set; }
+
public IList Kernels { get; private set; }
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistrationModule.cs b/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistrationModule.cs
index 762fd133..571bbc18 100644
--- a/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistrationModule.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/GlobalKernelRegistrationModule.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,9 +17,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
-#if !SILVERLIGHT && !NETCF
namespace Telerik.JustMock.AutoMock.Ninject
{
using Telerik.JustMock.AutoMock.Ninject.Modules;
@@ -48,5 +47,4 @@ public override void Unload()
GlobalKernelRegistration.UnregisterKernelForType(this.Kernel, typeof(TGlobalKernelRegistry));
}
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectComponents.cs b/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectComponents.cs
new file mode 100644
index 00000000..4ed33210
--- /dev/null
+++ b/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectComponents.cs
@@ -0,0 +1,36 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
+namespace Telerik.JustMock.AutoMock.Ninject
+{
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
+ ///
+ /// Provides access to Ninject components.
+ ///
+ public interface IHaveNinjectComponents
+ {
+ ///
+ /// Gets the component container, which holds components that contribute to Ninject.
+ ///
+ IComponentContainer Components { get; }
+ }
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectSettings.cs b/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectSettings.cs
new file mode 100644
index 00000000..77762f26
--- /dev/null
+++ b/Telerik.JustMock/AutoMock/Ninject/IHaveNinjectSettings.cs
@@ -0,0 +1,34 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
+namespace Telerik.JustMock.AutoMock.Ninject
+{
+ ///
+ /// Provides access to Ninject settings.
+ ///
+ public interface IHaveNinjectSettings
+ {
+ ///
+ /// Gets the kernel settings.
+ ///
+ INinjectSettings Settings { get; }
+ }
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/IInitializable.cs b/Telerik.JustMock/AutoMock/Ninject/IInitializable.cs
index 9681d69a..f1e44495 100644
--- a/Telerik.JustMock/AutoMock/Ninject/IInitializable.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/IInitializable.cs
@@ -1,15 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
@@ -23,4 +31,4 @@ public interface IInitializable
///
void Initialize();
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/IKernel.cs b/Telerik.JustMock/AutoMock/Ninject/IKernel.cs
index 7a292017..c1372748 100644
--- a/Telerik.JustMock/AutoMock/Ninject/IKernel.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/IKernel.cs
@@ -1,31 +1,41 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Activation.Blocks;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
-using Telerik.JustMock.AutoMock.Ninject.Modules;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-using Telerik.JustMock.AutoMock.Ninject.Syntax;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+ using System.Collections.Generic;
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation.Blocks;
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
+ using Telerik.JustMock.AutoMock.Ninject.Modules;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Syntax;
+
///
/// A super-factory that can create objects of all kinds, following hints provided by s.
///
- public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDisposableObject
+ public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDisposableObject, INotifyWhenDisposed
{
///
/// Gets the kernel settings.
@@ -56,7 +66,6 @@ public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDis
/// The modules to load.
void Load(IEnumerable m);
- #if !NO_ASSEMBLY_SCANNING
///
/// Loads modules from the files that match the specified pattern(s).
///
@@ -68,7 +77,6 @@ public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDis
///
/// The assemblies to search.
void Load(IEnumerable assemblies);
- #endif
///
/// Unloads the plugin with the specified name.
@@ -76,13 +84,6 @@ public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDis
/// The plugin's name.
void Unload(string name);
- ///
- /// Injects the specified existing instance, without managing its lifecycle.
- ///
- /// The instance to inject.
- /// The parameters to pass to the request.
- void Inject(object instance, params IParameter[] parameters);
-
///
/// Gets the bindings registered for the specified service.
///
@@ -96,4 +97,4 @@ public interface IKernel : IBindingRoot, IResolutionRoot, IServiceProvider, IDis
/// The new activation block.
IActivationBlock BeginBlock();
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/INinjectSettings.cs b/Telerik.JustMock/AutoMock/Ninject/INinjectSettings.cs
index e2424c24..da8df5ef 100644
--- a/Telerik.JustMock/AutoMock/Ninject/INinjectSettings.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/INinjectSettings.cs
@@ -1,20 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+
///
/// Contains configuration options for Ninject.
///
@@ -35,7 +45,6 @@ public interface INinjectSettings
///
Func DefaultScopeCallback { get; }
- #if !NO_ASSEMBLY_SCANNING
///
/// Gets a value indicating whether the kernel should automatically load extensions at startup.
///
@@ -45,31 +54,28 @@ public interface INinjectSettings
/// Gets the paths that should be searched for extensions.
///
string[] ExtensionSearchPatterns { get; }
- #endif //!NO_ASSEMBLY_SCANNING
- #if !NO_LCG
+#if !NO_LCG
///
/// Gets a value indicating whether Ninject should use reflection-based injection instead of
/// the (usually faster) lightweight code generation system.
///
bool UseReflectionBasedInjection { get; }
- #endif //!NO_LCG
+#endif //!NO_LCG
- #if !SILVERLIGHT
///
- /// Gets a value indicating whether Ninject should inject non public members.
+ /// Gets or sets a value indicating whether Ninject should inject non public members.
///
bool InjectNonPublic { get; set; }
///
- /// Gets a value indicating whether Ninject should inject private properties of base classes.
+ /// Gets or sets a value indicating whether Ninject should inject private properties of base classes.
///
///
- /// Activating this setting has an impact on the performance. It is recomended not
+ /// Activating this setting has an impact on the performance. It is recommended not
/// to use this feature and use constructor injection instead.
///
bool InjectParentPrivateProperties { get; set; }
- #endif //!SILVERLIGHT
///
/// Gets or sets a value indicating whether the activation cache is disabled.
@@ -85,11 +91,19 @@ public interface INinjectSettings
///
/// Gets or sets a value indicating whether Null is a valid value for injection.
- /// By defuault this is disabled and whenever a provider returns null an exception is thrown.
+ /// By default this is disabled and whenever a provider returns null an exception is thrown.
///
/// true if null is allowed as injected value otherwise false.
bool AllowNullInjection { get; set; }
+ ///
+ /// Gets or sets a value indicating whether the old (<= 3.3.4) behavior of
+ /// should be used which throws an exception if the requested service cannot be found. Note that the documentation
+ /// of that method https://docs.microsoft.com/en-us/dotnet/api/system.iserviceprovider.getservice?view=netframework-4.6.2
+ /// states that the method should return if there is no such service.
+ ///
+ bool ThrowOnGetServiceNotFound { get; set; }
+
///
/// Gets the value for the specified key.
///
@@ -106,4 +120,4 @@ public interface INinjectSettings
/// The setting's value.
void Set(string key, object value);
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/IStartable.cs b/Telerik.JustMock/AutoMock/Ninject/IStartable.cs
index ea172fd1..15ce53e5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/IStartable.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/IStartable.cs
@@ -1,15 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
@@ -28,4 +36,4 @@ public interface IStartable
///
void Stop();
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/BaseWeakReference.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/BaseWeakReference.cs
deleted file mode 100644
index 96d5c0f0..00000000
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/BaseWeakReference.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
-{
- using System;
-
- ///
- /// Inheritable weak reference base class for Silverlight
- ///
- public abstract class BaseWeakReference
- {
- private readonly WeakReference innerWeakReference;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- protected BaseWeakReference(object target)
- {
- this.innerWeakReference = new WeakReference(target);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- /// if set to true [track resurrection].
- protected BaseWeakReference(object target, bool trackResurrection)
- {
- this.innerWeakReference = new WeakReference(target, trackResurrection);
- }
-
- ///
- /// Gets a value indicating whether this instance is alive.
- ///
- /// true if this instance is alive; otherwise, false .
- public bool IsAlive
- {
- get
- {
- return this.innerWeakReference.IsAlive;
- }
- }
-
- ///
- /// Gets or sets the target of this weak reference.
- ///
- /// The target of this weak reference.
- public object Target
- {
- get
- {
- return this.innerWeakReference.Target;
- }
-
- set
- {
- this.innerWeakReference.Target = value;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/DisposableObject.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/DisposableObject.cs
index ebe4f201..9505f21f 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/DisposableObject.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/DisposableObject.cs
@@ -1,24 +1,46 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that notifies when it is disposed.
///
- public abstract class DisposableObject : IDisposableObject
+ public abstract class DisposableObject : IDisposableObject, INotifyWhenDisposed
{
+ ///
+ /// Finalizes an instance of the class.
+ ///
+ ~DisposableObject()
+ {
+ this.Dispose(false);
+ }
+
+ ///
+ /// Occurs when the object is disposed.
+ ///
+ public event EventHandler Disposed;
+
///
/// Gets a value indicating whether this instance is disposed.
///
@@ -29,30 +51,25 @@ public abstract class DisposableObject : IDisposableObject
///
public void Dispose()
{
- Dispose(true);
+ this.Dispose(true);
}
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public virtual void Dispose(bool disposing)
{
lock (this)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
- IsDisposed = true;
+ this.IsDisposed = true;
+ this.Disposed?.Invoke(this, EventArgs.Empty);
+ this.Disposed = null;
GC.SuppressFinalize(this);
}
}
}
-
- ///
- /// Releases resources before the object is reclaimed by garbage collection.
- ///
- ~DisposableObject()
- {
- Dispose(false);
- }
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/IDisposableObject.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/IDisposableObject.cs
index 07867e08..7dad029d 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/IDisposableObject.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/IDisposableObject.cs
@@ -1,18 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that can report whether or not it is disposed.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
index ed991b0f..7c2d65f3 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
@@ -1,18 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that fires an event when it is disposed.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Ensure.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Ensure.cs
index f1f876c6..0ccd6a21 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Ensure.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Ensure.cs
@@ -1,28 +1,57 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
+ using System;
+
+ ///
+ /// Argument guard.
+ ///
internal static class Ensure
{
- public static void ArgumentNotNull(object argument, string name)
+ ///
+ /// Ensures the argument is not null.
+ ///
+ /// The argument value.
+ /// The argument name.
+ internal static void ArgumentNotNull(object argument, string name)
{
- if (argument == null) throw new ArgumentNullException(name, "Cannot be null");
+ if (argument == null)
+ {
+ throw new ArgumentNullException(name, "Cannot be null");
+ }
}
- public static void ArgumentNotNullOrEmpty(string argument, string name)
+ ///
+ /// Ensures the argument is not null or empty.
+ ///
+ /// The argument value.
+ /// The argument name.
+ internal static void ArgumentNotNullOrEmpty(string argument, string name)
{
- if (String.IsNullOrEmpty(argument)) throw new ArgumentException("Cannot be null or empty", name);
+ if (string.IsNullOrEmpty(argument))
+ {
+ throw new ArgumentException("Cannot be null or empty", name);
+ }
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Future.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Future.cs
deleted file mode 100644
index 4ceaafd6..00000000
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Future.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
-
-namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
-{
- ///
- /// Represents a future value.
- ///
- /// The type of value.
- public class Future
- {
- private bool _hasValue;
- private T _value;
-
- ///
- /// Gets the value, resolving it if necessary.
- ///
- public T Value
- {
- get
- {
- if (!_hasValue)
- {
- _value = Callback();
- _hasValue = true;
- }
-
- return _value;
- }
- }
-
- ///
- /// Gets the callback that will be called to resolve the value.
- ///
- public Func Callback { get; private set; }
-
- ///
- /// Initializes a new instance of the Future<T> class.
- ///
- /// The callback that will be triggered to read the value.
- public Future(Func callback)
- {
- Callback = callback;
- }
-
- ///
- /// Gets the value from the future.
- ///
- /// The future.
- /// The future value.
- public static implicit operator T(Future future)
- {
- return future.Value;
- }
- }
-}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveBindingConfiguration.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveBindingConfiguration.cs
index d2df576a..0c0394e0 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveBindingConfiguration.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveBindingConfiguration.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+
///
/// Indicates the object has a reference to a .
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveKernel.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveKernel.cs
index f8fbeed3..2d52c8f5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveKernel.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/IHaveKernel.cs
@@ -1,15 +1,23 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
index 6482c953..211106bc 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
@@ -1,12 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2007-2009, Enkari, Ltd.
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Nate Kohari (nate@enkari.com)
-// Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -19,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection
{
@@ -50,6 +48,7 @@ public static string ModulesWithNullOrEmptyNamesAreNotSupported()
///
/// Generates a message saying that modules without names are not supported.
///
+ /// The target.
/// The exception message.
public static string TargetDoesNotHaveADefaultValue(ITarget target)
{
@@ -71,10 +70,10 @@ public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule,
sw.WriteLine("Suggestions:");
sw.WriteLine(" 1) Ensure that you have not accidentally loaded the same module twice.");
- #if !SILVERLIGHT
+#if !NO_ASSEMBLY_SCANNING
sw.WriteLine(" 2) If you are using automatic module loading, ensure you have not manually loaded a module");
sw.WriteLine(" that may be found by the module loader.");
- #endif
+#endif
return sw.ToString();
}
@@ -117,6 +116,7 @@ public static string CouldNotUniquelyResolveBinding(IRequest request, string[] f
{
sw.WriteLine(" {0}) {1}", i + 1, formattedMatchingBindings[i]);
}
+
sw.WriteLine("Activation path:");
sw.WriteLine(request.FormatActivationPath());
@@ -147,9 +147,9 @@ public static string CouldNotResolveBinding(IRequest request)
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.");
sw.WriteLine(" 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.");
- #if !SILVERLIGHT
+#if !NO_ASSEMBLY_SCANNING
sw.WriteLine(" 5) If you are using automatic module loading, ensure the search path and filters are correct.");
- #endif
+#endif
return sw.ToString();
}
@@ -229,7 +229,7 @@ public static string NoConstructorsAvailable(IContext context)
return sw.ToString();
}
}
-
+
///
/// Generates a message saying that no constructors are available for the given component.
///
@@ -297,6 +297,28 @@ public static string CouldNotResolvePropertyForValueInjection(IRequest request,
}
}
+ ///
+ /// Generates a message saying that the provider callback on the specified context is null.
+ ///
+ /// The context.
+ /// The exception message.
+ public static string ProviderCallbackIsNull(IContext context)
+ {
+ using (var sw = new StringWriter())
+ {
+ sw.WriteLine("Error activating {0}", context.Request.Service.Format());
+ sw.WriteLine("Provider callback is null.");
+
+ sw.WriteLine("Activation path:");
+ sw.WriteLine(context.Request.FormatActivationPath());
+
+ sw.WriteLine("Suggestions:");
+ sw.WriteLine(" 1) Ensure that one of the 'To' methods is called after 'Bind' methond.");
+
+ return sw.ToString();
+ }
+ }
+
///
/// Generates a message saying that the provider on the specified context returned null.
///
@@ -308,13 +330,13 @@ public static string ProviderReturnedNull(IContext context)
{
sw.WriteLine("Error activating {0} using {1}", context.Request.Service.Format(), context.Binding.Format(context));
sw.WriteLine("Provider returned null.");
-
+
sw.WriteLine("Activation path:");
sw.WriteLine(context.Request.FormatActivationPath());
sw.WriteLine("Suggestions:");
sw.WriteLine(" 1) Ensure that the provider handles creation requests properly.");
-
+
return sw.ToString();
}
}
@@ -332,7 +354,7 @@ public static string ConstructorsAmbiguous(IContext context, IGrouping
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.IO;
-using System.Reflection;
-using System.Text;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
-using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection
{
- using System.Globalization;
+ using System;
+ using System.IO;
+ using System.Reflection;
+ using System.Text;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
///
/// Provides extension methods for string formatting
@@ -35,7 +44,7 @@ public static string FormatActivationPath(this IRequest request)
{
using (var sw = new StringWriter())
{
- IRequest current = request;
+ var current = request;
while (current != null)
{
@@ -48,7 +57,7 @@ public static string FormatActivationPath(this IRequest request)
}
///
- /// Formats the given binding into a meaningful string representation.
+ /// Formats the given binding into a meaningful string representation.
///
/// The binding to be formatted.
/// The context.
@@ -58,12 +67,16 @@ public static string Format(this IBinding binding, IContext context)
using (var sw = new StringWriter())
{
if (binding.Condition != null)
+ {
sw.Write("conditional ");
+ }
if (binding.IsImplicit)
+ {
sw.Write("implicit ");
+ }
- IProvider provider = binding.GetProvider(context);
+ var provider = binding.GetProvider(context);
switch (binding.Target)
{
@@ -76,8 +89,11 @@ public static string Format(this IBinding binding, IContext context)
break;
case BindingTarget.Provider:
- sw.Write("provider binding from {0} to {1} (via {2})", binding.Service.Format(),
- provider.Type.Format(), provider.GetType().Format());
+ sw.Write(
+ "provider binding from {0} to {1} (via {2})",
+ binding.Service.Format(),
+ provider.Type.Format(),
+ provider.GetType().Format());
break;
case BindingTarget.Method:
@@ -106,9 +122,13 @@ 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();
}
@@ -156,16 +176,12 @@ public static string Format(this Type type)
{
var friendlyName = GetFriendlyName(type);
-#if !MONO
if (friendlyName.Contains("AnonymousType"))
+ {
return "AnonymousType";
-#else
-
- if (friendlyName.Contains("__AnonType"))
- return "AnonymousType";
-#endif
+ }
- switch (friendlyName.ToLower(CultureInfo.InvariantCulture))
+ switch (friendlyName.ToLowerInvariant())
{
case "int16": return "short";
case "int32": return "int";
@@ -186,9 +202,12 @@ public static string Format(this Type type)
}
var genericArguments = type.GetGenericArguments();
- if(genericArguments.Length > 0)
+
+ if (genericArguments.Length > 0)
+ {
return FormatGenericType(friendlyName, genericArguments);
-
+ }
+
return friendlyName;
}
@@ -199,30 +218,29 @@ private static string GetFriendlyName(Type type)
// remove generic arguments
var firstBracket = friendlyName.IndexOf('[');
if (firstBracket > 0)
+ {
friendlyName = friendlyName.Substring(0, firstBracket);
+ }
// remove assembly info
var firstComma = friendlyName.IndexOf(',');
if (firstComma > 0)
+ {
friendlyName = friendlyName.Substring(0, firstComma);
+ }
// remove namespace
var lastPeriod = friendlyName.LastIndexOf('.');
if (lastPeriod >= 0)
+ {
friendlyName = friendlyName.Substring(lastPeriod + 1);
+ }
return friendlyName;
}
private static string FormatGenericType(string friendlyName, Type[] genericArguments)
{
- //var genericTag = "`" + genericArguments.Length;
- //var genericArgumentNames = new string[genericArguments.Length];
- //for (int i = 0; i < genericArguments.Length; i++)
- // genericArgumentNames[i] = genericArguments[i].Format();
-
- //return friendlyName.Replace(genericTag, string.Join(", ", genericArgumentNames));
-
var sb = new StringBuilder(friendlyName.Length + 10);
var genericArgumentIndex = 0;
@@ -231,8 +249,8 @@ private static string FormatGenericType(string friendlyName, Type[] genericArgum
{
if (friendlyName[index] == '`')
{
- var numArguments = friendlyName[index+1] - 48;
-
+ var numArguments = friendlyName[index + 1] - 48;
+
sb.Append(friendlyName.Substring(startIndex, index - startIndex));
AppendGenericArguments(sb, genericArguments, genericArgumentIndex, numArguments);
genericArgumentIndex += numArguments;
@@ -240,8 +258,11 @@ private static string FormatGenericType(string friendlyName, Type[] genericArgum
startIndex = index + 2;
}
}
+
if (startIndex < friendlyName.Length)
+ {
sb.Append(friendlyName.Substring(startIndex));
+ }
return sb.ToString();
}
@@ -250,14 +271,16 @@ private static void AppendGenericArguments(StringBuilder sb, Type[] genericArgum
{
sb.Append("{");
- for(int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
if (i != 0)
+ {
sb.Append(", ");
+ }
sb.Append(genericArguments[start + i].Format());
}
-
+
sb.Append("}");
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
index e76d3afa..194c6a00 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
@@ -1,35 +1,59 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !NO_ASSEMBLY_SCANNING
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Modules;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Modules;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForAssembly
{
+ ///
+ /// Determines whether the assembly has loadable .
+ ///
+ /// The .
+ /// True if there's any loadable , otherwise False .
public static bool HasNinjectModules(this Assembly assembly)
{
- return assembly.GetExportedTypes().Any(IsLoadableModule);
+ return !assembly.IsDynamic && assembly.ExportedTypes.Any(IsLoadableModule);
}
+ ///
+ /// Gets loadable s from the .
+ ///
+ /// The .
+ /// The loadable s
public static IEnumerable GetNinjectModules(this Assembly assembly)
{
- return assembly.GetExportedTypes()
- .Where(IsLoadableModule)
- .Select(type => Activator.CreateInstance(type) as INinjectModule);
+ return assembly.IsDynamic ?
+ Enumerable.Empty() :
+ assembly.ExportedTypes.Where(IsLoadableModule)
+ .Select(type => Activator.CreateInstance(type) as INinjectModule);
}
private static bool IsLoadableModule(Type type)
@@ -40,5 +64,4 @@ private static bool IsLoadableModule(Type type)
&& type.GetConstructor(Type.EmptyTypes) != null;
}
}
-}
-#endif //!NO_ASSEMBLY_SCANNING
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
index b448aa80..c35944f5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
@@ -1,24 +1,43 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
using System;
using System.Reflection;
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForICustomAttributeProvider
{
+ ///
+ /// Determines if the has the specified attribute.
+ ///
+ /// The .
+ /// The attribute type.
+ /// True if the has the attribute, otherwise False .
public static bool HasAttribute(this ICustomAttributeProvider member, Type type)
{
- var memberInfo = member as MemberInfo;
- if (memberInfo != null)
+ if (member is MemberInfo memberInfo)
{
return memberInfo.HasAttribute(type);
}
@@ -26,10 +45,16 @@ public static bool HasAttribute(this ICustomAttributeProvider member, Type type)
return member.IsDefined(type, true);
}
+ ///
+ /// Gets custom attributes which supports and .
+ ///
+ /// The .
+ /// The attribute type.
+ /// When true, look up the hierarchy chain for the inherited custom attribute.
+ /// The attributes.
public static object[] GetCustomAttributesExtended(this ICustomAttributeProvider member, Type attributeType, bool inherit)
{
- var memberInfo = member as MemberInfo;
- if (memberInfo != null)
+ if (member is MemberInfo memberInfo)
{
return memberInfo.GetCustomAttributesExtended(attributeType, inherit);
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
index 49562ab1..a2418cc5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
@@ -1,37 +1,76 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections;
-using System.Linq;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
+ using System;
+ using System.Collections;
+ using System.Linq;
+ using System.Reflection;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForIEnumerable
{
+ private static readonly MethodInfo Cast = typeof(Enumerable).GetMethod(nameof(Cast));
+ private static readonly MethodInfo ToArray = typeof(Enumerable).GetMethod(nameof(ToArray));
+ private static readonly MethodInfo ToList = typeof(Enumerable).GetMethod(nameof(ToList));
+
+ ///
+ /// Casts the elements of an to the specified type using reflection.
+ ///
+ /// The that contains the elements to be cast.
+ /// The type to cast the elements of source to.
+ ///
+ /// An that contains each element of the
+ /// source sequence cast to the specified type.
+ ///
public static IEnumerable CastSlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(elementType);
+ var method = Cast.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as IEnumerable;
}
+ ///
+ /// Creates an array from an .
+ ///
+ /// An to create an array from.
+ /// The type of the elements.
+ /// An array that contains the elements from the input sequence.
public static Array ToArraySlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetMethod("ToArray").MakeGenericMethod(elementType);
+ var method = ToArray.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as Array;
}
+ ///
+ /// Creates an from an .
+ ///
+ /// An to create an from.
+ /// The type of the elements.
+ /// An that contains the elements from the input sequence.
public static IList ToListSlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetMethod("ToList").MakeGenericMethod(elementType);
+ var method = ToList.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as IList;
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
index 356b4d8c..9650ebac 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
@@ -1,35 +1,47 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+
///
- /// Provides extension methods for see cref="IEnumerable{T}"/>
+ /// Provides extension methods for .
///
public static class ExtensionsForIEnumerableOfT
{
///
/// Executes the given action for each of the elements in the enumerable.
///
- ///
+ /// Type of the enumerable.
/// The series.
/// The action.
public static void Map(this IEnumerable series, Action action)
{
foreach (T item in series)
+ {
action(item);
+ }
}
///
@@ -42,5 +54,28 @@ public static IEnumerable ToEnumerable(this IEnumerable series)
{
return series.Select(x => x);
}
+
+ ///
+ /// Returns single element of enumerable or throws exception.
+ ///
+ /// The series.
+ /// The exception creator.
+ /// Type of the enumerable.
+ /// The single element of enumerable.
+ ///
+ /// Exception specified by exception creator.
+ ///
+ public static T SingleOrThrowException(this IEnumerable series, Func exceptionCreator)
+ {
+ var e = series.GetEnumerator();
+ e.MoveNext();
+ var result = e.Current;
+ if (e.MoveNext())
+ {
+ throw exceptionCreator();
+ }
+
+ return result;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
index d542e8cb..e5f61d88 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
@@ -1,12 +1,23 @@
-#region License
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
//
-// Author: Remo Gloor (remo.gloor@bbv.ch)
-// Copyright (c) 2010, bbv Software Engineering AG.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
@@ -17,18 +28,17 @@ namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
using System.Reflection;
///
- /// Extensions for MemberInfo
+ /// Provides extension methods for .
///
public static class ExtensionsForMemberInfo
{
- const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance;
-#if !NO_LCG && !SILVERLIGHT
- const BindingFlags Flags = DefaultFlags | BindingFlags.NonPublic;
+ private const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance;
+#if !NO_LCG
+ private const BindingFlags Flags = DefaultFlags | BindingFlags.NonPublic;
#else
- const BindingFlags Flags = DefaultFlags;
+ private const BindingFlags Flags = DefaultFlags;
#endif
-#if !MONO
private static MethodInfo parentDefinitionMethodInfo;
private static MethodInfo ParentDefinitionMethodInfo
@@ -44,7 +54,6 @@ private static MethodInfo ParentDefinitionMethodInfo
return parentDefinitionMethodInfo;
}
}
-#endif
///
/// Determines whether the specified member has attribute.
@@ -52,7 +61,7 @@ private static MethodInfo ParentDefinitionMethodInfo
/// The type of the attribute.
/// The member.
///
- /// true if the specified member has attribute; otherwise, false .
+ /// true if the specified member has attribute; otherwise, false .
///
public static bool HasAttribute(this MemberInfo member)
{
@@ -65,26 +74,15 @@ public static bool HasAttribute(this MemberInfo member)
/// The member.
/// The type of the attribute.
///
- /// true if the specified member has attribute; otherwise, false .
+ /// true if the specified member has attribute; otherwise, false .
///
public static bool HasAttribute(this MemberInfo member, Type type)
{
- var propertyInfo = member as PropertyInfo;
- if (propertyInfo != null)
+ if (member is PropertyInfo propertyInfo)
{
return IsDefined(propertyInfo, type, true);
}
-#if NETCF
- // Workaround for the CF bug that derived generic methods throw an exception for IsDefined
- // This means that the Inject attribute can not be defined on base methods for CF framework
- var methodInfo = member as MethodInfo;
- if (methodInfo != null)
- {
- return methodInfo.IsDefined(type, false);
- }
-#endif
-
return member.IsDefined(type, true);
}
@@ -95,10 +93,7 @@ public static bool HasAttribute(this MemberInfo member, Type type)
/// The property definition.
/// The flags.
/// The property info from the declared type of the property.
- public static PropertyInfo GetPropertyFromDeclaredType(
- this MemberInfo memberInfo,
- PropertyInfo propertyDefinition,
- BindingFlags flags)
+ public static PropertyInfo GetPropertyFromDeclaredType(this MemberInfo memberInfo, PropertyInfo propertyDefinition, BindingFlags flags)
{
return memberInfo.DeclaringType.GetProperty(
propertyDefinition.Name,
@@ -114,7 +109,7 @@ public static PropertyInfo GetPropertyFromDeclaredType(
///
/// The property info.
///
- /// true if the specified property info is private; otherwise, false .
+ /// true if the specified property info is private; otherwise, false .
///
public static bool IsPrivate(this PropertyInfo propertyInfo)
{
@@ -125,25 +120,15 @@ public static bool IsPrivate(this PropertyInfo propertyInfo)
///
/// Gets the custom attributes.
- /// This version is able to get custom attributes for properties from base types even if the property is none public.
+ /// This version is able to get custom attributes for properties from base types even if the property is non-public.
///
/// The member.
/// Type of the attribute.
/// if set to true [inherited].
- ///
+ /// The custom attributes.
public static object[] GetCustomAttributesExtended(this MemberInfo member, Type attributeType, bool inherited)
{
-#if !NET_35 && !MONO_40
return Attribute.GetCustomAttributes(member, attributeType, inherited);
-#else
- var propertyInfo = member as PropertyInfo;
- if (propertyInfo != null)
- {
- return GetCustomAttributes(propertyInfo, attributeType, inherited);
- }
-
- return member.GetCustomAttributes(attributeType, inherited);
-#endif
}
private static PropertyInfo GetParentDefinition(PropertyInfo property)
@@ -163,25 +148,12 @@ private static PropertyInfo GetParentDefinition(PropertyInfo property)
private static MethodInfo GetParentDefinition(this MethodInfo method, BindingFlags flags)
{
-#if MEDIUM_TRUST || MONO
- var baseDefinition = method.GetBaseDefinition();
- var type = method.DeclaringType.BaseType;
- MethodInfo result = null;
- while (result == null && type != null)
- {
- result = type.GetMethods(flags).Where(m => m.GetBaseDefinition().Equals(baseDefinition)).SingleOrDefault();
- type = type.BaseType;
- }
-
- return result;
-#else
if (ParentDefinitionMethodInfo == null)
{
return null;
}
return (MethodInfo)ParentDefinitionMethodInfo.Invoke(method, flags, null, null, CultureInfo.InvariantCulture);
-#endif
}
private static bool IsDefined(PropertyInfo element, Type attributeType, bool inherit)
@@ -225,7 +197,7 @@ private static object[] GetCustomAttributes(PropertyInfo propertyInfo, Type attr
info != null;
info = GetParentDefinition(info))
{
- object[] customAttributes = info.GetCustomAttributes(attributeType, false);
+ var customAttributes = info.GetCustomAttributes(attributeType, false);
AddAttributes(attributes, customAttributes, attributeUsages);
}
@@ -240,9 +212,9 @@ private static object[] GetCustomAttributes(PropertyInfo propertyInfo, Type attr
private static void AddAttributes(List attributes, object[] customAttributes, Dictionary attributeUsages)
{
- foreach (object attribute in customAttributes)
+ foreach (var attribute in customAttributes)
{
- Type type = attribute.GetType();
+ var type = attribute.GetType();
if (!attributeUsages.ContainsKey(type))
{
attributeUsages[type] = InternalGetAttributeUsage(type).Inherited;
@@ -257,8 +229,7 @@ private static void AddAttributes(List attributes, object[] customAttrib
private static AttributeUsageAttribute InternalGetAttributeUsage(Type type)
{
- object[] customAttributes = type.GetCustomAttributes(typeof(AttributeUsageAttribute), true);
- return (AttributeUsageAttribute)customAttributes[0];
- }
+ return type.GetCustomAttribute(true);
+ }
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
index ce2cf8b5..8663ad99 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
@@ -1,27 +1,42 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
+ using System.Reflection;
+ using System.Runtime.ExceptionServices;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForTargetInvocationException
{
+ ///
+ /// Re-throws inner exception.
+ ///
+ /// The .
public static void RethrowInnerException(this TargetInvocationException exception)
{
- Exception innerException = exception.InnerException;
-
- FieldInfo stackTraceField = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic);
- stackTraceField.SetValue(innerException, innerException.StackTrace);
+ var innerException = exception.InnerException;
+ ExceptionDispatchInfo.Capture(innerException).Throw();
throw innerException;
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForType.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForType.cs
index 3f4d6cce..2c74a481 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForType.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Language/ExtensionsForType.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
{
@@ -25,9 +25,8 @@ namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language
using System.Collections.Generic;
///
- /// Extension methods for type
+ /// Extension methods for .
///
- ///
public static class ExtensionsForType
{
///
@@ -40,6 +39,7 @@ public static IEnumerable GetAllBaseTypes(this Type type)
while (type != null)
{
yield return type;
+
type = type.BaseType;
}
}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Multimap.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Multimap.cs
index 9d8471ae..0d723fe1 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Multimap.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Multimap.cs
@@ -1,60 +1,71 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections;
-using System.Collections.Generic;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
+ using System.Collections;
+ using System.Collections.Generic;
+
///
/// A data structure that contains multiple values for a each key.
///
- /// The type of key.
- /// The type of value.
- public class Multimap : IEnumerable>>
+ /// The type of key.
+ /// The type of value.
+ public class Multimap : IEnumerable>>
{
- private readonly Dictionary> _items = new Dictionary>();
+ private readonly Dictionary> items = new Dictionary>();
///
- /// Gets the collection of values stored under the specified key.
+ /// Gets the collection of keys.
///
- /// The key.
- public ICollection this[K key]
+ public ICollection Keys
{
- get
- {
- Ensure.ArgumentNotNull(key, "key");
-
- if (!_items.ContainsKey(key))
- _items[key] = new List();
-
- return _items[key];
- }
+ get { return this.items.Keys; }
}
///
- /// Gets the collection of keys.
+ /// Gets the collection of collections of values.
///
- public ICollection Keys
+ public ICollection> Values
{
- get { return _items.Keys; }
+ get { return this.items.Values; }
}
///
- /// Gets the collection of collections of values.
+ /// Gets the collection of values stored under the specified key.
///
- public ICollection> Values
+ /// The key.
+ public ICollection this[TKey key]
{
- get { return _items.Values; }
+ get
+ {
+ Ensure.ArgumentNotNull(key, "key");
+
+ if (!this.items.ContainsKey(key))
+ {
+ this.items[key] = new List();
+ }
+
+ return this.items[key];
+ }
}
///
@@ -62,7 +73,7 @@ public ICollection> Values
///
/// The key.
/// The value.
- public void Add(K key, V value)
+ public void Add(TKey key, TValue value)
{
Ensure.ArgumentNotNull(key, "key");
Ensure.ArgumentNotNull(value, "value");
@@ -76,15 +87,17 @@ public void Add(K key, V value)
/// The key.
/// The value.
/// True if such a value existed and was removed; otherwise false .
- public bool Remove(K key, V value)
+ public bool Remove(TKey key, TValue value)
{
Ensure.ArgumentNotNull(key, "key");
Ensure.ArgumentNotNull(value, "value");
- if (!_items.ContainsKey(key))
+ if (!this.items.ContainsKey(key))
+ {
return false;
+ }
- return _items[key].Remove(value);
+ return this.items[key].Remove(value);
}
///
@@ -92,10 +105,10 @@ public bool Remove(K key, V value)
///
/// The key.
/// True if any such values existed; otherwise false .
- public bool RemoveAll(K key)
+ public bool RemoveAll(TKey key)
{
Ensure.ArgumentNotNull(key, "key");
- return _items.Remove(key);
+ return this.items.Remove(key);
}
///
@@ -103,7 +116,7 @@ public bool RemoveAll(K key)
///
public void Clear()
{
- _items.Clear();
+ this.items.Clear();
}
///
@@ -111,10 +124,10 @@ public void Clear()
///
/// The key.
/// True if the multimap has one or more values for the specified key; otherwise, false .
- public bool ContainsKey(K key)
+ public bool ContainsKey(TKey key)
{
Ensure.ArgumentNotNull(key, "key");
- return _items.ContainsKey(key);
+ return this.items.ContainsKey(key);
}
///
@@ -123,12 +136,12 @@ public bool ContainsKey(K key)
/// The key.
/// The value.
/// True if the multimap contains such a value; otherwise, false .
- public bool ContainsValue(K key, V value)
+ public bool ContainsValue(TKey key, TValue value)
{
Ensure.ArgumentNotNull(key, "key");
Ensure.ArgumentNotNull(value, "value");
- return _items.ContainsKey(key) && _items[key].Contains(value);
+ return this.items.ContainsKey(key) && this.items[key].Contains(value);
}
///
@@ -137,12 +150,16 @@ public bool ContainsValue(K key, V value)
/// An object that can be used to iterate through the multimap.
public IEnumerator GetEnumerator()
{
- return _items.GetEnumerator();
+ return this.items.GetEnumerator();
}
- IEnumerator>> IEnumerable>>.GetEnumerator()
+ ///
+ /// Returns an enumerator that iterates through a the multimap.
+ ///
+ /// An object that can be used to iterate through the multimap.
+ IEnumerator>> IEnumerable>>.GetEnumerator()
{
- return _items.GetEnumerator();
+ return this.items.GetEnumerator();
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/ReferenceEqualWeakReference.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
index 9ed0bdee..1213802d 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
@@ -1,19 +1,28 @@
-#region License
-//
-// Author: Remo Gloor (remo.gloor@bbv.ch)
-// Copyright (c) 2010, bbv Software Services AG
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
using System;
using System.Runtime.CompilerServices;
-#if SILVERLIGHT
- using WeakReference = BaseWeakReference;
-#endif
///
/// Weak reference that can be used in collections. It is equal to the
@@ -21,19 +30,16 @@ namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
///
public class ReferenceEqualWeakReference : WeakReference
{
- private readonly int cashedHashCode;
+ private readonly int cachedHashCode;
///
/// Initializes a new instance of the class.
///
/// The target.
- public ReferenceEqualWeakReference(object target) : base(target)
+ public ReferenceEqualWeakReference(object target)
+ : base(target)
{
-#if !NETCF
- this.cashedHashCode = RuntimeHelpers.GetHashCode(target);
-#else
- this.cashedHashCode = target.GetHashCode();
-#endif
+ this.cachedHashCode = RuntimeHelpers.GetHashCode(target);
}
///
@@ -41,13 +47,10 @@ public ReferenceEqualWeakReference(object target) : base(target)
///
/// The target.
/// if set to true [track resurrection].
- public ReferenceEqualWeakReference(object target, bool trackResurrection) : base(target, trackResurrection)
+ public ReferenceEqualWeakReference(object target, bool trackResurrection)
+ : base(target, trackResurrection)
{
-#if !NETCF
- this.cashedHashCode = RuntimeHelpers.GetHashCode(target);
-#else
- this.cashedHashCode = target.GetHashCode();
-#endif
+ this.cachedHashCode = RuntimeHelpers.GetHashCode(target);
}
///
@@ -64,8 +67,7 @@ public override bool Equals(object obj)
{
var thisInstance = this.IsAlive ? this.Target : this;
- var referenceEqualWeakReference = obj as WeakReference;
- if (referenceEqualWeakReference != null && referenceEqualWeakReference.IsAlive)
+ if (obj is WeakReference referenceEqualWeakReference && referenceEqualWeakReference.IsAlive)
{
obj = referenceEqualWeakReference.Target;
}
@@ -77,11 +79,11 @@ public override bool Equals(object obj)
/// Returns a hash code for this instance.
///
///
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
- return this.cashedHashCode;
+ return this.cachedHashCode;
}
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/StandardScopeCallbacks.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/StandardScopeCallbacks.cs
index d62a6bd8..153e1e21 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/StandardScopeCallbacks.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/StandardScopeCallbacks.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Infrastructure
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+
///
/// Scope callbacks for standard scopes.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Threading/ReaderWriterLock.cs b/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Threading/ReaderWriterLock.cs
deleted file mode 100644
index 06cce2c9..00000000
--- a/Telerik.JustMock/AutoMock/Ninject/Infrastructure/Threading/ReaderWriterLock.cs
+++ /dev/null
@@ -1,416 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-//
-//
-//
-//
-// A reader-writer lock implementation that is intended to be simple, yet very
-// efficient. In particular only 1 interlocked operation is taken for any lock
-// operation (we use spin locks to achieve this). The spin lock is never held
-// for more than a few instructions (in particular, we never call event APIs
-// or in fact any non-trivial API while holding the spin lock).
-// Currently this ReaderWriterLock does not support recurision, however it is
-// not hard to add
-//
-// --------------------------------------------------------------------------------------------------------------------
-
-#if SILVERLIGHT || NETCF
-namespace System.Threading
-{
- using System.Diagnostics;
-
- ///
- /// A reader-writer lock implementation that is intended to be simple, yet very
- /// efficient. In particular only 1 interlocked operation is taken for any lock
- /// operation (we use spin locks to achieve this). The spin lock is never held
- /// for more than a few instructions (in particular, we never call event APIs
- /// or in fact any non-trivial API while holding the spin lock).
- ///
- /// Currently this ReaderWriterLock does not support recurision, however it is
- /// not hard to add
- ///
- ///
- /// By Vance Morrison
- /// Taken from - http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx
- /// Code at - http://blogs.msdn.com/vancem/attachment/563180.ashx
- ///
- public class ReaderWriterLock
- {
- // Lock specifiation for myLock: This lock protects exactly the local fields associted
- // instance of MyReaderWriterLock. It does NOT protect the memory associted with the
- // the events that hang off this lock (eg writeEvent, readEvent upgradeEvent).
-#region Constants and Fields
-
- ///
- /// The my lock.
- ///
- private int myLock;
-
- // Who owns the lock owners > 0 => readers
- // owners = -1 means there is one writer. Owners must be >= -1.
-
- ///
- /// The number read waiters.
- ///
- private uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent
-
- ///
- /// The number upgrade waiters.
- ///
- private uint numUpgradeWaiters; // maximum number of threads that can be doing a WaitOne on the upgradeEvent (at most 1).
-
- ///
- /// The number write waiters.
- ///
- private uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent
-
- ///
- /// The owners.
- ///
- private int owners;
-
- // conditions we wait on.
-
- ///
- /// The read event.
- ///
- private EventWaitHandle readEvent; // threads waiting to aquire a read lock go here (will be released in bulk)
-
- ///
- /// The upgrade event.
- ///
- private EventWaitHandle upgradeEvent; // thread waiting to upgrade a read lock to a write lock go here (at most one)
-
- ///
- /// The write event.
- ///
- private EventWaitHandle writeEvent; // threads waiting to aquire a write lock go here.
-
- #endregion
-
-#region Properties
-
- ///
- /// Gets a value indicating whether MyLockHeld.
- ///
- private bool MyLockHeld
- {
- get
- {
- return this.myLock != 0;
- }
- }
-
- #endregion
-
-#region Public Methods
-
- ///
- /// The acquire reader lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- public void AcquireReaderLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- // We can enter a read lock if there are only read-locks have been given out
- // and a writer is not trying to get in.
- if (this.owners >= 0 && this.numWriteWaiters == 0)
- {
- // Good case, there is no contention, we are basically done
- this.owners++; // Indicate we have another reader
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.readEvent == null)
- {
- // Create the needed event
- this.LazyCreateEvent(ref this.readEvent, false);
- continue; // since we left the lock, start over.
- }
-
- this.WaitOnEvent(this.readEvent, ref this.numReadWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- }
-
- ///
- /// The acquire writer lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- public void AcquireWriterLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- if (this.owners == 0)
- {
- // Good case, there is no contention, we are basically done
- this.owners = -1; // indicate we have a writer.
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.writeEvent == null)
- {
- // create the needed event.
- this.LazyCreateEvent(ref this.writeEvent, true);
- continue; // since we left the lock, start over.
- }
-
- this.WaitOnEvent(this.writeEvent, ref this.numWriteWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- }
-
- ///
- /// The downgrade to reader lock.
- ///
- /// The lock cookie.
- public void DowngradeFromWriterLock(ref int lockCookie)
- {
- this.EnterMyLock();
- Debug.Assert(this.owners == -1, "Downgrading when no writer lock held");
- this.owners = 1;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The release reader lock.
- ///
- public void ReleaseReaderLock()
- {
- this.EnterMyLock();
- Debug.Assert(this.owners > 0, "ReleasingReaderLock: releasing lock and no read lock taken");
- --this.owners;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The release writer lock.
- ///
- public void ReleaseWriterLock()
- {
- this.EnterMyLock();
- Debug.Assert(this.owners == -1, "Calling ReleaseWriterLock when no write lock is held");
- Debug.Assert(this.numUpgradeWaiters > 0);
- this.owners++;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The upgrade to writer lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- ///
- ///
- public int UpgradeToWriterLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- Debug.Assert(this.owners > 0, "Upgrading when no reader lock held");
- if (this.owners == 1)
- {
- // Good case, there is no contention, we are basically done
- this.owners = -1; // inidicate we have a writer.
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.upgradeEvent == null)
- {
- // Create the needed event
- this.LazyCreateEvent(ref this.upgradeEvent, false);
- continue; // since we left the lock, start over.
- }
-
- if (this.numUpgradeWaiters > 0)
- {
- this.ExitMyLock();
- throw new InvalidOperationException("UpgradeToWriterLock already in process. Deadlock!");
- }
-
- this.WaitOnEvent(this.upgradeEvent, ref this.numUpgradeWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- return 0;
- }
-
- #endregion
-
-#region Methods
-
- ///
- /// The enter my lock.
- ///
- private void EnterMyLock()
- {
- if (Interlocked.CompareExchange(ref this.myLock, 1, 0) != 0)
- {
- this.EnterMyLockSpin();
- }
- }
-
- ///
- /// The enter my lock spin.
- ///
- private void EnterMyLockSpin()
- {
- for (int i = 0;; i++)
- {
-#if !NETCF
- if (i < 3 && Environment.ProcessorCount > 1)
- {
- Thread.SpinWait(20); // Wait a few dozen instructions to let another processor release lock.
- }
- else
- {
- Thread.Sleep(0); // Give up my quantum.
- }
-#else
- Thread.Sleep(0); // Give up my quantum.
-#endif
-
- if (Interlocked.CompareExchange(ref this.myLock, 1, 0) == 0)
- {
- return;
- }
- }
- }
-
- ///
- /// Determines the appropriate events to set, leaves the locks, and sets the events.
- ///
- private void ExitAndWakeUpAppropriateWaiters()
- {
- Debug.Assert(this.MyLockHeld);
-
- if (this.owners == 0 && this.numWriteWaiters > 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.writeEvent.Set(); // release one writer.
- }
- else if (this.owners == 1 && this.numUpgradeWaiters != 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.upgradeEvent.Set(); // release all upgraders (however there can be at most one).
-
- // two threads upgrading is a guarenteed deadlock, so we throw in that case.
- }
- else if (this.owners >= 0 && this.numReadWaiters != 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.readEvent.Set(); // release all readers.
- }
- else
- {
- this.ExitMyLock();
- }
- }
-
- ///
- /// The exit my lock.
- ///
- private void ExitMyLock()
- {
- Debug.Assert(this.myLock != 0, "Exiting spin lock that is not held");
- this.myLock = 0;
- }
-
- ///
- /// A routine for lazily creating a event outside the lock (so if errors
- /// happen they are outside the lock and that we don't do much work
- /// while holding a spin lock). If all goes well, reenter the lock and
- /// set 'waitEvent'
- ///
- ///
- /// The wait Event.
- ///
- ///
- /// The make Auto Reset Event.
- ///
- private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
- {
- Debug.Assert(this.MyLockHeld);
- Debug.Assert(waitEvent == null);
-
- this.ExitMyLock();
- EventWaitHandle newEvent;
- if (makeAutoResetEvent)
- {
- newEvent = new AutoResetEvent(false);
- }
- else
- {
- newEvent = new ManualResetEvent(false);
- }
-
- this.EnterMyLock();
- waitEvent = newEvent;
- }
-
- ///
- /// Waits on 'waitEvent' with a timeout of 'millisceondsTimeout.
- /// Before the wait 'numWaiters' is incremented and is restored before leaving this routine.
- ///
- ///
- /// The wait Event.
- ///
- ///
- /// The num Waiters.
- ///
- ///
- /// The milliseconds Timeout.
- ///
- private void WaitOnEvent(EventWaitHandle waitEvent, ref uint numWaiters, int millisecondsTimeout)
- {
- Debug.Assert(this.MyLockHeld);
-
- waitEvent.Reset();
- numWaiters++;
-
- bool waitSuccessful = false;
- this.ExitMyLock(); // Do the wait outside of any lock
- try
- {
-#if !NETCF
- if (!waitEvent.WaitOne(millisecondsTimeout))
- {
- throw new InvalidOperationException("ReaderWriterLock timeout expired");
- }
-#else
- if (!waitEvent.WaitOne(millisecondsTimeout, false))
- {
- throw new InvalidOperationException("ReaderWriterLock timeout expired");
- }
-#endif
-
- waitSuccessful = true;
- }
- finally
- {
- this.EnterMyLock();
- --numWaiters;
- if (!waitSuccessful)
- {
- // We are going to throw for some reason. Exit myLock.
- this.ExitMyLock();
- }
- }
- }
-
-#endregion
- }
-}
-#endif
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/ConstructorInjector.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/ConstructorInjector.cs
index fa4f4a99..904e116e 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/ConstructorInjector.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/ConstructorInjector.cs
@@ -1,17 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
///
- /// A delegate that can inject values into a constructor.
+ /// Represents a delegate that can inject values into a constructor.
///
+ /// The arguments used for the constructor.
+ /// An object created from the constructor.
public delegate object ConstructorInjector(params object[] arguments);
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/DynamicMethodInjectorFactory.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/DynamicMethodInjectorFactory.cs
index 9a2050f6..272d2455 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/DynamicMethodInjectorFactory.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/DynamicMethodInjectorFactory.cs
@@ -1,27 +1,40 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !NO_LCG
-#region Using Directives
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+#if !NO_LCG
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
+ using System;
+ using System.Reflection;
+ using System.Reflection.Emit;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Creates injectors for members via s.
///
public class DynamicMethodInjectorFactory : NinjectComponent, IInjectorFactory
{
+ private static readonly MethodInfo UnboxPointer = typeof(Pointer).GetMethod("Unbox");
+
///
/// Gets or creates an injector for the specified constructor.
///
@@ -29,23 +42,21 @@ public class DynamicMethodInjectorFactory : NinjectComponent, IInjectorFactory
/// The created injector.
public ConstructorInjector Create(ConstructorInfo constructor)
{
- #if SILVERLIGHT
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) });
- #else
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) }, true);
- #endif
+ var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) }, constructor.Module, true);
- ILGenerator il = dynamicMethod.GetILGenerator();
+ var il = dynamicMethod.GetILGenerator();
EmitLoadMethodArguments(il, constructor);
il.Emit(OpCodes.Newobj, constructor);
if (constructor.ReflectedType.IsValueType)
+ {
il.Emit(OpCodes.Box, constructor.ReflectedType);
+ }
il.Emit(OpCodes.Ret);
- return (ConstructorInjector) dynamicMethod.CreateDelegate(typeof(ConstructorInjector));
+ return (ConstructorInjector)dynamicMethod.CreateDelegate(typeof(ConstructorInjector));
}
///
@@ -55,13 +66,13 @@ public ConstructorInjector Create(ConstructorInfo constructor)
/// The created injector.
public PropertyInjector Create(PropertyInfo property)
{
- #if NO_SKIP_VISIBILITY
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) });
- #else
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }, true);
- #endif
-
- ILGenerator il = dynamicMethod.GetILGenerator();
+#if NO_SKIP_VISIBILITY
+ var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object), property.Module });
+#else
+ var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }, property.Module, true);
+#endif
+
+ var il = dynamicMethod.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
EmitUnboxOrCast(il, property.DeclaringType);
@@ -69,16 +80,12 @@ public PropertyInjector Create(PropertyInfo property)
il.Emit(OpCodes.Ldarg_1);
EmitUnboxOrCast(il, property.PropertyType);
- #if !SILVERLIGHT
- bool injectNonPublic = Settings.InjectNonPublic;
- #else
- const bool injectNonPublic = false;
- #endif // !SILVERLIGHT
+ var injectNonPublic = this.Settings.InjectNonPublic;
EmitMethodCall(il, property.GetSetMethod(injectNonPublic));
il.Emit(OpCodes.Ret);
- return (PropertyInjector) dynamicMethod.CreateDelegate(typeof(PropertyInjector));
+ return (PropertyInjector)dynamicMethod.CreateDelegate(typeof(PropertyInjector));
}
///
@@ -88,13 +95,13 @@ public PropertyInjector Create(PropertyInfo property)
/// The created injector.
public MethodInjector Create(MethodInfo method)
{
- #if NO_SKIP_VISIBILITY
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) });
- #else
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, true);
- #endif
+#if NO_SKIP_VISIBILITY
+ var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, method.Module);
+#else
+ var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, method.Module, true);
+#endif
- ILGenerator il = dynamicMethod.GetILGenerator();
+ var il = dynamicMethod.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
EmitUnboxOrCast(il, method.DeclaringType);
@@ -103,18 +110,20 @@ public MethodInjector Create(MethodInfo method)
EmitMethodCall(il, method);
if (method.ReturnType != typeof(void))
+ {
il.Emit(OpCodes.Pop);
+ }
il.Emit(OpCodes.Ret);
- return (MethodInjector) dynamicMethod.CreateDelegate(typeof(MethodInjector));
+ return (MethodInjector)dynamicMethod.CreateDelegate(typeof(MethodInjector));
}
private static void EmitLoadMethodArguments(ILGenerator il, MethodBase targetMethod)
{
- ParameterInfo[] parameters = targetMethod.GetParameters();
- OpCode ldargOpcode = targetMethod is ConstructorInfo ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1;
-
+ var parameters = targetMethod.GetParameters();
+ var ldargOpcode = targetMethod is ConstructorInfo ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1;
+
for (int idx = 0; idx < parameters.Length; idx++)
{
il.Emit(ldargOpcode);
@@ -127,14 +136,24 @@ private static void EmitLoadMethodArguments(ILGenerator il, MethodBase targetMet
private static void EmitMethodCall(ILGenerator il, MethodInfo method)
{
- OpCode opCode = method.IsFinal ? OpCodes.Call : OpCodes.Callvirt;
+ var opCode = method.IsFinal ? OpCodes.Call : OpCodes.Callvirt;
il.Emit(opCode, method);
}
private static void EmitUnboxOrCast(ILGenerator il, Type type)
{
- OpCode opCode = type.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass;
- il.Emit(opCode, type);
+ if (type.IsValueType)
+ {
+ il.Emit(OpCodes.Unbox_Any, type);
+ }
+ else if (type.IsPointer)
+ {
+ il.Emit(OpCodes.Call, UnboxPointer);
+ }
+ else
+ {
+ il.Emit(OpCodes.Castclass, type);
+ }
}
private static string GetAnonymousMethodName()
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/IInjectorFactory.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/IInjectorFactory.cs
index e8936929..b0c50c83 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/IInjectorFactory.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/IInjectorFactory.cs
@@ -1,20 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Creates injectors from members.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/MethodInjector.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/MethodInjector.cs
index 98e54476..a419a377 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/MethodInjector.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/MethodInjector.cs
@@ -1,16 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
///
- /// A delegate that can inject values into a method.
+ /// Represents a delegate that can inject values into a method.
///
+ /// The method info.
+ /// The arguments used for the method.
public delegate void MethodInjector(object target, params object[] arguments);
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/PropertyInjector.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/PropertyInjector.cs
index 30fed456..368a38cb 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/PropertyInjector.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/PropertyInjector.cs
@@ -1,16 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
///
- /// A delegate that can inject values into a property.
+ /// Represents a delegate that can inject values into a property.
///
+ /// The property info.
+ /// The value to be injected to the property.
public delegate void PropertyInjector(object target, object value);
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Injection/ReflectionInjectorFactory.cs b/Telerik.JustMock/AutoMock/Ninject/Injection/ReflectionInjectorFactory.cs
index d9e797b0..63ef58cd 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Injection/ReflectionInjectorFactory.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Injection/ReflectionInjectorFactory.cs
@@ -1,20 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Injection
{
+ using System.Reflection;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Creates injectors from members via reflective invocation.
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/KernelBase.cs b/Telerik.JustMock/AutoMock/Ninject/KernelBase.cs
index a5432cee..0febf571 100644
--- a/Telerik.JustMock/AutoMock/Ninject/KernelBase.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/KernelBase.cs
@@ -1,10 +1,23 @@
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
@@ -12,6 +25,7 @@ namespace Telerik.JustMock.AutoMock.Ninject
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+
using Telerik.JustMock.AutoMock.Ninject.Activation;
using Telerik.JustMock.AutoMock.Ninject.Activation.Blocks;
using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
@@ -31,17 +45,16 @@ namespace Telerik.JustMock.AutoMock.Ninject
///
public abstract class KernelBase : BindingRoot, IKernel
{
- ///
- /// Lock used when adding missing bindings.
- ///
- protected readonly object HandleMissingBindingLockObject = new object();
-
+ private readonly object handleMissingBindingLockObject = new object();
+
private readonly Multimap bindings = new Multimap();
- private readonly Multimap bindingCache = new Multimap();
+ private readonly Dictionary> bindingCache = new Dictionary>();
private readonly Dictionary modules = new Dictionary();
+ private readonly IBindingPrecedenceComparer bindingPrecedenceComparer;
+
///
/// Initializes a new instance of the class.
///
@@ -88,15 +101,16 @@ protected KernelBase(IComponentContainer components, INinjectSettings settings,
this.AddComponents();
+ this.bindingPrecedenceComparer = this.Components.Get();
+
this.Bind().ToConstant(this).InTransientScope();
this.Bind().ToConstant(this).InTransientScope();
-#if !NO_ASSEMBLY_SCANNING
if (this.Settings.LoadExtensions)
{
this.Load(this.Settings.ExtensionSearchPatterns);
}
-#endif
+
this.Load(modules);
}
@@ -113,9 +127,10 @@ protected KernelBase(IComponentContainer components, INinjectSettings settings,
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
if (this.Components != null)
{
@@ -168,7 +183,9 @@ public override void RemoveBinding(IBinding binding)
this.bindings.Remove(binding.Service, binding);
lock (this.bindingCache)
+ {
this.bindingCache.Clear();
+ }
}
///
@@ -206,10 +223,8 @@ public void Load(IEnumerable m)
{
throw new NotSupportedException(ExceptionFormatter.ModulesWithNullOrEmptyNamesAreNotSupported());
}
-
- INinjectModule existingModule;
- if (this.modules.TryGetValue(module.Name, out existingModule))
+ if (this.modules.TryGetValue(module.Name, out INinjectModule existingModule))
{
throw new NotSupportedException(ExceptionFormatter.ModuleWithSameNameIsAlreadyLoaded(module, existingModule));
}
@@ -225,7 +240,6 @@ public void Load(IEnumerable m)
}
}
-#if !NO_ASSEMBLY_SCANNING
///
/// Loads modules from the files that match the specified pattern(s).
///
@@ -244,7 +258,6 @@ public void Load(IEnumerable assemblies)
{
this.Load(assemblies.SelectMany(asm => asm.GetNinjectModules()));
}
-#endif //!NO_ASSEMBLY_SCANNING
///
/// Unloads the plugin with the specified name.
@@ -254,9 +267,7 @@ public void Unload(string name)
{
Ensure.ArgumentNotNullOrEmpty(name, "name");
- INinjectModule module;
-
- if (!this.modules.TryGetValue(name, out module))
+ if (!this.modules.TryGetValue(name, out INinjectModule module))
{
throw new NotSupportedException(ExceptionFormatter.NoModuleLoadedWithTheSpecifiedName(name));
}
@@ -337,57 +348,7 @@ public virtual bool CanResolve(IRequest request, bool ignoreImplicitBindings)
/// An enumerator of instances that match the request.
public virtual IEnumerable Resolve(IRequest request)
{
- Ensure.ArgumentNotNull(request, "request");
-
- var bindingPrecedenceComparer = this.GetBindingPrecedenceComparer();
- var resolveBindings = Enumerable.Empty();
-
- if (this.CanResolve(request) || this.HandleMissingBinding(request))
- {
- resolveBindings = this.GetBindings(request.Service)
- .Where(this.SatifiesRequest(request));
-
- }
-
- if (!resolveBindings.Any())
- {
- if (request.IsOptional)
- {
- return Enumerable.Empty();
- }
-
- throw new ActivationException(ExceptionFormatter.CouldNotResolveBinding(request));
- }
-
- if (request.IsUnique)
- {
- resolveBindings = resolveBindings.OrderByDescending(b => b, bindingPrecedenceComparer).ToList();
- var model = resolveBindings.First(); // the type (conditonal, implicit, etc) of binding we'll return
- resolveBindings =
- resolveBindings.TakeWhile(binding => bindingPrecedenceComparer.Compare(binding, model) == 0);
-
- if (resolveBindings.Count() > 1)
- {
- if (request.IsOptional)
- {
- return Enumerable.Empty();
- }
-
- var formattedBindings =
- from binding in resolveBindings
- let context = this.CreateContext(request, binding)
- select binding.Format(context);
- throw new ActivationException(ExceptionFormatter.CouldNotUniquelyResolveBinding(request, formattedBindings.ToArray()));
- }
- }
-
- if(resolveBindings.Any(binding => !binding.IsImplicit))
- {
- resolveBindings = resolveBindings.Where(binding => !binding.IsImplicit);
- }
-
- return resolveBindings
- .Select(binding => this.CreateContext(request, binding).Resolve());
+ return this.Resolve(request, true, false);
}
///
@@ -431,9 +392,12 @@ public virtual IEnumerable GetBindings(Type service)
{
var resolvers = this.Components.GetAll();
- resolvers
+ var compiledBindings = resolvers
.SelectMany(resolver => resolver.Resolve(this.bindings, service))
- .Map(binding => this.bindingCache.Add(service, binding));
+ .OrderByDescending(b => b, this.bindingPrecedenceComparer).ToList();
+ this.bindingCache.Add(service, compiledBindings);
+
+ return compiledBindings;
}
return this.bindingCache[service];
@@ -441,12 +405,15 @@ public virtual IEnumerable GetBindings(Type service)
}
///
- /// Returns an IComparer that is used to determine resolution precedence.
+ /// Gets the service object of the specified type.
///
- /// An IComparer that is used to determine resolution precedence.
- protected virtual IComparer GetBindingPrecedenceComparer()
+ /// The service type.
+ /// The service object
+ object IServiceProvider.GetService(Type service)
{
- return new BindingPrecedenceComparer();
+ return this.Settings.ThrowOnGetServiceNotFound
+ ? this.Get(service)
+ : this.TryGet(service);
}
///
@@ -464,17 +431,6 @@ protected virtual Func SatifiesRequest(IRequest request)
///
protected abstract void AddComponents();
- ///
- /// Attempts to handle a missing binding for a service.
- ///
- /// The service.
- /// True if the missing binding can be handled; otherwise false .
- [Obsolete]
- protected virtual bool HandleMissingBinding(Type service)
- {
- return false;
- }
-
///
/// Attempts to handle a missing binding for a request.
///
@@ -484,15 +440,8 @@ protected virtual bool HandleMissingBinding(IRequest request)
{
Ensure.ArgumentNotNull(request, "request");
-#pragma warning disable 612,618
- if (this.HandleMissingBinding(request.Service))
- {
- return true;
- }
-#pragma warning restore 612,618
-
var components = this.Components.GetAll();
-
+
// Take the first set of bindings that resolve.
var bindings = components
.Select(c => c.Resolve(this.bindings, request).ToList())
@@ -503,7 +452,7 @@ protected virtual bool HandleMissingBinding(IRequest request)
return false;
}
- lock (this.HandleMissingBindingLockObject)
+ lock (this.handleMissingBindingLockObject)
{
if (!this.CanResolve(request))
{
@@ -515,21 +464,6 @@ protected virtual bool HandleMissingBinding(IRequest request)
return true;
}
- ///
- /// Returns a value indicating whether the specified service is self-bindable.
- ///
- /// The service.
- /// if the type is self-bindable; otherwise .
- [Obsolete]
- protected virtual bool TypeIsSelfBindable(Type service)
- {
- return !service.IsInterface
- && !service.IsAbstract
- && !service.IsValueType
- && service != typeof(string)
- && !service.ContainsGenericParameters;
- }
-
///
/// Creates a context for the specified request and binding.
///
@@ -544,46 +478,122 @@ protected virtual IContext CreateContext(IRequest request, IBinding binding)
return new Context(this, request, binding, this.Components.Get(), this.Components.Get(), this.Components.Get());
}
- private void AddBindings(IEnumerable bindings)
+ private IEnumerable Resolve(IRequest request, bool handleMissingBindings, bool filterImplicitBindings)
{
- bindings.Map(binding => this.bindings.Add(binding.Service, binding));
+ void UpdateRequest(Type service)
+ {
+ if (request.ParentRequest == null)
+ {
+ request = this.CreateRequest(service, null, request.Parameters.Where(p => p.ShouldInherit), true, false);
+ }
+ else
+ {
+ request = request.ParentRequest.CreateChild(service, request.ParentContext, request.Target);
+ request.IsOptional = true;
+ }
+ }
- lock (this.bindingCache)
- this.bindingCache.Clear();
- }
+ if (request.Service.IsArray)
+ {
+ var service = request.Service.GetElementType();
- object IServiceProvider.GetService(Type service)
- {
- return this.Get(service);
- }
+ UpdateRequest(service);
- private class BindingPrecedenceComparer : IComparer
- {
- public int Compare(IBinding x, IBinding y)
+ return new[] { this.Resolve(request, false, true).CastSlow(service).ToArraySlow(service) };
+ }
+
+ if (request.Service.IsGenericType)
+ {
+ var gtd = request.Service.GetGenericTypeDefinition();
+
+ if (gtd == typeof(List<>) || gtd == typeof(IList<>) || gtd == typeof(ICollection<>))
+ {
+ var service = request.Service.GenericTypeArguments[0];
+
+ UpdateRequest(service);
+
+ return new[] { this.Resolve(request, false, true).CastSlow(service).ToListSlow(service) };
+ }
+
+ if (gtd == typeof(IEnumerable<>))
+ {
+ var service = request.Service.GenericTypeArguments[0];
+
+ UpdateRequest(service);
+
+ return new[] { this.Resolve(request, false, true).CastSlow(service) };
+ }
+ }
+
+ var satisfiedBindings = this.GetBindings(request.Service)
+ .Where(this.SatifiesRequest(request));
+
+ if (filterImplicitBindings)
+ {
+ satisfiedBindings = satisfiedBindings.Where(binding => binding.IsImplicit == false);
+ }
+
+ var satisfiedBindingEnumerator = satisfiedBindings.GetEnumerator();
+
+ if (!satisfiedBindingEnumerator.MoveNext())
+ {
+ if (handleMissingBindings && this.HandleMissingBinding(request))
+ {
+ return this.Resolve(request, false, false);
+ }
+
+ if (request.IsOptional)
+ {
+ return Enumerable.Empty();
+ }
+
+ throw new ActivationException(ExceptionFormatter.CouldNotResolveBinding(request));
+ }
+
+ if (request.IsUnique)
{
- if (x == y)
+ var selectedBinding = satisfiedBindingEnumerator.Current;
+
+ if (satisfiedBindingEnumerator.MoveNext() &&
+ this.bindingPrecedenceComparer.Compare(selectedBinding, satisfiedBindingEnumerator.Current) == 0)
{
- return 0;
+ if (request.IsOptional && !request.ForceUnique)
+ {
+ return Enumerable.Empty();
+ }
+
+ var formattedBindings =
+ from binding in satisfiedBindings
+ let context = this.CreateContext(request, binding)
+ select binding.Format(context);
+
+ throw new ActivationException(ExceptionFormatter.CouldNotUniquelyResolveBinding(
+ request,
+ formattedBindings.ToArray()));
+ }
+
+ return new[] { this.CreateContext(request, selectedBinding).Resolve() };
+ }
+ else
+ {
+ if (satisfiedBindings.Any(binding => !binding.IsImplicit))
+ {
+ satisfiedBindings = satisfiedBindings.Where(binding => !binding.IsImplicit);
}
- // Each function represents a level of precedence.
- var funcs = new List>
- {
- b => b != null, // null bindings should never happen, but just in case
- b => b.IsConditional, // conditional bindings > unconditional
- b => !b.Service.ContainsGenericParameters, // closed generics > open generics
- b => !b.IsImplicit, // explicit bindings > implicit
- };
-
- var q = from func in funcs
- let xVal = func(x)
- where xVal != func(y)
- select xVal ? 1 : -1;
-
- // returns the value of the first function that represents a difference
- // between the bindings, or else returns 0 (equal)
- return q.FirstOrDefault();
+ return satisfiedBindings
+ .Select(binding => this.CreateContext(request, binding).Resolve());
+ }
+ }
+
+ private void AddBindings(IEnumerable bindings)
+ {
+ bindings.Map(binding => this.bindings.Add(binding.Service, binding));
+
+ lock (this.bindingCache)
+ {
+ this.bindingCache.Clear();
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/AssemblyNameRetriever.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/AssemblyNameRetriever.cs
index 56e1d835..ec4584f9 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/AssemblyNameRetriever.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/AssemblyNameRetriever.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,9 +17,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
-#if !NO_ASSEMBLY_SCANNING
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
using System;
@@ -43,7 +42,7 @@ public class AssemblyNameRetriever : NinjectComponent, IAssemblyNameRetriever
/// All assembly names of the assemblies in the given files that match the filter.
public IEnumerable GetAssemblyNames(IEnumerable filenames, Predicate filter)
{
-#if !NO_APPDOMAIN_ISOLATION
+#if !NO_ASSEMBLY_SCANNING
var assemblyCheckerType = typeof(AssemblyChecker);
var temporaryDomain = CreateTemporaryAppDomain();
try
@@ -60,10 +59,10 @@ public IEnumerable GetAssemblyNames(IEnumerable filenames,
}
#else
return new AssemblyChecker().GetAssemblyNames(filenames, filter);
-#endif // !NO_APPDOMAIN_ISOLATION
+#endif
}
-#if !NO_APPDOMAIN_ISOLATION
+#if !NO_ASSEMBLY_SCANNING
///
/// Creates a temporary app domain.
///
@@ -75,7 +74,7 @@ private static AppDomain CreateTemporaryAppDomain()
AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.SetupInformation);
}
-#endif // !NO_APPDOMAIN_ISOLATION
+#endif
///
/// This class is loaded into the temporary appdomain to load and check if the assemblies match the filter.
@@ -98,20 +97,33 @@ public IEnumerable GetAssemblyNames(IEnumerable filenames,
{
try
{
- // .NET Core -> creates a new (anonymous) load context to load the assembly into.
- // https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/assemblyloadcontext.md#assembly-load-apis-and-loadcontext
- assembly = Assembly.LoadFile(filename);
+ assembly = Assembly.LoadFrom(filename);
}
catch (BadImageFormatException)
{
continue;
}
-
- if (filter(assembly))
+ }
+ else
+ {
+ try
{
- result.Add(assembly.GetName(false));
+ assembly = Assembly.Load(filename);
+ }
+ catch (FileLoadException)
+ {
+ continue;
+ }
+ catch (FileNotFoundException)
+ {
+ continue;
}
}
+
+ if (filter(assembly))
+ {
+ result.Add(assembly.GetName(false));
+ }
}
return result;
@@ -119,4 +131,3 @@ public IEnumerable GetAssemblyNames(IEnumerable filenames,
}
}
}
-#endif
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/CompiledModuleLoaderPlugin.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/CompiledModuleLoaderPlugin.cs
index fba18a39..1423c8b9 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/CompiledModuleLoaderPlugin.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/CompiledModuleLoaderPlugin.cs
@@ -1,12 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2007-2009, Enkari, Ltd.
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Nate Kohari (nate@enkari.com)
-// Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -19,9 +17,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
-#if !NO_ASSEMBLY_SCANNING
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
using System.Collections.Generic;
@@ -31,21 +28,21 @@ namespace Telerik.JustMock.AutoMock.Ninject.Modules
using Telerik.JustMock.AutoMock.Ninject.Components;
using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
-
+
///
/// Loads modules from compiled assemblies.
///
public class CompiledModuleLoaderPlugin : NinjectComponent, IModuleLoaderPlugin
{
///
- /// The assembly name retriever.
+ /// The file extensions that are supported.
///
- private readonly IAssemblyNameRetriever assemblyNameRetriever;
+ private static readonly string[] Extensions = { ".dll" };
///
- /// The file extensions that are supported.
+ /// The assembly name retriever.
///
- private static readonly string[] Extensions = new[] { ".dll" };
+ private readonly IAssemblyNameRetriever assemblyNameRetriever;
///
/// Initializes a new instance of the class.
@@ -55,6 +52,8 @@ public class CompiledModuleLoaderPlugin : NinjectComponent, IModuleLoaderPlugin
public CompiledModuleLoaderPlugin(IKernel kernel, IAssemblyNameRetriever assemblyNameRetriever)
{
Ensure.ArgumentNotNull(kernel, "kernel");
+ Ensure.ArgumentNotNull(assemblyNameRetriever, "assemblyNameRetriever");
+
this.Kernel = kernel;
this.assemblyNameRetriever = assemblyNameRetriever;
}
@@ -82,5 +81,4 @@ public void LoadModules(IEnumerable filenames)
this.Kernel.Load(assembliesWithModules.Select(asm => Assembly.Load(asm)));
}
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/IAssemblyNameRetriever.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/IAssemblyNameRetriever.cs
index f0615207..3201ba63 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/IAssemblyNameRetriever.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/IAssemblyNameRetriever.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,9 +17,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
-#if !NO_ASSEMBLY_SCANNING
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
using System;
@@ -41,5 +40,4 @@ public interface IAssemblyNameRetriever : INinjectComponent
/// All assembly names of the assemblies in the given files that match the filter.
IEnumerable GetAssemblyNames(IEnumerable filenames, Predicate filter);
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoader.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoader.cs
index ed7131a7..9142ebba 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoader.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoader.cs
@@ -1,21 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !SILVERLIGHT
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Finds modules defined in external files.
///
@@ -27,5 +36,4 @@ public interface IModuleLoader : INinjectComponent
/// The patterns to search.
void LoadModules(IEnumerable patterns);
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoaderPlugin.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoaderPlugin.cs
index c04f8c7b..b1044eca 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoaderPlugin.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/IModuleLoaderPlugin.cs
@@ -1,21 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !SILVERLIGHT
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+
///
/// Loads modules at runtime by searching external files.
///
@@ -32,5 +41,4 @@ public interface IModuleLoaderPlugin : INinjectComponent
/// The names of the files to load modules from.
void LoadModules(IEnumerable filenames);
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/INinjectModule.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/INinjectModule.cs
index d66516bc..b163b031 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/INinjectModule.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/INinjectModule.cs
@@ -1,20 +1,28 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Syntax;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+
///
/// A pluggable unit that can be loaded into an .
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/ModuleLoader.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/ModuleLoader.cs
index cf1f10d4..4c0e39a1 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/ModuleLoader.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/ModuleLoader.cs
@@ -1,34 +1,39 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !NO_ASSEMBLY_SCANNING
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using Telerik.JustMock.AutoMock.Ninject.Components;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+
+ using Telerik.JustMock.AutoMock.Ninject.Components;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+
///
/// Automatically finds and loads modules from assemblies.
///
public class ModuleLoader : NinjectComponent, IModuleLoader
{
- ///
- /// Gets or sets the kernel into which modules will be loaded.
- ///
- public IKernel Kernel { get; private set; }
-
///
/// Initializes a new instance of the class.
///
@@ -36,16 +41,22 @@ public class ModuleLoader : NinjectComponent, IModuleLoader
public ModuleLoader(IKernel kernel)
{
Ensure.ArgumentNotNull(kernel, "kernel");
- Kernel = kernel;
+
+ this.Kernel = kernel;
}
+ ///
+ /// Gets the kernel into which modules will be loaded.
+ ///
+ public IKernel Kernel { get; private set; }
+
///
/// Loads any modules found in the files that match the specified patterns.
///
/// The patterns to search.
public void LoadModules(IEnumerable patterns)
{
- var plugins = Kernel.Components.GetAll();
+ var plugins = this.Kernel.Components.GetAll();
var fileGroups = patterns
.SelectMany(pattern => GetFilesMatchingPattern(pattern))
@@ -53,11 +64,13 @@ public void LoadModules(IEnumerable patterns)
foreach (var fileGroup in fileGroups)
{
- string extension = fileGroup.Key;
- IModuleLoaderPlugin plugin = plugins.Where(p => p.SupportedExtensions.Contains(extension)).FirstOrDefault();
+ var extension = fileGroup.Key;
+ var plugin = plugins.Where(p => p.SupportedExtensions.Contains(extension)).FirstOrDefault();
if (plugin != null)
+ {
plugin.LoadModules(fileGroup);
+ }
}
}
@@ -71,7 +84,8 @@ private static IEnumerable NormalizePaths(string path)
{
return Path.IsPathRooted(path)
? new[] { Path.GetFullPath(path) }
- : GetBaseDirectories().Select(baseDirectory => Path.Combine(baseDirectory, path));
+ : GetBaseDirectories().Select(baseDirectory => Path.Combine(baseDirectory, path))
+ .Where(Directory.Exists);
}
private static IEnumerable GetBaseDirectories()
@@ -79,11 +93,10 @@ private static IEnumerable GetBaseDirectories()
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var searchPath = AppDomain.CurrentDomain.RelativeSearchPath;
- return String.IsNullOrEmpty(searchPath)
- ? new[] {baseDirectory}
- : searchPath.Split(new[] {Path.PathSeparator}, StringSplitOptions.RemoveEmptyEntries)
+ return string.IsNullOrEmpty(searchPath)
+ ? new[] { baseDirectory }
+ : searchPath.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries)
.Select(path => Path.Combine(baseDirectory, path));
}
}
}
-#endif //!NO_ASSEMBLY_SCANNING
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Modules/NinjectModule.cs b/Telerik.JustMock/AutoMock/Ninject/Modules/NinjectModule.cs
index c74859dd..a61bafde 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Modules/NinjectModule.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Modules/NinjectModule.cs
@@ -1,12 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2007-2009, Enkari, Ltd.
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Nate Kohari (nate@enkari.com)
-// Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -19,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Modules
{
@@ -54,7 +52,7 @@ protected NinjectModule()
///
public virtual string Name
{
- get { return GetType().FullName; }
+ get { return this.GetType().FullName; }
}
///
@@ -73,7 +71,7 @@ protected override IKernel KernelInstance
return this.Kernel;
}
}
-
+
///
/// Called when the module is loaded into a kernel.
///
@@ -81,6 +79,7 @@ protected override IKernel KernelInstance
public void OnLoad(IKernel kernel)
{
Ensure.ArgumentNotNull(kernel, "kernel");
+
this.Kernel = kernel;
this.Load();
}
@@ -92,6 +91,7 @@ public void OnLoad(IKernel kernel)
public void OnUnload(IKernel kernel)
{
Ensure.ArgumentNotNull(kernel, "kernel");
+
this.Unload();
this.Bindings.Map(this.Kernel.RemoveBinding);
this.Kernel = null;
diff --git a/Telerik.JustMock/AutoMock/Ninject/NinjectSettings.cs b/Telerik.JustMock/AutoMock/Ninject/NinjectSettings.cs
index 894c198e..478efbad 100644
--- a/Telerik.JustMock/AutoMock/Ninject/NinjectSettings.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/NinjectSettings.cs
@@ -1,36 +1,46 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject
{
+ using System;
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+
///
/// Contains configuration options for Ninject.
///
public class NinjectSettings : INinjectSettings
{
- private readonly Dictionary _values = new Dictionary();
+ private readonly Dictionary values = new Dictionary();
///
/// Gets or sets the attribute that indicates that a member should be injected.
///
public Type InjectAttribute
{
- get { return Get("InjectAttribute", typeof(InjectAttribute)); }
- set { Set("InjectAttribute", value); }
+ get { return this.Get("InjectAttribute", typeof(InjectAttribute)); }
+ set { this.Set("InjectAttribute", value); }
}
///
@@ -38,8 +48,8 @@ public Type InjectAttribute
///
public TimeSpan CachePruningInterval
{
- get { return Get("CachePruningInterval", TimeSpan.FromSeconds(30)); }
- set { Set("CachePruningInterval", value); }
+ get { return this.Get("CachePruningInterval", TimeSpan.FromSeconds(30)); }
+ set { this.Set("CachePruningInterval", value); }
}
///
@@ -47,18 +57,17 @@ public TimeSpan CachePruningInterval
///
public Func DefaultScopeCallback
{
- get { return Get("DefaultScopeCallback", StandardScopeCallbacks.Transient); }
- set { Set("DefaultScopeCallback", value); }
+ get { return this.Get("DefaultScopeCallback", StandardScopeCallbacks.Transient); }
+ set { this.Set("DefaultScopeCallback", value); }
}
- #if !NO_ASSEMBLY_SCANNING
///
/// Gets or sets a value indicating whether the kernel should automatically load extensions at startup.
///
public bool LoadExtensions
{
- get { return Get("LoadExtensions", true); }
- set { Set("LoadExtensions", value); }
+ get { return this.Get("LoadExtensions", true); }
+ set { this.Set("LoadExtensions", value); }
}
///
@@ -66,38 +75,36 @@ public bool LoadExtensions
///
public string[] ExtensionSearchPatterns
{
- get { return Get("ExtensionSearchPatterns", new [] { "Ninject.Extensions.*.dll", "Ninject.Web*.dll" }); }
- set { Set("ExtensionSearchPatterns", value); }
+ get { return this.Get("ExtensionSearchPatterns", new[] { "Ninject.Extensions.*.dll", "Ninject.Web*.dll" }); }
+ set { this.Set("ExtensionSearchPatterns", value); }
}
- #endif //!NO_ASSEMBLY_SCANNING
- #if !NO_LCG
+#if !NO_LCG
///
- /// Gets a value indicating whether Ninject should use reflection-based injection instead of
+ /// Gets or sets a value indicating whether Ninject should use reflection-based injection instead of
/// the (usually faster) lightweight code generation system.
///
public bool UseReflectionBasedInjection
{
- get { return Get("UseReflectionBasedInjection", false); }
- set { Set("UseReflectionBasedInjection", value); }
+ get { return this.Get("UseReflectionBasedInjection", false); }
+ set { this.Set("UseReflectionBasedInjection", value); }
}
- #endif //!NO_LCG
+#endif //!NO_LCG
- #if !SILVERLIGHT
///
- /// Gets a value indicating whether Ninject should inject non public members.
+ /// Gets or sets a value indicating whether Ninject should inject non public members.
///
public bool InjectNonPublic
{
- get { return Get("InjectNonPublic", false); }
- set { Set("InjectNonPublic", value); }
+ get { return this.Get("InjectNonPublic", false); }
+ set { this.Set("InjectNonPublic", value); }
}
///
- /// Gets a value indicating whether Ninject should inject private properties of base classes.
+ /// Gets or sets a value indicating whether Ninject should inject private properties of base classes.
///
///
- /// Activating this setting has an impact on the performance. It is recomended not
+ /// Activating this setting has an impact on the performance. It is recommended not
/// to use this feature and use constructor injection instead.
///
public bool InjectParentPrivateProperties
@@ -105,7 +112,6 @@ public bool InjectParentPrivateProperties
get { return this.Get("InjectParentPrivateProperties", false); }
set { this.Set("InjectParentPrivateProperties", value); }
}
- #endif //!SILVERLIGHT
///
/// Gets or sets a value indicating whether the activation cache is disabled.
@@ -115,7 +121,7 @@ public bool InjectParentPrivateProperties
/// Bind{IA}().ToMethod(ctx => kernel.Get{IA}();
///
///
- /// true if activation cache is disabled; otherwise, false .
+ /// true if activation cache is disabled; otherwise, false .
///
public bool ActivationCacheDisabled
{
@@ -128,7 +134,7 @@ public bool ActivationCacheDisabled
/// By default this is disabled and whenever a provider returns null an exception is thrown.
///
///
- /// true if null is allowed as injected value otherwise false.
+ /// true if null is allowed as injected value otherwise false.
///
public bool AllowNullInjection
{
@@ -136,6 +142,18 @@ public bool AllowNullInjection
set { this.Set("AllowNullInjection", value); }
}
+ ///
+ /// Gets or sets a value indicating whether the old (<= 3.3.4) behavior of
+ /// should be used which throws an exception if the requested service cannot be found. Note that the documentation
+ /// of that method https://docs.microsoft.com/en-us/dotnet/api/system.iserviceprovider.getservice?view=netframework-4.6.2
+ /// states that the method should return if there is no such service.
+ ///
+ public bool ThrowOnGetServiceNotFound
+ {
+ get { return this.Get("ThrowOnGetServiceNotFound", false); }
+ set { this.Set("ThrowOnGetServiceNotFound", value); }
+ }
+
///
/// Gets the value for the specified key.
///
@@ -145,8 +163,7 @@ public bool AllowNullInjection
/// The value, or the default value if none was found.
public T Get(string key, T defaultValue)
{
- object value;
- return _values.TryGetValue(key, out value) ? (T)value : defaultValue;
+ return this.values.TryGetValue(key, out object value) ? (T)value : defaultValue;
}
///
@@ -156,7 +173,7 @@ public T Get(string key, T defaultValue)
/// The setting's value.
public void Set(string key, object value)
{
- _values[key] = value;
+ this.values[key] = value;
}
}
-}
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/ConstructorArgument.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/ConstructorArgument.cs
index 0a853c79..3b07f685 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/ConstructorArgument.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/ConstructorArgument.cs
@@ -1,12 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2007-2009, Enkari, Ltd.
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Nate Kohari (nate@enkari.com)
-// Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -19,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
@@ -102,7 +100,7 @@ public ConstructorArgument(string name, Func valueCal
/// The context.
/// The target.
///
- /// Tre if the parameter applies in the specified context to the specified target.
+ /// True if the parameter applies in the specified context to the specified target.
///
///
/// Only one parameter may return true.
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/IConstructorArgument.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/IConstructorArgument.cs
index 38c2c6e0..bc2f09cc 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/IConstructorArgument.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/IConstructorArgument.cs
@@ -1,4 +1,25 @@
-namespace Telerik.JustMock.AutoMock.Ninject.Parameters
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
+namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
using Telerik.JustMock.AutoMock.Ninject.Activation;
using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
@@ -16,7 +37,7 @@ public interface IConstructorArgument : IParameter
///
/// The context.
/// The target.
- /// Tre if the parameter applies in the specified context to the specified target.
+ /// True if the parameter applies in the specified context to the specified target.
bool AppliesToTarget(IContext context, ITarget target);
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/IParameter.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/IParameter.cs
index 741271f9..09a0bbe7 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/IParameter.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/IParameter.cs
@@ -1,19 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
///
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/IPropertyValue.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/IPropertyValue.cs
index d7436908..3f698ec9 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/IPropertyValue.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/IPropertyValue.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2013 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
@@ -25,6 +25,6 @@ namespace Telerik.JustMock.AutoMock.Ninject.Parameters
/// Overrides the injected value of a property.
///
public interface IPropertyValue : IParameter
- {
+ {
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/Parameter.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/Parameter.cs
index 942919b0..f942a5c1 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/Parameter.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/Parameter.cs
@@ -1,20 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
///
@@ -22,28 +32,16 @@ namespace Telerik.JustMock.AutoMock.Ninject.Parameters
///
public class Parameter : IParameter
{
- ///
- /// Gets the name of the parameter.
- ///
- public string Name { get; private set; }
-
- ///
- /// Gets a value indicating whether the parameter should be inherited into child requests.
- ///
- public bool ShouldInherit { get; private set; }
-
- ///
- /// Gets or sets the callback that will be triggered to get the parameter's value.
- ///
- public Func ValueCallback { get; internal set; }
-
///
/// Initializes a new instance of the class.
///
/// The name of the parameter.
/// The value of the parameter.
/// Whether the parameter should be inherited into child requests.
- public Parameter(string name, object value, bool shouldInherit) : this(name, (ctx, target) => value, shouldInherit) { }
+ public Parameter(string name, object value, bool shouldInherit)
+ : this(name, (ctx, target) => value, shouldInherit)
+ {
+ }
///
/// Initializes a new instance of the class.
@@ -56,9 +54,9 @@ public Parameter(string name, Func valueCallback, bool shouldI
Ensure.ArgumentNotNullOrEmpty(name, "name");
Ensure.ArgumentNotNull(valueCallback, "valueCallback");
- Name = name;
- ValueCallback = (ctx, target) => valueCallback(ctx);
- ShouldInherit = shouldInherit;
+ this.Name = name;
+ this.ValueCallback = (ctx, target) => valueCallback(ctx);
+ this.ShouldInherit = shouldInherit;
}
///
@@ -72,11 +70,26 @@ public Parameter(string name, Func valueCallback, boo
Ensure.ArgumentNotNullOrEmpty(name, "name");
Ensure.ArgumentNotNull(valueCallback, "valueCallback");
- Name = name;
- ValueCallback = valueCallback;
- ShouldInherit = shouldInherit;
+ this.Name = name;
+ this.ValueCallback = valueCallback;
+ this.ShouldInherit = shouldInherit;
}
-
+
+ ///
+ /// Gets the name of the parameter.
+ ///
+ public string Name { get; private set; }
+
+ ///
+ /// Gets a value indicating whether the parameter should be inherited into child requests.
+ ///
+ public bool ShouldInherit { get; private set; }
+
+ ///
+ /// Gets the callback that will be triggered to get the parameter's value.
+ ///
+ public Func ValueCallback { get; internal set; }
+
///
/// Gets the value for the parameter within the specified context.
///
@@ -86,7 +99,8 @@ public Parameter(string name, Func valueCallback, boo
public object GetValue(IContext context, ITarget target)
{
Ensure.ArgumentNotNull(context, "context");
- return ValueCallback(context, target);
+
+ return this.ValueCallback(context, target);
}
///
@@ -97,7 +111,7 @@ public object GetValue(IContext context, ITarget target)
public override bool Equals(object obj)
{
var parameter = obj as IParameter;
- return parameter != null ? Equals(parameter) : base.Equals(obj);
+ return parameter != null ? this.Equals(parameter) : base.Equals(obj);
}
///
@@ -106,7 +120,7 @@ public override bool Equals(object obj)
/// A hash code for the object.
public override int GetHashCode()
{
- return GetType().GetHashCode() ^ Name.GetHashCode();
+ return this.GetType().GetHashCode() ^ this.Name.GetHashCode();
}
///
@@ -116,7 +130,7 @@ public override int GetHashCode()
/// True if the objects are equal; otherwise false
public bool Equals(IParameter other)
{
- return other.GetType() == GetType() && other.Name.Equals(Name);
+ return other.GetType() == this.GetType() && other.Name.Equals(this.Name);
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/PropertyValue.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/PropertyValue.cs
index b0905048..2ac164d5 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/PropertyValue.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/PropertyValue.cs
@@ -1,19 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
///
@@ -26,20 +36,29 @@ public class PropertyValue : Parameter, IPropertyValue
///
/// The name of the property to override.
/// The value to inject into the property.
- public PropertyValue(string name, object value) : base(name, value, false) { }
+ public PropertyValue(string name, object value)
+ : base(name, value, false)
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The name of the property to override.
/// The callback to invoke to get the value that should be injected.
- public PropertyValue(string name, Func valueCallback) : base(name, valueCallback, false) { }
+ public PropertyValue(string name, Func valueCallback)
+ : base(name, valueCallback, false)
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The name of the property to override.
/// The callback to invoke to get the value that should be injected.
- public PropertyValue(string name, Func valueCallback) : base(name, valueCallback, false) { }
+ public PropertyValue(string name, Func valueCallback)
+ : base(name, valueCallback, false)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/TypeMatchingConstructorArgument.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/TypeMatchingConstructorArgument.cs
new file mode 100644
index 00000000..81d1d13a
--- /dev/null
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/TypeMatchingConstructorArgument.cs
@@ -0,0 +1,144 @@
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
+
+namespace Telerik.JustMock.AutoMock.Ninject.Parameters
+{
+ using System;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
+
+ ///
+ /// Overrides the injected value of a constructor argument.
+ ///
+ public class TypeMatchingConstructorArgument : IConstructorArgument
+ {
+ private readonly Type type;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type of the argument to override.
+ /// The callback that will be triggered to get the parameter's value.
+ public TypeMatchingConstructorArgument(Type type, Func valueCallback)
+ : this(type, valueCallback, false)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type of the argument to override.
+ /// The callback that will be triggered to get the parameter's value.
+ /// Whether the parameter should be inherited into child requests.
+ public TypeMatchingConstructorArgument(Type type, Func valueCallback, bool shouldInherit)
+ {
+ Ensure.ArgumentNotNull(type, "type");
+ Ensure.ArgumentNotNull(valueCallback, "valueCallback");
+
+ this.ValueCallback = valueCallback;
+ this.ShouldInherit = shouldInherit;
+ this.type = type;
+ }
+
+ ///
+ /// Gets the name of the parameter.
+ ///
+ public string Name
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether the parameter should be inherited into child requests.
+ ///
+ public bool ShouldInherit { get; private set; }
+
+ ///
+ /// Gets or sets the callback that will be triggered to get the parameter's value.
+ ///
+ private Func ValueCallback { get; set; }
+
+ ///
+ /// Determines if the parameter applies to the given target.
+ ///
+ /// The context.
+ /// The target.
+ ///
+ /// True if the parameter applies in the specified context to the specified target.
+ ///
+ ///
+ /// Only one parameter may return true.
+ ///
+ public bool AppliesToTarget(IContext context, ITarget target)
+ {
+ return target.Type == this.type;
+ }
+
+ ///
+ /// Gets the value for the parameter within the specified context.
+ ///
+ /// The context.
+ /// The target.
+ /// The value for the parameter.
+ public object GetValue(IContext context, ITarget target)
+ {
+ Ensure.ArgumentNotNull(context, "context");
+
+ return this.ValueCallback(context, target);
+ }
+
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ /// True if the objects are equal; otherwise false
+ public bool Equals(IParameter other)
+ {
+ var argument = other as TypeMatchingConstructorArgument;
+ return argument != null && argument.type == this.type;
+ }
+
+ ///
+ /// Determines whether the object equals the specified object.
+ ///
+ /// An object to compare with this object.
+ /// True if the objects are equal; otherwise false
+ public override bool Equals(object obj)
+ {
+ var parameter = obj as IParameter;
+ return parameter != null ? this.Equals(parameter) : ReferenceEquals(this, obj);
+ }
+
+ ///
+ /// Serves as a hash function for a particular type.
+ ///
+ /// A hash code for the object.
+ public override int GetHashCode()
+ {
+ return this.GetType().GetHashCode() ^ this.type.GetHashCode();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakConstructorArgument.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakConstructorArgument.cs
index 5c3ffac1..862e70f2 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakConstructorArgument.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakConstructorArgument.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2013 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
@@ -37,7 +37,7 @@ public class WeakConstructorArgument : Parameter, IConstructorArgument
private readonly WeakReference weakReference;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The name of the argument to override.
/// The value to inject into the property.
@@ -47,7 +47,7 @@ public WeakConstructorArgument(string name, object value)
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The name of the argument to override.
/// The value to inject into the property.
@@ -65,7 +65,7 @@ public WeakConstructorArgument(string name, object value, bool shouldInherit)
/// The context.
/// The target.
///
- /// Tre if the parameter applies in the specified context to the specified target.
+ /// True if the parameter applies in the specified context to the specified target.
///
///
/// Only one parameter may return true.
@@ -75,4 +75,4 @@ public bool AppliesToTarget(IContext context, ITarget target)
return string.Equals(this.Name, target.Name);
}
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakPropertyValue.cs b/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakPropertyValue.cs
index ca5d2fb2..f404e716 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakPropertyValue.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Parameters/WeakPropertyValue.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2013 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// you may not use this file except in compliance with one of the Licenses.
+// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -17,7 +17,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Parameters
{
@@ -40,8 +40,7 @@ public WeakPropertyValue(string name, object value)
: base(name, (object)null, false)
{
this.weakReference = new WeakReference(value);
- this.ValueCallback = (ctx, target) => this.weakReference.Target;
+ this.ValueCallback = (ctx, target) => this.weakReference.Target;
}
-
}
-}
\ No newline at end of file
+}
diff --git a/Telerik.JustMock/AutoMock/Ninject/Planning/Bindings/Binding.cs b/Telerik.JustMock/AutoMock/Ninject/Planning/Bindings/Binding.cs
index e4707d31..b8244963 100644
--- a/Telerik.JustMock/AutoMock/Ninject/Planning/Bindings/Binding.cs
+++ b/Telerik.JustMock/AutoMock/Ninject/Planning/Bindings/Binding.cs
@@ -1,22 +1,33 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Telerik.JustMock.AutoMock.Ninject.Activation;
-using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
-using Telerik.JustMock.AutoMock.Ninject.Parameters;
-#endregion
+// -------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010 Enkari, Ltd. All rights reserved.
+// Copyright (c) 2010-2017 Ninject Project Contributors. All rights reserved.
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// You may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -------------------------------------------------------------------------------------------------
namespace Telerik.JustMock.AutoMock.Ninject.Planning.Bindings
{
+ using System;
+ using System.Collections.Generic;
+
+ using Telerik.JustMock.AutoMock.Ninject.Activation;
+ using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
+ using Telerik.JustMock.AutoMock.Ninject.Parameters;
+
///
/// Contains information about a service registration.
///
@@ -49,7 +60,7 @@ public Binding(Type service, IBindingConfiguration configuration)
}
///
- /// Gets or sets the binding configuration.
+ /// Gets the binding configuration.
///
/// The binding configuration.
public IBindingConfiguration BindingConfiguration { get; private set; }
@@ -62,7 +73,6 @@ public Binding(Type service, IBindingConfiguration configuration)
///
/// Gets the binding's metadata.
///
- ///
public IBindingMetadata Metadata
{
get
@@ -74,7 +84,6 @@ public IBindingMetadata Metadata
///
/// Gets or sets the type of target for the binding.
///
- ///
public BindingTarget Target
{
get
@@ -91,7 +100,6 @@ public BindingTarget Target
///
/// Gets or sets a value indicating whether the binding was implicitly registered.
///
- ///
public bool IsImplicit
{
get
@@ -108,7 +116,6 @@ public bool IsImplicit
///
/// Gets a value indicating whether the binding has a condition associated with it.
///
- ///
public bool IsConditional
{
get
@@ -120,13 +127,13 @@ public bool IsConditional
///
/// Gets or sets the condition defined for the binding.
///
- ///
public Func Condition
{
get
{
return this.BindingConfiguration.Condition;
}
+
set
{
this.BindingConfiguration.Condition = value;
@@ -136,7 +143,6 @@ public Func Condition
///
/// Gets or sets the callback that returns the provider that should be used by the binding.
///
- ///
public Func ProviderCallback
{
get
@@ -153,13 +159,13 @@ public Func ProviderCallback
///
/// Gets or sets the callback that returns the object that will act as the binding's scope.
///
- ///
public Func ScopeCallback
{
get
{
return this.BindingConfiguration.ScopeCallback;
}
+
set
{
this.BindingConfiguration.ScopeCallback = value;
@@ -169,7 +175,6 @@ public Func ScopeCallback
///
/// Gets the parameters defined for the binding.
///
- ///
public ICollection Parameters
{
get
@@ -181,7 +186,6 @@ public ICollection Parameters
///
/// Gets the actions that should be called after instances are activated via the binding.
///
- ///
public ICollection> ActivationActions
{
get
@@ -193,7 +197,6 @@ public ICollection