Xml配置IRepository <t>。 MSDN错了吗?</t>

时间:2012-09-30 12:05:07

标签: wcf unity-container

我正在尝试为泛型类型存储库接口实现构造函数注入。 我通过应用http://msdn.microsoft.com/en-us/library/ff660933(v=pandp.20).aspx文档来完成此操作。但是,xml编辑器不接受例如的方括号:

    <alias alias="IGenericRepository"
       type="Design.DataModel.Interfaces.IGenericRepository'1    [[Design.DataModel.Entities.GaugeModel, Design.DataModel]], Design.DataModel"/>    

xml-editor出现以下错误:“意外的文本”。 完整的xml部分是:

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<sectionExtension prefix="" type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />

<alias alias="IGenericRepository" type="Design.DataModel.Interfaces.IGenericRepository'1[[Design.DataModel.Entities.GaugeModel, Design.DataModel]], Design.DataModel"/>
<alias alias="GenericSqlRepository" type="Design.DataAccess.GenericSqlRepository'1[[Design.DataModel.Entities.GaugeModel, Design.DataModel]], Design.DataAccess"/>
<alias alias="IGaugeModelbaseService" type="Design.Contracts.IGaugeModelbaseService, Design.Contracts"/>
<alias alias="GaugeModelbaseService" type="Design.ContractImplememtations.GaugeModelbaseService, Design.ContractImplementations"/>
<alias alias="IContractMapper" type="Design.ContractImplementations.IContractMapper, Design.ContractImplementations"/>
<alias alias="ContractMapper" type="Design.ContractImplementations.ContractMapper"/>
 <container>
  <register type="IGaugeModelbaseService" mapTo="GaugeModelbaseService"> 
    <interceptor type="InterfaceInterceptor" />
  </register>
  <register type="IContractMapper" mapTo="ContractMapper"> 
    <lifetime type="hierarchical" />
  </register>
  <register type="IGenericRepository" mapTo="GenericSqlRepository">
    <lifetime type="hierarchical" />
  </register>
</container>  

浏览svc结果会导致错误:“无法解析类型名称或别名GaugeModelbaseService”

xml必须等同于以下流畅的API配置(工作正常):

public class WcfServiceFactory : UnityServiceHostFactory
{
    #region Methods

    protected override void ConfigureContainer(IUnityContainer container)
    {
        //container.LoadConfiguration();
        container.AddNewExtension<EnterpriseLibraryCoreExtension>();
        container.AddNewExtension<Interception>();
        container.RegisterType<IGaugeModelbaseService, GaugeModelbaseService>(
            new InterceptionBehavior<PolicyInjectionBehavior>(), new Interceptor<TransparentProxyInterceptor>());
        container.RegisterType<IContractMapper, ContractMapper>(new HierarchicalLifetimeManager());
        container.RegisterType<IGenericRepository<GaugeModel>, GenericSqlRepository<GaugeModel>>(
            new HierarchicalLifetimeManager());
    }

    #endregion
}

我是否会错过xml-configuration中的内容?请帮忙。

1 个答案:

答案 0 :(得分:0)

这是您的配置文件中的直接复制/粘贴吗?如果是这样,问题就是错字:

<alias alias="GaugeModelbaseService" type="Design.ContractImplememtations.GaugeModelbaseService, Design.ContractImplementations"/>

注意:'Implememtations'

否则您的语法看起来不正确。