1

I register my instance ConfigureApplicationContainer:

public class Bootstrapper : DefaultNancyBootstrapper
{
    // The bootstrapper enables you to reconfigure the composition of the framework,
    // by overriding the various methods and properties.
    // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper
    IParameterGetSetEngine _parameterGetSetEngine;

    public Bootstrapper(IParameterGetSetEngine parameterGetSetEngine)
    {
        _parameterGetSetEngine = parameterGetSetEngine;
    }

    protected override void ConfigureApplicationContainer(TinyIoCContainer container)
    {
        container.Register<IParameterGetSetEngine>(_parameterGetSetEngine);
        base.ConfigureApplicationContainer(container);
    }

}


public class ParametersModule : NancyModule
{
    IParameterGetSetEngine _parameterGetSetEngine;
    public ParametersModule(IParameterGetSetEngine parameterGetSetEngine)
    {
        _parameterGetSetEngine = parameterGetSetEngine;

        Get["/"] = parameters =>
        {
            return "Test";
        };
    }

}

There is a crash when Nancy attempts to create the ParametersModule. It looks like its trying to create an instance of ParameterGetSetEngine. Why doesn't it use the instance that I registered??

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. ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Nancy.NancyEngine ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.DefaultRequestDispatcher ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.DefaultRouteResolver ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.RouteCache ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: WindToolsWebService.Modules.ParametersModule ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Portable.Controller.Parameters.ParameterGetSetEngine ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: Portable.ConnectionManager.DeviceConnectionManager ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: j1939PubSubClient.j1939Client ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: System.String ---> Nancy.TinyIoc.TinyIoCResolutionException: Unable to resolve type: System.Char[] ---> System.ArgumentNullException: Value cannot be null.
pogorman
  • 1,641
  • 2
  • 22
  • 41

1 Answers1

1

ok got the answer from here: Registering dependencies within TinyIOC for use in NancyFX

Any registrations should happen after :

base.ConfigureApplicationContainer(container);
Community
  • 1
  • 1
pogorman
  • 1,641
  • 2
  • 22
  • 41