zoukankan      html  css  js  c++  java
  • Castle入门示例记录01

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Castle.Windsor;
    using Castle.Windsor.Configuration.Interpreters;
    using Castle.MicroKernel.Registration;

    namespace TestCastleWinApp1
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    //建立容器
                
    //IWindsorContainer container = new WindsorContainer( new XmlInterpreter("http://www.cnblogs.com/BasicUsage.xml") );
                IWindsorContainer container = new WindsorContainer(new XmlInterpreter("CastleConfig.xml"));

                
    //加入组件
                
    //container.AddComponent("txtLog", typeof(ILog), typeof(TextFileLog));
                
    //container.AddComponent("sdfsdfsfsdf", typeof(ILogFormatter), typeof(TextFormatter));

                
    //警告    1    “Castle.Windsor.IWindsorContainer.AddComponent(string, System.Type, System.Type)”已过时:
                
    //“Use Register(Component.For(serviceType).ImplementedBy(classType).Named(key)) instead.”    
                
    //D:\wucg\test\TestProjects\TestCastleWinApp1\TestCastleWinApp1\Program.cs    18    13    TestCastleWinApp1
                
                container.Register(Component.For(
    typeof(ILog)).ImplementedBy(typeof(TextFileLog)).Named("txtLog"));
                container.Register(Component.For(
    typeof(ILogFormatter)).ImplementedBy(typeof(TextFormatter)).Named("sdfsdf"));
                
                
    //获取组件
                
    //instantiate and configure root component and all its dependencies
                
    //ILog log = (ILog)container["txtLog"];     //已过时
                ILog log = (ILog)container.Resolve("txtLog"typeof(TextFileLog));
                
    //使用组件
                log.Write("这是我的输出内容");
                var log2 
    = container.Resolve<ILog>();      //("txtLog", typeof(TextFileLog));
                log2.Write("这是我的输出内容222222222");
                
                Console.WriteLine(
    object.ReferenceEquals(log, log2));   //同一个对象True

                container.Dispose();        
    // clean up
                Console.ReadLine();

            }
        }
    }
    项目文件: /Files/wucg/_TestProjects/TestCastleWinApp1.zip
  • 相关阅读:
    C语言中 指针和数组
    C语言中 指针与结构体
    void指针、NULL指针和未初始化指针
    C语言中 指针、引用和取值

    别--------
    快速开发 jQuery 插件的 10 大技巧(转)
    采用预取(Prefetch)来加速你的网站(转)
    HttpWatch工具简介及使用技巧(转)
    iScroll框架的使用和修改
  • 原文地址:https://www.cnblogs.com/wucg/p/1838503.html
Copyright © 2011-2022 走看看