/// <summary> /// Checkes whether a binding exists for a given target on the specified kernel. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="context">The context.</param> /// <param name="target">The target.</param> /// <returns>Whether a binding exists for the target in the given context.</returns> protected virtual bool BindingExists(IReadonlyKernel kernel, IContext context, ITarget target) { var targetType = GetTargetType(target); return(kernel.GetBindings(targetType).Any(b => !b.IsImplicit) || target.HasDefaultValue); }
internal static void RegisterKernelForType(IReadonlyKernel kernel, Type type) { #if PCL throw new NotImplementedException(); #else var registration = GetRegistrationForType(type); #if !WINRT registration.KernelLock.AcquireReaderLock(Timeout.Infinite); #else registration.KernelLock.EnterReadLock(); #endif try { registration.Kernels.Add(new WeakReference(kernel)); } finally { #if !WINRT registration.KernelLock.ReleaseReaderLock(); #else registration.KernelLock.ExitReadLock(); #endif } #endif }
internal static void UnregisterKernelForType(IReadonlyKernel kernel, Type type) { #if PCL throw new NotImplementedException(); #else var registration = GetRegistrationForType(type); RemoveKernels(registration, registration.Kernels.Where(reference => reference.Target == kernel || !reference.IsAlive)); #endif }
/// <summary> /// Initializes a new instance of the <see cref="Context"/> class. /// </summary> /// <param name="readonlyKernel">The kernel managing the resolution.</param> /// <param name="request">The context's request.</param> /// <param name="binding">The context's binding.</param> /// <param name="cache">The cache component.</param> /// <param name="planner">The planner component.</param> /// <param name="pipeline">The pipeline component.</param> public Context(IReadonlyKernel readonlyKernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline) { this.Kernel = readonlyKernel; 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.GetTypeInfo().IsGenericTypeDefinition) { HasInferredGenericArguments = true; GenericArguments = request.Service.GetTypeInfo().GenericTypeArguments; } }
internal static void RegisterKernelForType(IReadonlyKernel kernel, Type type) { #if PCL throw new NotImplementedException(); #else var registration = GetRegistrationForType(type); registration.KernelLock.EnterReadLock(); try { registration.Kernels.Add(new WeakReference(kernel)); } finally { registration.KernelLock.ExitReadLock(); } #endif }
public NinjectServiceLocator(IReadonlyKernel kernel) { Kernel = kernel; }
/// <summary> /// Checkes whether a binding exists for a given target on the specified kernel. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="context">The context.</param> /// <param name="target">The target.</param> /// <returns>Whether a binding exists for the target in the given context.</returns> protected virtual bool BindingExists(IReadonlyKernel kernel, IContext context, ITarget target) { var targetType = GetTargetType(target); return kernel.GetBindings(targetType).Any(b => !b.IsImplicit) || target.HasDefaultValue; }