2012-09-30 17 views
0

我想实现一个通用类型库接口的构造函数注入。 我通过应用http://msdn.microsoft.com/en-us/library/ff660933(v=pandp.20).aspx文档来完成此操作。在XML编辑器但是不接受,例如方括号:Xml配置IRepository <T>。 MSDN是否错误?

<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必须等同到以下流利的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配置中的东西吗?请帮忙。

+0

[另一个问题]的副本(http://stackoverflow.com/questions/3486837/unity-2-0-registering-generic-types-via-xml)。 –

+0

部分是的。但这个问题没有给我答复。为什么xml编辑器不接受方括号?为什么它不起作用?我想念什么? –

+0

仔细阅读Chris Tavares的回答。他首先为开放泛型类型创建一个别名,并使用该别名为封闭泛型类型定义别名。并忽略xml编辑器的警告。这是一个错误的否定。 –

回答

0

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

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

注: 'Implememtations'

你的语法是正确的,否则。