# Dependency Injection

Services can be conditionally injected, or conditionally decorate existing services.

### AddTransient / AddScoped

```csharp
services.AddTransientForFeature<ILinkService, GlobalLinkService>("GlobalLink");
```

### Decorate

The decorator pattern injects the existing implementation of a service into the constructor of the decorator service

```csharp
services.AddScoped<ITaxService, LocalTaxService>();
services.DecorateForFeature<ITaxService, AvalaraTaxService>("Avalara");
```

###

{% hint style="info" %}
Transient, scoped and middleware flags take effect immediately and don't require an application restart. They are usually preferred for this reason over singleton implementations, which live for the entire lifetime of the application.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toggly.io/feature-flags/feature-flags-in-c-.net/dependency-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
