Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
Autofac-通过xml配置将实例传递给构造函数参数_Xml_Dependency Injection_Ioc Container_Autofac - Fatal编程技术网

Autofac-通过xml配置将实例传递给构造函数参数

Autofac-通过xml配置将实例传递给构造函数参数,xml,dependency-injection,ioc-container,autofac,Xml,Dependency Injection,Ioc Container,Autofac,我有一个将MemoryCache作为构造函数参数的实现 我的xml配置: <autofac defaultAssembly="Test.Caching"> <component name="memoryCache" type="System.Runtime.Caching.MemoryCache, System.Runtime.Caching"> <parameters> <paramete

我有一个将MemoryCache作为构造函数参数的实现

我的xml配置:

 <autofac defaultAssembly="Test.Caching">
    <component name="memoryCache"
        type="System.Runtime.Caching.MemoryCache, System.Runtime.Caching">
        <parameters>
           <parameter name="name" value="TestCache"/>
        </parameters>
    </component>

    <component type="My.Caching.TaskCache, Test.Caching" service="Test.Caching.ITaskCache" >
        <parameters>
          <parameter name="cache" value="testCache" />
        </parameters>
    </component>
 </autofac>

我在项目中引用了-System.Runtime.Caching。

我认为您需要一个接口来进行声明:

<component name="memoryCache"
type="System.Runtime.Caching.MemoryCache, System.Runtime.Caching"
service="your.interface.IMemoryCache, your.interface"

System.Configuration.ConfigurationErrorsException: The type 'System.Runtime.Caching.MemoryCache, System.Runtime.Caching' could not be found. It may re
quire assembly qualification, e.g. "MyType, MyAssembly".
   at Autofac.Configuration.ConfigurationRegistrar.LoadType(String typeName, Assembly defaultAssembly)
   at Autofac.Configuration.ConfigurationRegistrar.RegisterConfiguredComponents(ContainerBuilder builder, SectionHandler configurationSection)
   at Autofac.Configuration.ConfigurationRegistrar.RegisterConfigurationSection(ContainerBuilder builder, SectionHandler configurationSection)
   at Autofac.Configuration.Core.ConfigurationModule.Load(ContainerBuilder builder)
   at Autofac.Module.Configure(IComponentRegistry componentRegistry)
   at Autofac.ContainerBuilder.Build(IComponentRegistry componentRegistry, Boolean excludeDefaultModules)
   at Autofac.ContainerBuilder.Build(ContainerBuildOptions options)
<component name="memoryCache"
type="System.Runtime.Caching.MemoryCache, System.Runtime.Caching"
service="your.interface.IMemoryCache, your.interface"