Resolve()后Console.WriteLine无效

时间:2013-02-03 05:25:12

标签: c# containers castle-windsor console.writeline

此代码在执行期间不会出现错误或警告。但它忽略了console.read()函数,我对windsor更新。它真的是一个bug还是windsor的简单行为?

using System;
using Castle.Windsor;
using Castle.MicroKernel.Registration;

namespace CastleProject
{
class Program
{
    internal interface ILogger
    {
        void log(string message);
        void showMethod();
    }
    internal interface Ishowing
    {
        void checkInterface();
    }

    class Logger : ILogger
    {
        public void log(string message)
        {
            Console.WriteLine(message);
            Console.Read();
        }
        public void showMethod()
        {
            Console.WriteLine("This is again showing just function i existing");
        }

    }
    class Showing : Ishowing
    {
        public void checkInterface()
        {
            Console.WriteLine("this is line from checkInterface()");
            var a = Console.ReadLine();
            Console.WriteLine(a);
        }
    }

    static void Main(string[] args)
    {
        var container = new WindsorContainer();
        container.Register(Component.For<ILogger>().ImplementedBy<Logger>(),Component.For<Ishowing>().ImplementedBy<Showing>());
        var logger = container.Resolve<ILogger>();
        var logger2 = container.Resolve<Ishowing>();
        logger.log("hello message");
        logger.showMethod();
        logger2.checkInterface();          
    }
}

}

1 个答案:

答案 0 :(得分:1)

我认为您可能希望使用Console.ReadLine而不是Console.Read

尝试使用此代码段来了解Read / ReadLine行为:

var a = Console.Read();
Console.WriteLine(a);
var b = Console.ReadLine();            
Console.WriteLine(b);