Domanda

This code gives no error or warning during execution. but it ignores the console.read() function, i am newer with windsor. is it really a bug or the simple behavior of 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();          
    }
}

}

È stato utile?

Soluzione

I think you probably want to use Console.ReadLine rather than Console.Read.

Try this snippet of code to understand Read/ReadLine behavior:

var a = Console.Read();
Console.WriteLine(a);
var b = Console.ReadLine();            
Console.WriteLine(b);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top