首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nancy TinyIoc不使用已注册的实例

Nancy TinyIoc不使用已注册的实例
EN

Stack Overflow用户
提问于 2017-02-22 06:00:52
回答 1查看 830关注 0票数 1

我注册我的实例ConfigureApplicationContainer:

代码语言:javascript
复制
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";
        };
    }

}

当南希尝试创建ParametersModule时发生崩溃。它看起来像是在尝试创建一个ParameterGetSetEngine实例。为什么不使用我注册的实例??

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2017-02-22 06:33:32

ok从这里得到了答案:Registering dependencies within TinyIOC for use in NancyFX

任何注册都应在以下时间之后进行:

代码语言:javascript
复制
base.ConfigureApplicationContainer(container);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42378817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档