---
title: "Discussion on \"Why Avoid Service Locators in Dependency Injection?\" | Hashnode"
description: "Discussion on \"Why Avoid Service Locators in Dependency Injection?\". Why Avoid Service Locators?\nService Locator is an anti-pattern where you inject IServiceProvider and manually resolve dependencies:\n// ❌ Bad - Service Locator pattern\npublic class OrderService\n{\n    p"
url: "https://hashnode.com/posts/why-avoid-service-locators-in-dependency-injection/6a3e6462b43003b9cd089f46"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why Avoid Service Locators in Dependency Injection?](https://nova-globen.hashnode.dev/why-avoid-service-locators-in-dependency-injection?utm_source=hashnode&utm_medium=feed)

Why Avoid Service Locators? Service Locator is an anti-pattern where you inject IServiceProvider and manually resolve dependencies: // ❌ Bad - Service Locator pattern public class OrderService { p

Jun 26 · 2 min read · nova-globen.hashnode.dev  
Read the article

-   [#dependency](https://hashnode.com/tag/dependency)
-   [#injection](https://hashnode.com/tag/injection)
-   [#service](https://hashnode.com/tag/service)
-   [#locators](https://hashnode.com/tag/locators)

## Written by

[Hossein Esmati](https://hashnode.com/@desmati)

@desmati · Stockholm, Sweden

  
[View profile](https://hashnode.com/@desmati)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
