Created
November 2, 2018 16:02
-
-
Save angelo-marano/bb54ac8b570fff99124195d439127b6b to your computer and use it in GitHub Desktop.
Really bad service locator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IServiceLocator { | |
//This is real bad, don't use this | |
//There's so much missing from this | |
void Register<T>(T t); | |
T Resolve<T>(); | |
} | |
public class ServiceLocator : IServiceLocator | |
{ | |
//This is worse than the above interface. Seriously, don't use this | |
private readonly Dictionary<Type, object> _types = new Dictionary<Type, object>(); | |
public void Register<T>(T t) | |
{ | |
_types.Add(typeof(T), t); | |
} | |
public T Resolve<T>() | |
{ | |
var obj = _types[typeof(T)]; | |
return (T)obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment