using System;
using Ninject.Activation.Caching;
using Ninject.Planning.Bindings;
namespace Ninject.Moq
{
///
/// A kernel that will create mocked instances (via Moq) for any service that is
/// requested for which no binding is registered.
///
public class MockingKernel : StandardKernel
{
///
/// Clears the kernel's cache, immediately deactivating all activated instances regardless of scope.
/// This does not remove any modules, extensions, or bindings.
///
public void Reset()
{
Components.Get().Clear();
}
///
/// Attempts to handle a missing binding for a service.
///
/// The service.
/// True if the missing binding can be handled; otherwise false.
protected override bool HandleMissingBinding(Type service)
{
var binding = new Binding(service)
{
ProviderCallback = MockProvider.GetCreationCallback(),
ScopeCallback = ctx => null,
IsImplicit = true
};
AddBinding(binding);
return true;
}
}
}