<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    Castle研究-第一個Castle程序


    ?

    Castle:About

    From Castle

    Castle was born from the Apache Avalon project as an attempt to build a very simple inversion of control container. The overall design is the result of more than a year in contact with masters of the Avalon land like Carsten Ziegeler, Leo Sutic, Leo Simons and Berin Loritsch to name a few.

    After several discussions about what a useful container must solve, Castle's first draft was created. Several changes have taken place before reaching its current form.

    However, Castle had a more ambitious agenda. Tools like DynamicProxy and the Management Extensions were used by several projects and a proper home to support those users and build a community was necessary. Along the same lines, these tools had nothing in common with Avalon's mission, so we had to find a more suitable home for them.



    Castle:Rationale

    From Castle

    An empty space lies in the open source community between those who happen to use CLI (Common Language Infrastructure) running on Windows (.Net Framework from MS) and|or Linux (Mono). This empty space represents the lack of a model for how to build a Good Application (tm).

    Of course there are several factors that contribute to creating a Good Application, and from our standpoint one them is good architecture. Good architecture is accomplished by having cohesion, single classes with well-defined responsibilities, orthogonallity and loosely coupled components (providing reusability among different projects).

    From our experience, inversion of control can help even an inexperienced team to accomplish good architecture. However, the usage of this design principle is a matter of taste, and people should not feel obligated to use it.

    Castle's goal is to provide a set of standalone tools and an inversion of control container implementation in order to create a meeting point for these tools.



    新建c#工程

    添加對Dll的引用

    Castle.DynamicProxy.dll

    Castle.MicroKernel.dll

    Castle.Model.dll

    Castle.Windsor.dll


    新建 接口
    namespace?first.Castle
    {
    ??
    public???interface?Interface1
    ????
    {
    ????????
    void?add();
    ????????
    void?del();
    ????}

    }

    新建實現(xiàn)類

    namespace?first.Castle
    {
    ????
    public?class?ClassTest:Interface1
    ????
    {
    ????????
    public?void?add()
    ????????
    {
    ???????????System.Diagnostics.Debug.Assert(
    false,"add");
    ????????}


    ????????
    public?void?del()
    ????????
    {
    ???????????System.Diagnostics.Debug.Assert(
    false,"del");
    ????????}

    ????}

    }



    讀取配置

    using?System;
    using?System.Diagnostics;
    using?Castle.MicroKernel;
    using?Castle.Windsor;

    //http://m.tkk7.com/wujun
    namespace?first.Castle
    {
    ????
    public?class?MindDumpContainer
    ????
    {
    ????????
    private?static?MindDumpContainer?_singleMindDupContainer?=?null;
    ????????
    private?static?WindsorContainer?_windsorContainer?=?null;

    ????????
    private?MindDumpContainer()
    ????????
    {
    ????????????_windsorContainer?
    =
    ????????????????
    new?WindsorContainer("配置文件路徑?windsor.config",?AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

    ????????????
    if?(_windsorContainer?==?null)
    ????????????
    {
    ????????????????
    throw?new?Exception("Failed?initialize?WindsorContainer.");
    ????????????}

    ????????}

    //單態(tài)
    ????????public?static?MindDumpContainer?GetInstance()
    ????????
    {
    ????????????
    if?(_singleMindDupContainer?==?null)
    ????????????
    {
    ????????????????_singleMindDupContainer?
    =?new?MindDumpContainer();
    ????????????}

    ????????????
    return?_singleMindDupContainer;
    ????????}


    ????????
    ///?<summary>
    ????????
    ///?Get?contained?object?by?its?name
    ????????
    ///?</summary>
    ????????
    ///?<param?name="key">key?of?the?object?when?registered</param>
    ????????
    ///?<returns>the?object</returns>

    ????????public?object?GetObject(string?key)
    ????????
    {
    ????????????Debug.Assert(_windsorContainer?
    !=?null);

    ????????????
    try
    ????????????
    {
    ????????????????
    return?_windsorContainer[key];
    ????????????}

    ????????????
    catch?(ComponentNotFoundException?ex)
    ????????????
    {
    ????????????????
    throw?new?Exception(string.Format("No?componet?with?the?passed?key:?{0}",?key),?ex);
    ????????????}

    ????????}


    ????????
    public?object?GetObject(Type?type)
    ????????
    {
    ????????????Debug.Assert(_windsorContainer?
    !=?null);
    ????????????
    try
    ????????????
    {
    ????????????????
    return?_windsorContainer[type];
    ????????????}

    ????????????
    catch?(ComponentNotFoundException?ex)
    ????????????
    {
    ????????????????
    throw?new?Exception(
    ????????????????????
    "error");
    ????????????}

    ????????}

    ????}

    }


    配置文件

    <?xml?version="1.0"?encoding="utf-8"??>
    <!--?This?configuration?file?contains?castle?windsor?config?file,?including?facilities?and?components?-->
    <configuration>
    ??
    <configSections>
    ????
    <section?name="log4net"?type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"?/>
    ??
    </configSections>
    //http://m.tkk7.com/wujun
    ??
    <components>
    //service是配置接口?逗號后面是命名空間
    //type?是具體的實現(xiàn)?逗號后面是命名空間
    ????
    <component?id="Classtest"?service="first.Castle.Interface1,first.Castle"?type="first.Castle.ClassTest,first.Castle"?/>
    </components>

    </configuration>

    調(diào)用 只要
    ?Interface1 iface = (Interface1) MindDumpContainer.GetInstance().GetObject(typeof(Interface1));
    ? iface.add();

    就可以了 。。

    和spring 太象了 。。

    ?
    官方網(wǎng)站:
    http://www.castleproject.org/index.php/Main_Page


    http://www.codeproject.com/cs/design/introducingcastle.asp



    posted on 2006-07-24 16:13 record java and net 閱讀(1537) 評論(0)  編輯  收藏 所屬分類: dot net相關(guān)Spring

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 香蕉成人免费看片视频app下载| 久久久久久国产a免费观看不卡| 免费在线视频你懂的| 国产av天堂亚洲国产av天堂| 国产在线观看免费视频软件| 国精无码欧精品亚洲一区| a毛片久久免费观看| 亚洲va国产va天堂va久久| 国产真人无码作爱免费视频| 亚洲精品无码久久久久去q | 伊人久久精品亚洲午夜| 一区二区三区视频免费| 亚洲尤码不卡AV麻豆| 免费久久人人爽人人爽av| 日本亚洲国产一区二区三区| 狠狠躁狠狠爱免费视频无码| 亚洲色WWW成人永久网址| a级毛片免费在线观看| 久久久婷婷五月亚洲97号色| 亚洲无砖砖区免费| 亚洲a级在线观看| 日韩精品免费电影| selaoban在线视频免费精品| 亚洲精品V欧洲精品V日韩精品| 99在线观看免费视频| 亚洲国产视频久久| 亚洲国产av无码精品| 日韩免费高清播放器| 亚洲午夜久久久精品电影院| 日韩成人免费在线| 91视频免费观看| 亚洲AV无码乱码在线观看代蜜桃 | 亚洲精品一二三区| 四虎永久精品免费观看| 大妹子影视剧在线观看全集免费 | 成在线人直播免费视频| 亚洲国产成人精品不卡青青草原| 亚洲一区二区三区免费观看| 亚洲av成人一区二区三区在线播放| 国产精品亚洲mnbav网站| 国产精品免费观看|