0

我正在尝试为通用类型存储库接口实现构造函数注入。我通过应用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 编辑器给出以下错误:“意外的文本”。完整的 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 必须等同于以下 fluent 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 配置中的某些内容吗?请帮忙。

4

1 回答 1

0

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

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

注意:“实现”

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

于 2012-09-30T17:50:08.837 回答