Documentation Coverage Report
Current view: top level - Ninject/Cqrs.Ninject/Configuration - ResolvableModule.cs Hit Total Coverage
Version: 2.2 Artefacts: 5 5 100.0 %
Date: 2017-09-22

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.Linq;
      11             : using Ninject.Modules;
      12             : using Ninject.Parameters;
      13             : 
      14             : namespace Cqrs.Ninject.Configuration
      15             : {
      16             :         /// <summary>
      17             :         /// A <see cref="INinjectModule"/> that can resolve anything bound before being called.
      18             :         /// </summary>
      19             :         public abstract class ResolvableModule : NinjectModule
      20           1 :         {
      21             :                 /// <summary>
      22             :                 /// Resolves instances for the specified <typeparamref name="T"/>.
      23             :                 /// </summary>
      24             :                 /// <typeparam name="T">The <see cref="Type"/> to resolve.</typeparam>
      25             :                 /// <returns>Null if no resolution is made.</returns>
      26           1 :                 protected virtual T Resolve<T>()
      27             :                 {
      28             :                         return (T)Resolve(typeof(T));
      29             :                 }
      30             : 
      31             :                 /// <summary>
      32             :                 /// Resolves instances for the specified <paramref name="type"/>.
      33             :                 /// </summary>
      34             :                 /// <param name="type">The <see cref="Type"/> to resolve.</param>
      35             :                 /// <returns>Null if no resolution is made.</returns>
      36           1 :                 protected virtual object Resolve(Type type)
      37             :                 {
      38             :                         return Kernel.Resolve(Kernel.CreateRequest(type, null, new Parameter[0], true, true)).SingleOrDefault();
      39             :                 }
      40             : 
      41             :                 /// <summary>
      42             :                 /// Indicates if the provided <typeparamref name="T"/> is already registered or not.
      43             :                 /// </summary>
      44             :                 /// <typeparam name="T">The <see cref="Type"/> to check.</typeparam>
      45           1 :                 public bool IsRegistered<T>()
      46             :                 {
      47             :                         return IsRegistered(typeof(T));
      48             :                 }
      49             : 
      50             :                 /// <summary>
      51             :                 /// Indicates if the provided <paramref name="type"/> is already registered or not.
      52             :                 /// </summary>
      53             :                 /// <param name="type">The <see cref="Type"/> to check.</param>
      54           1 :                 public bool IsRegistered(Type type)
      55             :                 {
      56             :                         return Kernel.GetBindings(type).Any();
      57             :                 }
      58             :         }
      59             : }

Generated by: LCOV version 1.10