Giter Club home page Giter Club logo

nancy.bootstrappers.ninject's People

Contributors

bnm91 avatar cemremengu avatar gatapia avatar grumpydev avatar horsdal avatar jchannon avatar khellang avatar scott-xu avatar sphiecoh avatar stabbylambda avatar thecodejunkie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nancy.bootstrappers.ninject's Issues

Ninject binding issue with IDiagnosticsProvider

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

  1. Request for IDiagnostics

I am using the latest stable nuget packages:

  • Nancy 0.23.2
  • Nancy.Bootstrappers.Ninject 0.23.2
  • Ninject 3.0.1.10
  • Ninject.Extensions.ChildKernel 3.0.0.5

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?

Support of Ninject3

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.

Ninject v3.2.2 dependency resolution issue

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.

Ninject Bootstrapper not working with UseNancy() Owin AppBuilderExtensions

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.NancyBootstrapperBase1.GetEngine()
at Nancy.Owin.NancyMiddleware.UseNancy(NancyOptions options)
at Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, NancyOptions options)
at MyHost.

b__b(IAppBuilder builder) in c:\dev\MyHost\Program.cs:line 194
at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext context)
at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options, Action1 startup) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options, Action1 startup)
at MyHost.Main() in c:\dev\MyHost\Program.cs:line 177
at MyHost.Main(String[] args) in c:\dev\MyHost\Program.cs:line 248
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: Ninject.ActivationException
HResult=-2146233088
Message=Error activating IRouteResolverTrie
No matching bindings are available, and the type is not self-bindable.
Activation path:
4) Injection of dependency IRouteResolverTrie into parameter trie of constructor of type DefaultRouteResolver
3) Injection of dependency IRouteResolver into parameter routeResolver of constructor of type DefaultRequestDispatcher
2) Injection of dependency IRequestDispatcher into parameter dispatcher of constructor of type NancyEngine

  1. Request for INancyEngine

Suggestions:

  1. Ensure that you have defined a binding for IRouteResolverTrie.
  2. If the binding was defined in a module, ensure that the module has been loaded into the kernel.
  3. Ensure you have not accidentally created more than one kernel.
  4. If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
  5. If you are using automatic module loading, ensure the search path and filters are correct.
   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: 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.