我正在尝试为通用类型存储库接口实现构造函数注入。我通过应用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 配置中的某些内容吗?请帮忙。