profile for Macon_Cao at Stack Overflow, Q&A for professional and enthusiast programmers

Unity Dependency Parser

Unity是一个非常有名的IOC框架,这里我就不用多说。使用Unity,其中的一项重要工作是在config文件中配置接口和实现类的映射。如下配置

<unity>

    <containers>

      <container name="container1">

        <types>

          <type type="MyNamespace.Interfaces.IMyInterface" mapTo="YourNamespace.Imps.YourImplementation" >

         </types>

      </container>

    </containers>

  </unity>

使用映射的代码

var container = new UnityContainer();

var unityConfig = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

unityConfig.Containers[“container1”].Configure(container);

其中的<type type="MyNamespace.Interfaces.IMyInterface" mapTo="YourNamespace.Imps.YourImplementation" >实在是难写。特别是在一个大型项目中,可能会存在多个映射,如果仅仅通过手工维护,这的确是一个挑战。

为了解决这个问题,我编写了Unit Dependency Parser,专们帮助生成接口的映射信息。这是第一个版本,有些简陋。

image 

使用方法:

复制Assebmly所在的文件夹路径到Assembly Path,然后点击Parse按钮。

在Implement classes表格中,会列出接口的实现类

在Dependency Interfaces表格中,会列出通过[Dependency]属性访问的接口

选中实现类和对应的接口,点击Add按钮,将数据添加到Dependency Relation中

点击Generate按钮,用于生成unity的接口映射配置

 

现在的功能实在是简陋,不过已经可以满足基本的需求。我会对其进行不断的调整,以使其在软件开发领域发挥多一点的作用。

欢迎大家的意见与板砖。

我已将源代码和执行程序上传到codeplex.com,大家可以访问http://udp.codeplex.com/下载

posted on 2010-09-15 22:15  无所畏惧,有所期待  阅读(1174)  评论(6编辑  收藏  举报