问题标签 [ninject-extensions]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - Ninject.Extensions.Logging.Log4Net 为类/方法名称生成不正确的输出
我正在使用Ninject 3.0.1.10 进行依赖注入,并希望将Ninject.Extensions.Logging 3.0.1.0 用于log4net 1.2.11 日志记录。但是,当我使用扩展而不是直接使用 log4net 时,我的日志文件中会得到不同的输出。我希望输出包含执行日志记录的类/方法的名称,如下在我的 app.config 中:
我制作了一个示例项目来演示我看到的问题,如下所示:
这会产生以下输出(注意 Ninject 版本中的类/方法名称不正确):
我希望第二行LoggingWithNinject.LogMessage():21
作为源类/方法,但 NinjectLog4NetLogger
被用作源。如何正确识别来源?
c# - 获取 ninject 工厂扩展以允许将工厂参数传递给依赖项
使用 Ninject Factory 扩展,您可以自动生成工厂,并让工厂将参数传递给类的构造函数。以下测试通过:
但是,在我的特定问题中,我希望它将工厂参数传递给我正在构建的类的依赖项,而不是类本身,如下所示:
此测试失败并显示以下消息:
Ninject.ActivationException : Error activation int 没有匹配的绑定可用,并且类型不是自绑定的。激活路径:
3) 将依赖 int 注入 Bar 类型的构造函数的参数 foo
2) 将依赖 IBar 注入 BarContainer 类型的构造函数的参数 bar
1) 请求 IBarContainer
有没有办法让工厂弄清楚我想在解决“Bar”依赖项时使用传递的“foo”参数?
c# - Ninject、WCF 和自动发现
我似乎无法让这三个人一起工作。
我使用 1 种方法将其缩小到一个非常简单的服务:
我有一个看起来像这样的工厂:
如果我像这样创建服务......
...发现工作得很好。但是,如果我像这样使用工厂......
...服务不再被发现。该服务的其他一切都按预期工作。
任何人都喜欢让 Discovery 以这种方式工作,还是我做错了什么?
dependency-injection - Ninject Extensions Factory 中的 NamedLikeFactoryMethod 不符合文档要求
我的简单示例有一个小问题。
我有简单的工厂界面:
我将它绑定为工厂:
当我尝试转换时:
到:
它不编译。
例如,这段代码被编译(但它很糟糕):
我究竟做错了什么?
Ninject 3.0.1.10
Ninject.Extension.Factory 3.0.1.0
编译错误:https ://dl.dropbox.com/u/21806986/Screenshots/shot_19072012_133454.png
c# - Ninject ActivationException:激活 IAlertManagement 时出错
我收到以下错误:
这是导致此异常的测试用例:
上述错误发生在我的构建服务器上的一个单元测试中,但没有发生在我的开发机器上。我有 7 个其他测试几乎与此测试相同,它们在构建服务器和我的开发机器上通过,但这是唯一失败的测试。
IAlertManagement 接口来自一个名为Core的 dll ,具体类型来自另一个名为AlertManagement的 dll 。我的单元测试项目中包含Core dll 和AlertManagement dll 作为项目引用。我有 7 或 8 个与这种情况相同的其他测试,但这是唯一失败的测试。
任何想法都会不胜感激。
dependency-injection - Using Ninject.MockingKernel with Asp.Net Web API
I've set up a Web API project using Ninject, and I've used the fix detailed here for getting it to work with the latest version of the Web API. Everything is working fine, but I'm now trying to write some tests.
I'm using in-memory hosting to run the project for the tests, as detailed here, as I have a DelegatingHandler
that performs authentication and then sets a property on the request message that is used by all the Api Controllers.
So, I've got a base class for my tests, and have a SetUp
method where I set up the HttpServer
and configuration, which I've pretty much taken from my working Ninject code:
This is how I create the MoqMockingKernel
:
And this is how I register the objects to use:
While I'm not testing the Controller per se, I do want a proper instance of it to be called, which is why I'm binding it ToSelf. I must admit that I am assuming that this is correct. This is an example of a test:
I'm basically getting a 404 error. When I debug it, it does go to my DelegatingHandler
, but it doesn't go to my controller.
I get the feeling that I'm fundamentally missing a point here, and it may not even be possible to do what I'm trying to do, but if anyone has any suggestions for either how to do this, or a different way to achieve the same thing, I'm all ears.
Update I think that it's because the default behaviour of the MockingKernel
is to provide a Mock unless told otherwise, so it is returning a Mock of IHttpControllerSelector
. I've set up a couple of default ones now:
It's still not working, I think because there are no formatters specified. I'll try that tomorrow and see if that gets me there.
c# - 用 Ninject 拦截。无法加载 IProxyRequestFactory
我正在学习使用 Ninject 和 Interceptor 模式。
我有以下拦截器。
并且有一个名为的类MyClass
,它除了 2 个简单的方法之外什么都没有,它们是虚拟的,以允许拦截器对其进行处理。(两种方法是 Echo 和 double,正如他们的名字所说的那样。)
我通过 NuGet 将 Ninject、Ninject.Extensions.Interception 和 Ninject.Extensions.Interception.DynamicProxy 添加到我的项目中。
添加了以下using
语句。
我的主要方法,它进行引导看起来像这样。
我在指定的行收到以下错误。
谁能告诉我我做错了什么?
asp.net-mvc-3 - 使用带有工厂扩展的 Ninject 3.0.0 将工厂注入到 ASP.NET MVC 3 中的自定义成员提供程序时遇到问题
我正在创建一个具有自定义成员资格提供程序的 ASP.NET MVC 3 webapp。我Ninject.Extensions.Factory 3.0.0
过去尝试将工厂注入到我的自定义会员提供程序的公共财产中,但进展并不顺利。
这是我的自定义会员类和工厂接口:
这是我的会员初始化模块:
这是来自 NinjectWebCommon.cs 的 RegisterServices 代码:
在 web.config 中,我有以下内容:
当我启动 webapp 时,在模块初始化期间出现异常:
我不确定我做错了什么。我已经关注了 Remo Gloor 的关于ASP.NET Provider 依赖注入与 Ninject 3.0.0的博客文章,以及相关的 StackExchange 讨论,以及关于 NamedLikeFactoryMethod和许多其他帖子的这个问题,但我被卡住了。我错过了什么?
c# - 使用参数的 Ninject 方法级拦截
我在拦截教程中注意到您可以定位一个方法并拦截它。IE
文档/教程不包括在您尝试拦截的方法具有参数的情况下要做什么,即ThrowsAnError是否接受字符串作为参数。
在绑定时,我无法访问参数,所以我想知道我是否以错误的方式进行此操作?
编辑
c# - MoqMockingKernel:System.TypeLoadException:类型违反了继承安全规则
我尝试使用 MoqMockingKernel 类。(Ninject.MockingKernel.Moq) 来自 Ninject.MockingKernel 扩展,用于单元测试。
在初始化 MoqMockingKernel 时,我收到以下错误:
System.TypeLoadException:System.TypeLoadException:类型违反继承安全规则:'Ninject.MockingKernel.MockingKernel'。派生类型必须与基类型的安全可访问性相匹配,或者难以访问。
我的初始化代码:
我该如何解决这个问题TypeLoadException
?