在web.config中配置的UnityContainer [英] UnityContainer configured in web.config
本文介绍了在web.config中配置的UnityContainer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
var container = new UnityContainer(); //第1行
容器。RegisterType< ILogUtility,LogUtil>(); //第2行
var logger = container.Resolve< Logger>(); //第3行
logger.Log(LogType.Warn,从容器中记录); //第4行
如何在web.config中实现第2行,这样我只需要我的代码后面的代码行1、3和4?我已经在每个地方搜索了代码示例,但不清楚。
谢谢
解决方案
看看我的教程
http ://netpl.blogspot.com/2011/11/unity-application-block-is-lightweight.html
有一个示例XML配置:
<?xml version = 1.0 encoding = utf-8吗?
< unity xmlns = http://schemas.microsoft.com/practices/2010/unity>
<容器>
< register type = ConsoleApplication30.Logic.ICustomService,ConsoleApplication30
mapTo = ConsoleApplication30.Logic.CustomServiceImpl,ConsoleApplication30 />
< / container>< / unity>
,然后用
<$ p $加载它p>
IUnityContainer容器= new UnityContainer();
container.LoadConfiguration();
I have the following code
var container = new UnityContainer(); //LINE 1
container.RegisterType<ILogUtility,LogUtil>(); //LINE 2
var logger = container.Resolve<Logger>(); //LINE 3
logger.Log(LogType.Warn, "logging from container"); //LINE 4
How do I implement line 2 in web.config such that I will only have to code line 1, 3, and 4 in my code behind? I have searched every where for code example but they are not clear.
Thanks
解决方案
Take a look at my tutorial
http://netpl.blogspot.com/2011/11/unity-application-block-is-lightweight.html
There's an example XML configuration:
<?xml version="1.0" encoding="utf-8" ?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="ConsoleApplication30.Logic.ICustomService, ConsoleApplication30"
mapTo="ConsoleApplication30.Logic.CustomServiceImpl, ConsoleApplication30" />
</container></unity>
and you load it with
IUnityContainer container = new UnityContainer();
container.LoadConfiguration();
这篇关于在web.config中配置的UnityContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文