Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC2, issue with HttpApplicationInitializationHttpModule Injection #4

Closed
jpknoll opened this issue Mar 8, 2012 · 3 comments
Closed

Comments

@jpknoll
Copy link

jpknoll commented Mar 8, 2012

If my webservice global inherits from NinjectHttpApplication, then the application fails with the following error:

Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency IntPtr into parameter method of constructor of type Func{IKernel}
2) Injection of dependency Func{IKernel} into parameter lazyKernel of constructor of type HttpApplicationInitializationHttpModule

  1. Request for IHttpModule

The following code resolved this error:

public class Global : NinjectHttpApplication
{
    protected override void OnApplicationStarted()
    {
        base.OnApplicationStarted();
    }

    protected override IKernel CreateKernel()
    {
        //define modules loaded by default
        var modules = new INinjectModule[]
        {
            new ServiceModule(),
            new EntityContextModule(),
        };

        IKernel kernel = new StandardKernel(modules);

        //hack for Ninject.Web.Common.HttpApplicationInitializationHttpModule
        kernel.Bind<Func<IKernel>>().ToMethod(c => () => GetKernelInstance());

        return kernel;
    }

    private IKernel GetKernelInstance()
    {
        //this method is deprecated
        return this.Kernel;
    }
}

Is this intended?

@jpknoll
Copy link
Author

jpknoll commented Mar 8, 2012

Nevermind, found the nuget generated file in the app_start. Would it be possible to get an example in the wiki?

@jpknoll jpknoll closed this as completed Mar 8, 2012
@remogloor
Copy link
Member

HttpApplicationInitializationHttpModule is not intended to be used together with NinjectHttpApplication. It's for the AppStart way only.

@jpknoll
Copy link
Author

jpknoll commented Mar 9, 2012

Yeah, I'd completely missed the nuget generated file and didn't realized I was using both. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants