Resolve Dependency Injection
resolve_injectionResolve Microsoft DI registrations for a service: returns implementation, lifetime, site, ambiguity, and collection consumption, so you can answer what gets injected.
Instructions
Resolve a Microsoft DI registration: what is registered for a service, with lifetime and site. Not usage (find_usages), implementers (find_implementations), construction (instantiation_sites).
It reads Add{Singleton,Scoped,Transient}, TryAdd*, descriptor adds built at the call, AddHostedService, project-local helpers registering their own type arguments (note 'via '), and a foreach over a static new(typeof(Service), typeof(Impl)) table. A key, and a closing, is a service of its own (IRepo, IRepo); open IRepo<> is read. Not read: a descriptor built elsewhere, AddHttpClient-style helpers, Scrutor, other containers.
Returns JSON: registrations (serviceType, implementationType [= its service for a self/instance form], lifetime, note, location, project, declaringMethod, key; note 'inferred, not read' = from a package helper's call shape AddSingletonAs().As(): lifetime from its name, body unseen; not in ambiguous or a winner) and: multiRegistration / registrationSites; ambiguous (ONE site registers several implementations of one service, not consumed as a collection); effectiveRegistration (2+ calls: the winner a single-service resolve gets, read only in ONE straight-line site; else null + reason); consumedAsCollection; constructorConsumerCount (plain constructor parameters; not a usage verdict); optionalDependencies (optional constructor parameters, each judged yes/no/unknown).
An empty list says why: resolvedKind 'not_found' plus 'nearest' = nothing in the solution names it; else a 'note' names the forms not read and which of them the solution holds (package helpers, conventions, runtime types) - empty means 'not statically visible', never 'not registered'.
Needs a live session. Test-project registrations and consumers count only with includeTests=true; testRegistrationsFiltered counts what that hid. interface is the SERVICE type (an interface, or a class registered as itself); a closed form (IRepo) lists that closing and IRepo<> (typeArgumentFilter: the rest); site narrows by file path.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Optional: narrow to registrations whose file path contains this substring. | |
| interface | Yes | The interface simple or fully-qualified name, e.g. 'ICodeAnalyzer'. A closed generic form ('IHandler<Saved>') lists only the registrations serving that closing; 'IHandler' or 'IHandler<T>' lists every closing. | |
| sessionId | Yes | The session_id returned by analyze_solution. Also takes an absolute .sln/.slnx/.slnf path, analyzed on first use. | |
| includeTests | No | Include registrations declared in test projects (default false - production focus). |