Created
September 15, 2011 15:27
-
-
Save ThorstenHans/1219551 to your computer and use it in GitHub Desktop.
Generic Service Locator
This file contains hidden or 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 class ServiceLocator | |
{ | |
//Some kind of singleton is here... | |
// only the stuff that matters | |
public static void For<T>(params Func<T>[] regs) | |
{ | |
// ... | |
} | |
public static T Use<T>() | |
{ | |
// .. | |
} | |
} | |
// usage | |
ServiceLocator.Instance.For<IFoo>(ServiceLocator.Use<Foo>(),ServiceLocator.Use<Bar>()); | |
// nice but something like | |
ServiceLocator.Instance.For<IFoo>(Use<Foo>(),Use<Bar>()); | |
// seems to be more elegant... | |
// Use<T> is a extension method on object, so its a global method... | |
// working approach is | |
SerivceLocator.Instance.For<IFoo>().Use<Foo>().Use<FooBar>().Use<Bar>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment