My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
9 hours ago: Here's a use-case for datapod format, recording human-readable data that later can be used as a datasource: http://is.gd/eSsLg @pholdings.
9 hours ago: "Subscriptions are available to U.S. addresses only." http://www.highlights.com another global economy #fail.
10 hours ago: "Subscriptions are available to U.S. addresses only." http://www.highlights.com another global #fail.
11 hours ago: My notes on podcast with author Aimee Bender's Lemoncake book, "a normal kid punished by expectations of giftedness": http://is.gd/eSsLg.
12 hours ago: Interesting: "one page per book": http://openlibrary.org/about.
12 hours ago: Another after-work 8K, did 5K in 23:33, getting cooler here as #berlin #marathon approaches: http://is.gd/eSp95.
yesterday: C# CODE EXAMPLE: Extension method for checking regex in one line: http://is.gd/eQzyg.
yesterday: New podcast source: "I don't want to put you to sleep, but I want to be as rich, and rewarding, and resident as a dream.":http://is.gd/eQrdC.
yesterday: An intense colin marshall interview with michael silverblatt on the art of interviewing & more: http://is.gd/eQqve (search for "blatt").
yesterday: The stackexchange site for wordpress is up: get your answers / establish your reputation @cottonr http://wordpress.stackexchange.com.
2 days ago: "I've always felt that any time you can use a tuple, you should use a struct.": http://is.gd/eQm9V.
IOC CODE EXAMPLE created on Friday, March 06, 2009 permalink
Simple example of Inversion of Control and Dependency Injection
I read James Kovac's article on Inversion of Control and Dependency Injection and then used what I learned to make my own IoC/DI example. This implements what he calls "the poor man's dependency injection" but I think it is simple enough to show the concept of inversion quite well in a simple example.
using System;
using System.Linq;
using System.Collections.Generic;

namespace TestSimpleDependencyInjection1
{
    class Program
    {
        static void Main(string[] args)
        {
            AuthorizationService authorizationService = new AuthorizationService();

            //real example
            Repository repository = new Repository(authorizationService);
            for (int id = 1; id <= 3; id++)
            {
                Customer customer = repository.GetCustomer(id);
                customer.Display();
            }
            Console.WriteLine();

            //mock test example
            MockRepository mockRepository = new MockRepository(authorizationService);
            Customer mockCustomerAdministrator = repository.GetCustomer(1);
            Customer mockCustomerSalesperson = repository.GetCustomer(2);
            UnitTester.Assert("Administrators have access", mockCustomerAdministrator.GetAuthorizationMessage(), "Access Granted");
            UnitTester.Assert("Salespeople do not have access", mockCustomerAdministrator.GetAuthorizationMessage(), "Access Granted");

            Console.ReadLine();
        }
    }

    public static class UnitTester
    {
        public static void Assert(string title, string value, string expectedResult)
        {
            Console.WriteLine(value == expectedResult ? String.Format("{0}: test succeeded", title) : String.Format("{0}: TEST FAILED!", title));
        }
    }

    public class Customer
    {

        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public AccessGroup AccessGroup { get; set; }
        public AuthorizationService AuthorizationService { get; set; }

        public string GetAuthorizationMessage()
        {
            return this.AuthorizationService.GetAccessMessage(this);
        }

        public Customer()
        {

        }

        public void Display()
        {
            Console.WriteLine("Customer: {1}, {0} ({2}): {3}", this.FirstName, this.LastName, this.AccessGroup, this.GetAuthorizationMessage());
        }
    }

    public class AuthorizationService
    {
        public string GetAccessMessage(Customer customer)
        {
            return customer.AccessGroup == AccessGroup.Administrator ? "Access Granted" : "Access Denied";
        }
    }


    public class Repository : IRepository
    {
        private List<Customer> _customerSet = new List<Customer>();
        private AuthorizationService _authorizationService;

        public Repository(AuthorizationService authorizationService)
        {
            _authorizationService = authorizationService;
            _customerSet.Add(new Customer {AuthorizationService = _authorizationService, ID = 1, FirstName = "Jim", LastName = "Smith", AccessGroup = AccessGroup.Administrator });
            _customerSet.Add(new Customer {AuthorizationService = _authorizationService, ID = 2, FirstName = "John", LastName = "Johnson", AccessGroup = AccessGroup.Administrator });
            _customerSet.Add(new Customer {AuthorizationService = _authorizationService, ID = 3, FirstName = "Hank", LastName = "Rivers", AccessGroup = AccessGroup.Salesperson });
        }

        public Customer GetCustomer(int id)
        {
            return (from c in _customerSet
                    where c.ID == id
                    select c).SingleOrDefault();
        }
    }

    public class MockRepository : IRepository
    {
        private List<Customer> _customerSet = new List<Customer>();
        private AuthorizationService _authorizationService;

        public MockRepository(AuthorizationService authorizationService)
        {
            _authorizationService = authorizationService;
            _customerSet.Add(new Customer { AuthorizationService = _authorizationService, ID = 1, FirstName = "Test1AdministratorFirstName", LastName = "Test1AdministratorLastName", AccessGroup = AccessGroup.Administrator });
            _customerSet.Add(new Customer { AuthorizationService = _authorizationService, ID = 2, FirstName = "Test2SalespersonFirstName", LastName = "Test2SalesPersonLastName", AccessGroup = AccessGroup.Salesperson });
        }

        public Customer GetCustomer(int id)
        {
            return (from c in _customerSet
                            where c.ID == id
                            select c).SingleOrDefault();
        }

    }

    public interface IRepository
    {
        Customer GetCustomer(int id);
    }

    public enum AccessGroup
    {
        Administrator,
        Salesperson
    }
}
need markup?