gpt4 book ai didi

c# - 在 Ninject 中使用 ToFactory 时出现 ActivationException

转载 作者:太空狗 更新时间:2023-10-29 23:16:54 29 4
gpt4 key购买 nike

当我尝试在 Ninject 中使用 ToFactory 时,我得到 Ninject.ActivationException

var test = new StandardKernel();
test.Bind<IFoo>().To<Foo>();
test.Bind<IFooFactory>().ToFactory();
var factory = test.Get<IFooFactory>();
var foo = factory.GetFoo(); //<--Ninject.ActivationException

工厂:

public interface IFooFactory
{
IFoo GetFoo();
}

异常:

Ninject.ActivationException was unhandled
Message=Error activating IFoo
No matching bindings are available, and the type is not self-bindable.
Activation path:
1) Request for IFoo

Suggestions:
1) Ensure that you have defined a binding for IFoo.
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) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 359
at Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:line 263
at Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, String name, IParameter[] parameters) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:line 164
at Ninject.Extensions.Factory.Factory.InstanceResolver.Get(Type type, String name, Func`2 constraint, ConstructorArgument[] constructorArguments, Boolean fallback) in c:\Projects\Ninject\ninject.extensions.factory\src\Ninject.Extensions.Factory\Factory\InstanceResolver.cs:line 75
at Ninject.Extensions.Factory.StandardInstanceProvider.GetInstance(IInstanceResolver instanceResolver, MethodInfo methodInfo, Object[] arguments) in c:\Projects\Ninject\ninject.extensions.factory\src\Ninject.Extensions.Factory\Factory\StandardInstanceProvider.cs:line 78
at Ninject.Extensions.Factory.FactoryInterceptor.Intercept(IInvocation invocation) in c:\Projects\Ninject\ninject.extensions.factory\src\Ninject.Extensions.Factory\Factory\FactoryInterceptor.cs:line 57
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IFooFactoryProxy.GetFoo()

最佳答案

关于c# - 在 Ninject 中使用 ToFactory 时出现 ActivationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10479384/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com