Skip to content

Feather auto-loading NinjectModule's multiple times #2580

@RJCuthbertson

Description

@RJCuthbertson

There's a similar issue posted here:
http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/sitefinity-8-2-to-9-upgrade-error

With a suggested fix of "don't use NinjectModule's - just register the bindings directly to the FeatherModule DependencyResolver" but if you have a NinjectModule with a public parameterless constructor in a library referenced by your SF web application project, the FeatherModule.Initialize method throws an exception:

Error loading module 'YourModuleNamespace.Bindings' of type Bindings Another module (of type Bindings) with the same name has already been loaded Suggestions: 1) Ensure that you have not accidentally loaded the same module twice. 2) If you are using automatic module loading, ensure you have not manually loaded a module that may be found by the module loader.

at:
Ninject.dll!Ninject.KernelBase.Load(System.Collections.Generic.IEnumerable<Ninject.Modules.INinjectModule> m) Line 214 C# Telerik.Sitefinity.Frontend.dll!Telerik.Sitefinity.Frontend.FrontendModule.Initialize(Telerik.Sitefinity.Services.ModuleSettings settings) Unknown Telerik.Sitefinity.dll!Telerik.Sitefinity.Services.SystemManager.InitializeModule(Telerik.Sitefinity.Services.ModuleSettings settings, Telerik.Sitefinity.Services.InstallContext installContext, Telerik.Sitefinity.Metadata.Model.ModuleVersion moduleVersion, bool? start, bool skipModuleRegistration) C# Telerik.Sitefinity.dll!Telerik.Sitefinity.Services.SystemManager.Initialize() Line 1682 C# Telerik.Sitefinity.dll!Telerik.Sitefinity.Abstractions.Bootstrapper.RegisterRoutes() Line 349 C# Telerik.Sitefinity.dll!Telerik.Sitefinity.Abstractions.Bootstrapper.Bootstrap() Line 173 C# Telerik.Sitefinity.dll!Telerik.Sitefinity.Web.SitefinityHttpModule.Init.AnonymousMethod__2(object ctx) Line 276 C# mscorlib.dll!System.Threading.Tasks.Task.Execute() Unknown mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Unknown mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Unknown mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Unknown

I worked around the issue by adding a constructor to my module with an unused parameter:

public class Bindings : NinjectModule
{
    /// <summary>
    /// Initializes a new instance of the <see cref="Bindings"/> class
    /// </summary>
    /// <param name="unused">This is an unused parameter. It needs to exist to prevent Feather from auto-loading this module.</param>
    public Bindings(bool unused)
    {
    }
    ...
}

Please fix this. We have multiple projects in our code base that provide their own Ninject bindings for the types used in those projects.

This is easily reproducible on SF version 9.1.6119.0 and Feather version 1.6.560.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions