如何申报统一InjectionFactory的XML配置 [英] How to declare the Unity InjectionFactory in XML configuration

查看:193
本文介绍了如何申报统一InjectionFactory的XML配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在感动我们的统一配置到web.config文件的过程。我卡在如何以下code配置迁移到XML格式:

  VAR集装箱=​​新UnityContainer();
container.RegisterType<的IPrincipal>(新InjectionFactory(X => HttpContext.Current.User));
返回容器;
 

下面是XML declartion:

 <统一的xmlns =htt​​p://schemas.microsoft.com/practices/2010/unity>
    <别名别名为IRepositoryTYPE =Model.IRepository,型号/>
    <别名别名为库TYPE =Data.Repository,数据/>
    <集装箱>
      <注册类型=IRepositorymapTo =资源库/>
    < /容器>
< /团结和GT;
 

解决方案

InjectionFactory是一件事,不能重新psented在XML开箱$ P $。为了使它完全正常工作,你必须写一个C#编译器,可以工作在XML文件中,这是方式比我想的时候咬掉。

不过,我确实有到位桶上的一个样本,显示一种方式来获得工厂创建通过XML工作的限定版。可能会给你一些想法。

I'm in the process of moving our Unity configuration to the web.config file. I'm stuck on how to migrate the following code config to the xml format:

var container = new UnityContainer();
container.RegisterType<IPrincipal>(new InjectionFactory(x=> HttpContext.Current.User));
return container;

Here are the XML declartion:

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <alias alias="IRepository" type="Model.IRepository, Model" />        
    <alias alias="Repository" type="Data.Repository, Data" />
    <container>
      <register type="IRepository" mapTo="Repository" />      
    </container>    
</unity>

解决方案

InjectionFactory is the one thing that can't be represented in XML out of the box. In order for it to completely work, you'd have to write a C# parser that could work on the XML file, which was way more than I wanted to bite off at the time.

However, I do have a sample on bitbucket which shows a way to get a limited version of factory creation working via XML. Might give you some ideas.

这篇关于如何申报统一InjectionFactory的XML配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆