# LS2016: Handler Takes a Pipeline-Owned Collaborator

## Intent

LS2016 is a compiler check that reports a command or query handler, the type that runs a use case, taking a collaborator the pipeline owns, such as the unit of work or the outbox, which no handler should touch directly. This page states what the rule reports, where the error sits, and how to leave the collaborator to its owner.

## Reference

### What the Rule Enforces

LS2016 enforces [Keep uniqueness out of handlers](https://litespec.dev/4.0.0/backend/persistence.md#keep-uniqueness-out-of-handlers) (`litespec/backend/persistence#keep-uniqueness-out-of-handlers`). It runs in Application, Infrastructure, and Worker. Its category is `LiteSpec.Layers`. Severity and enablement follow the [Analyzers overview](https://litespec.dev/4.0.0/analyzers/README.md).

### What the Rule Reports

The rule reports a command or query handler, which is a class whose name ends in `CommandHandler` or `QueryHandler`, or that implements `ICommandHandler` or `IQueryHandler`, that takes a constructor parameter whose full type name is listed in the `litespec.LS2016.pipeline_owned_types` key. The diagnostic sits on the parameter type, and its message names the handler and the collaborator.

### Failing Example

```csharp
internal sealed class RenewLoanCommandHandler(IUnitOfWork unitOfWork)
{
}
```

### Passing Example

```csharp
internal sealed class RenewLoanCommandHandler(ILoanRepository loanRepository)
{
}
```

### How to Fix

Take only the repositories the record's changes and reads name. The pipeline owns the unit of work, idempotency, and the outbox, and persistence owns uniqueness claims.

### Configuration

The rule reads the comma-separated `.editorconfig` key `litespec.LS2016.pipeline_owned_types`, which lists the full type names the rule reports. When the key is absent or empty, the rule reports these defaults:

- `LiteBus.Messaging.Abstractions.IUnitOfWork`
- `LiteBus.Messaging.Abstractions.IIdempotencyStore`
- `LiteBus.Outbox.Abstractions.ITransactionalOutbox`
- `LiteBus.Outbox.Abstractions.IOutbox`

A project adds its uniqueness claim service to the same key:

```ini
litespec.LS2016.pipeline_owned_types = LiteBus.Messaging.Abstractions.IUnitOfWork, LiteBus.Messaging.Abstractions.IIdempotencyStore, LiteBus.Outbox.Abstractions.ITransactionalOutbox, LiteBus.Outbox.Abstractions.IOutbox, Loans.Holds.IHoldClaimService
```

## Notes

### What the Rule Ignores

The rule does not report a constructor parameter whose type is not listed, a collaborator taken outside a constructor, or a handler that is neither a command nor a query handler. It does not run in Domain or WebApi.
