How to avoid service locator in .net extension methods
问题 I'm looking for a clean pattern to use dependencies in .Net extension methods without explicitly newing-up or using a service locator: public static class HttpContextExtensions { public static SomeClass ExtensionMethod(this HttpContext context) { //looking to avoid this var dependency = ServiceLocator.GetService<DependencyType>(); return dependency.DoSomething(context); } } Am I barking up the wrong tree here? Should I be looking for a more direct solution that passes context into a method? I