public void LoadModule(INinjectModule module)
 {
     if (!Kernel.HasModule(module.Name) && !IsModuleDisabled(module.GetType()))
     {
         Kernel.Load(module);
     }
 }
示例#2
0
        public static void LoadModuleIfNotLoaded(INinjectModule module)
        {
            var modules = _kernel.GetModules();

            if (modules.Any(x => x.GetType() == module.GetType()))
            {
                return;
            }

            _kernel.Load(module);
        }
示例#3
0
 /// <summary>
 /// Загружаем еще один Ninject-модуль
 /// </summary>
 /// <param name="module">модуль</param>
 public static void Load(INinjectModule module)
 {
     lock (OneModuleLocker)
     {
         if (_kernel.Value.GetModules().All(t => t.Name != module.GetType().FullName))
         {
             _kernel.Value.Load(new[]
             {
                 module
             });
         }
     }
 }
示例#4
0
        /// <summary>
        /// Generates a message saying that a module with the same name is already loaded.
        /// </summary>
        /// <param name="newModule">The new module.</param>
        /// <param name="existingModule">The existing module.</param>
        /// <returns>The exception message.</returns>
        public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule, INinjectModule existingModule)
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine("Error loading module '{0}' of type {1}", newModule.Name, newModule.GetType().Format());
                sw.WriteLine("Another module (of type {0}) with the same name has already been loaded", existingModule.GetType().Format());

                sw.WriteLine("Suggestions:");
                sw.WriteLine("  1) Ensure that you have not accidentally loaded the same module twice.");
                #if !SILVERLIGHT
                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

                return sw.ToString();
            }
        }
示例#5
0
        /// <summary>
        /// Generates a message saying that a module with the same name is already loaded.
        /// </summary>
        /// <param name="newModule">The new module.</param>
        /// <param name="existingModule">The existing module.</param>
        /// <returns>The exception message.</returns>
        public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule, INinjectModule existingModule)
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine("Error loading module '{0}' of type {1}", newModule.Name, newModule.GetType().Format());
                sw.WriteLine("Another module (of type {0}) with the same name has already been loaded", existingModule.GetType().Format());

                sw.WriteLine("Suggestions:");
                sw.WriteLine("  1) Ensure that you have not accidentally loaded the same module twice.");
#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

                return(sw.ToString());
            }
        }
 private bool NotAlreadyKnownModule(INinjectModule module)
 {
     return this.modules.All(knownModule => knownModule.GetType() != module.GetType());
 }
 private bool NotAlreadyKnownExtension(INinjectModule extension)
 {
     return this.extensions.All(knownExtension => knownExtension.GetType() != extension.GetType());
 }