Pregunta

I've been banging my head at this for about 8 hours now, and I just can't seem to find a simple explanation on how to change my custom bootstrapper for ninject (Last worked on the code back in v2.x.x.x) to the new v3.0.0.0 syntax.

I currently have the following:

public class NinjectCustomBootStrapper : NinjectNancyBootstrapper
{
  protected override Ninject.IKernel GetApplicationContainer()
  {
    return Program.MyContainer;
  }

}

in a septate class, and :

public static IKernel MyContainer
{
  get { return _myContainer ?? (_myContainer = CreateKernel()); }
  set { _myContainer = value; }
}

private static IKernel CreateKernel()
{
  var kernel = new StandardKernel();
  kernel.Bind<CardMonitorService>().ToSelf().InSingletonScope();
  return kernel;
}

in my main program 'Program.c' in a command line app.

Iv'e since updated ninject to V3.0.0.0 only to find that there's been some breaking changes. I'll admit I don't use ninject very often (I usually use structuremap), and the only reason this project does is I didn't write it originally.

Since I've upgraded Ninject, now when the app is started up I get the following exception:

Method not found: 'Ninject.Syntax.IBindingWhenInNamedWithOrOnSyntax`1<!0>
Ninject.Syntax.IBindingToSyntax`1.ToConstant(!0)'.

After a ton of searching and researching, the closest I've been able to find is this:

http://sharpfellows.com/post/Ninject-Auto-registration-is-changing-in-version-3.aspx

Which while it points me in the right direction, still isn't quite a solution as I'm not using a custom binding generator.

So my question is this.

How do I rewrite the above so that my project once again works and the WCF service when called gets the correct singleton binding handed to it when a request comes in. Going back to ninject 2 is not an option, as other dependencies in the project that have been added have forced the v3 upgrade and these add new functionality that's been requested hence why I'm working on it.

For reference this is a .NET4 build, running on NancyFX with a self hosting WCF setup as a windows service using Topshelf to provide the SCM interface.

Cheers

Shawty

Addendum to clear things up a little

This is an existing project that was originally written sometime back, I've been asked to add some new features to the project.

As part of adding these new features I have been required to upgrade the version of Ninject being used from an earlier version to V3.0.0.0 as newer dependencies added to the project require the newer version of Ninject.

Under the previous V2 of Ninject the code I have given above worked fine, with no issues, since the project has had Ninject V3 added I now get the exception as described above.

I cannot go back to the earlier version of Ninject as that will mean not being able to add the new functionality that I'm adding.

From the research I've done so far the sharpfellows link above is the closest explanation of my issue that I've managed to find so far on the internet.

I don't use Ninject very often, so I've not got the background to know what's changed between V2 & V3 that (based on my research) is the cause of my issue.

I need to know how to change my code written under V2 (and shown above) so that it works under V3.

¿Fue útil?

Solución 2

So after a week or so it turns out that the problem was that the Nancy dev team broke binary comparability with the latest version of ninject (or vice versa) :-)

There is a GitHub pull request to fix this available at :

https://github.com/NancyFx/Nancy.Bootstrappers.Ninject/pull/6

However the next version 'Nancy.Bootstrapper.Ninject' 0.12 will be out on NuGet soon which will have the fix implemented.

Otros consejos

MissingMethodException is usually a deployment problem. You compile against a different assembly than you deploy. Check that you deployed the same version and same build.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top