我在感动我们的统一配置到web.config文件的过程。我卡在如何以下code配置迁移到XML格式:
VAR集装箱=新UnityContainer();
container.RegisterType<的IPrincipal>(新InjectionFactory(X => HttpContext.Current.User));
返回容器;
下面是XML declartion:
<统一的xmlns =http://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.