Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dependency injection ServiceStack国际奥委会。AutoWire(此)尝试注入未在容器中注册的公共属性_Dependency Injection_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack_Inversion Of Control - Fatal编程技术网 servicestack,inversion-of-control,Dependency Injection,servicestack,Inversion Of Control" /> servicestack,inversion-of-control,Dependency Injection,servicestack,Inversion Of Control" />

Dependency injection ServiceStack国际奥委会。AutoWire(此)尝试注入未在容器中注册的公共属性

Dependency injection ServiceStack国际奥委会。AutoWire(此)尝试注入未在容器中注册的公共属性,dependency-injection,servicestack,inversion-of-control,Dependency Injection,servicestack,Inversion Of Control,在使用ServiceStack及其IoC/DI框架时,我遇到以下问题: DI框架将null注入到属性中,并且该属性类型未在容器中注册 class DependencyInjectedA : IDependencyInjectedA { public DependencyInjectedB { get; set; } } class DependencyInjectedB { public Dictionary<DateTime, SomeClass> MyProp

在使用ServiceStack及其IoC/DI框架时,我遇到以下问题:

DI框架将null注入到属性中,并且该属性类型未在容器中注册

class DependencyInjectedA : IDependencyInjectedA
{
    public DependencyInjectedB { get; set; }
}

class DependencyInjectedB 
{
    public Dictionary<DateTime, SomeClass> MyProperty { get; set; }
}
AutoWire调用背后的原因是,我可以让DI框架注入
this
的后代。我的印象是,只有在容器中注册的类型才会被注入依赖项,而且它将是
this
的后代,但是
DependencyInjectedB
中的
MyProperty
似乎也被注入,然后使用
null
值,因为我们没有向容器中添加
字典

class DependencyInjectedA : IDependencyInjectedA
{
    public DependencyInjectedB { get; set; }
}

class DependencyInjectedB 
{
    public Dictionary<DateTime, SomeClass> MyProperty { get; set; }
}
下面是一幅(经过编辑的)画面:DI注入NULL,而我认为它不应该这样做

Mythz实际上:

Autowire注册您可以注册依赖项,以便所有 依赖项自动连接。就像上面的钩子一样, 一旦解决,Funq将创建一个新实例来解决依赖关系 对于具有最多参数和所有公共参数的构造函数 财产

问题:

  • 我怎样才能拥有我不想被注入的公共属性
  • 是否有办法只注入容器(.AddXXX)中注册的类型
这是同时进行公共属性和构造函数注入的行为

特别是Funq的自动布线行为将注入以下任何属性:

  • 公开
  • 可写的(即具有公共设置器)
  • 不是值类型字符串
  • 它的完整类型名未在
    容器中注册。IgnorePropertyTypeFullNames
    集合
因此,如果您不希望注入属性,那么它们无法满足上述所有标准。如果只是一种要防止注入的属性类型,则可以在中注册完整类型名称:

Container.IgnorePropertyTypeFullNames.Add(typeof(DependencyInjectedB).FullName);
或者,将其更改为不公开,否则不应使用包含此行为,而是使用自定义工厂函数注册依赖项,例如:

container.AddSingleton<IDependencyInjectedA>(c => new DependencyInjectedA());
container.AddSingleton(c=>newDependencyInjecteda());
container.AddSingleton<IDependencyInjectedA>(c => new DependencyInjectedA());