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
  • 相关阅读:
    NSScanner 的使用
    判断ios设备型号
    图片渲染成蓝色的问题
    UITextView使用体会
    html标签的语义化之搜索引擎优化
    如何用 Canvas绘制图形
    js的几个案例
    js的几种面向对象
    CSS3的几个基本知识点简介
    关于html和CSS的几个基本知识点
  • 原文地址:https://www.cnblogs.com/wucg/p/1838503.html
Copyright © 2011-2022 走看看