I would recommend that you do not worry about writing your very own service locator (you certainly can experiment building one!) if you are going to use it for production code. Instead, try using Windsor container or Unity framework to handle service location.