Skip to content

Instantly share code, notes, and snippets.

@angelo-marano
Created November 2, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelo-marano/bb54ac8b570fff99124195d439127b6b to your computer and use it in GitHub Desktop.
Save angelo-marano/bb54ac8b570fff99124195d439127b6b to your computer and use it in GitHub Desktop.
Really bad service locator
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