nancyfx / nancy.bootstrappers.ninject Goto Github PK
View Code? Open in Web Editor NEWNancy boostrapper for the Ninject container
License: MIT License
Nancy boostrapper for the Ninject container
License: MIT License
Hi,
it all worked when I used the Nancy internal IoC. With this lib I now get this exception:
A first chance exception of type 'Ninject.ActivationException' occurred in Ninject.dll
Additional information: Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
4) Injection of dependency IntPtr into parameter method of constructor of type Func{IRouteCache}
3) Injection of dependency Func{IRouteCache} into parameter routeCacheFactory of constructor of type DefaultRouteCacheProvider
2) Injection of dependency IDiagnosticsProvider into parameter diagnosticProviders of constructor of type DefaultDiagnostics
- Request for IDiagnostics
I am using the latest stable nuget packages:
I have a workaround. Injecting this bind in the bootstrapper:
protected override void ConfigureApplicationContainer(IKernel existingContainer)
{
base.ConfigureApplicationContainer(existingContainer);
existingContainer.Rebind<Func<IRouteCache>>().ToMethod(ctx =>
() => ctx.Kernel.Get<IRouteCache>());
// A Bind might be enough.
}
The problem might be that Ninject cannot inject into constructor parameters of type Func<Interface>
as is the case in DefaultRouteCacheProvider
.
Am I doing anything wrong or am I just the first to notice this?
I can see that support for Ninject3 has been provided with-in this commit.
I've installed Nancy.Bootstrappers.Ninject via Nuget and application started to throw an exception, related missing Bind method. It really smells like NuGet version still depended on Ninject 2.
PS. Latest NuGet package is dated Monday, May 07, 2012 - but Ninject 3 support provided in June, so looks like NuGet package is not up-to-date. As workaround I'll try to build it from sources.
Hi
The latest release of Ninject (v3.2.2) does not work out of the box with Bootstrappers.Ninject - the dependency resolution is picking up the wrong version of Ninject's Child Kernel library - see below for package manager output:
PM> Get-Package Ninject
Id Version Description/Release Notes
-- ------- -------------------------
Ninject 3.2.2.0 Stop writing monolithic applications that make you feel like you have to move mountains to make the simplest of changes. Ninj...
PM> Install-Package Nancy.Bootstrappers.Ninject -ProjectName xxxxxx -Version 0.23.2
Attempting to resolve dependency 'Nancy (≥ 0.23.2)'.
Attempting to resolve dependency 'Ninject (≥ 3.0.0)'.
Attempting to resolve dependency 'Ninject.Extensions.ChildKernel (≥ 3.0)'.
Attempting to resolve dependency 'Ninject (≥ 3.0.0.0 && < 3.1.0.0)'.
Install-Package : Already referencing a newer version of 'Ninject'.
At line:1 char:1
+ Install-Package Nancy.Bootstrappers.Ninject -ProjectName xxxxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
PM>
Manually installing Ninject.Extensions.ChildKernel v3.2.0.0 first, and then installing the bootstrapper works. I assume this is because You're trying to target multiple versions of Ninject with a single package but I think Ninject's versioning may prohibit this. The only way I could therefore see this working would be to mirror the Ninject version's the same was as the ChildKernel library is doing, or eliminate support for older versions...
Either way, I thought I would raise it.
Thanks.
I am trying to use Nancy in a console hosted Owin app.
My Bootstrapper and the main startup of Nancy are defined as follows:
//NOTE: kernel is a static variable and is the ninject StandardKernel
public class Bootstrapper : NinjectNancyBootstrapper
{
protected override IKernel GetApplicationContainer()
{
kernel.Load<FactoryModule>();
return kernel;
}
protected override void ConfigureConventions(NancyConventions nancyConventions)
{
base.ConfigureConventions(nancyConventions);
nancyConventions.StaticContentsConventions.Add(
StaticContentConventionBuilder.AddDirectory("scripts", @"scripts", "js")
);
nancyConventions.StaticContentsConventions.Add(
StaticContentConventionBuilder.AddDirectory("css", @"css", "css")
);
}
protected override void ApplicationStartup(IKernel container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
}
protected override IKernel CreateRequestContainer(Nancy.NancyContext context)
{
return kernel;
}
}
class Program
{
public static void Main(string[] args)
{
var options = new StartOptions();
options.Urls.Add(this.config.HostUrl.AbsoluteUri);
using(WebApp.Start(options,
builder =>
{
builder.Properties["host.AppName"] = "Self host";
builder.Properties["host.AppMode"] = "development";
builder.MapSignalR("/signalr",
new HubConfiguration
{
EnableJSONP = true,
EnableJavaScriptProxies = true,
Resolver = new DefaultDependencyResolver()
});
builder.UseErrorPage();
builder.UseNancy();
})
{ Console.ReadLine();}
}
}
The call to UseNancy() throws the following error. Ninject is not able to resolve IRouteResolverTrie.
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Something went wrong when trying to satisfy one of the dependencies during composition, make sure that you've registered all new dependencies in the container and inspect the innerexception for more details.
Source=Nancy
StackTrace:
at Nancy.Bootstrapper.NancyBootstrapperBase1.SafeGetNancyEngineInstance() at Nancy.Bootstrapper.NancyBootstrapperBase
1.GetEngine()
at Nancy.Owin.NancyMiddleware.UseNancy(NancyOptions options)
at Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, NancyOptions options)
at MyHost.
1 startup) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options, Action
1 startup)Suggestions:
Source=Ninject
StackTrace:
at Ninject.KernelBase.Resolve(IRequest request)
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent)
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target)
at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
at Ninject.Activation.Context.ResolveInternal(Object scope)
at Ninject.Activation.Context.Resolve()
at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent)
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target)
at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
at Ninject.Activation.Context.ResolveInternal(Object scope)
at Ninject.Activation.Context.Resolve()
at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent)
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target)
at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
at Ninject.Activation.Context.ResolveInternal(Object scope)
at Ninject.Activation.Context.Resolve()
at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
at Nancy.Bootstrappers.Ninject.NinjectNancyBootstrapper.GetEngineInternal()
at Nancy.Bootstrapper.NancyBootstrapperBase`1.SafeGetNancyEngineInstance()
InnerException:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.