An Ordinary First Post

Using an IoC container enables me to change the greeter’s language by changing one line of code.

namespace xofz.BlogCode.Sup
{
    using System;
    using Ninject;
    using Ninject.Modules;

    static class EntryPoint
    {
        static void Main()
        {
            var module = new GreeterModule();

            using (var kernel = new StandardKernel(module))
            {
                var greeter = kernel.Get<IGreeter>();

                greeter.SayHello();
            }
        }
    }

    class GreeterModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IGreeter>().To<EnglishGreeter>(); // this is the line of code I would change
        }
    }

    interface IGreeter
    {
        void SayHello();
    }

    class FrenchGreeter : IGreeter
    {
        public void SayHello()
        {
            Console.WriteLine("Bonjour!");
        }
    }

    class SpanishGreeter : IGreeter
    {
        public void SayHello()
        {
            Console.WriteLine("Hola.");
        }
    }

    class EnglishGreeter : IGreeter
    {
        public void SayHello()
        {
            Console.WriteLine("WAZZAAAAAAAAAAAAAAAAA");
        }
    }
}

However, every single post in this blog will be in English, so you may prefer the simpler:

namespace xofz.BlogCode.Sup
{
    using System;

    static class EntryPoint
    {
        static void Main()
        {
            Console.WriteLine("Good day.");
        }
    }
}

Nevertheless, expect future posts to include lots of code utilizing IoC containers.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: