Find Instantiation Sites
instantiation_sitesFind where a type is constructed and where it is injected: the narrow 'who creates or obtains an instance of X?' that find_usages (every reference) cannot answer. resolve_injection answers the other half - what is registered for a type.
Instructions
Find where a type is constructed and where it is injected: the narrow 'who creates or obtains an instance of X?' that find_usages (every reference) cannot answer. resolve_injection answers the other half - what is registered for a type.
Use it before changing a constructor, and to see whether anything but a test builds a type.
'created': a method, constructor, accessor or top-level code that runs 'new X(...)', a target-typed new or a record 'with'; a field or property initializer is attributed to the constructor the compiler runs it in, so such a site is named '.ctor' ('.cctor' for a static one). 'injected': a type that takes X as a constructor parameter - no container is consulted. A parameter wrapped in another type (Lazy) is recorded under the outer type, and an array of X is not a creation of X.
Returns typeName, a 'note' when there is one, createdByCount, createdByTests, injectedIntoCount, injectedIntoTests, sites - at most 200 items (name, declaringType, namespace, kind, isTestProject), created sites first - and 'nearest'. The four counts are true totals within scope. Test-project sites are included, not filtered: isTestProject marks each, and createdByTests == createdByCount with a non-zero total means every recorded construction site is in a test project. A type the DI container builds has no recorded production site, so that reading is not proof.
A 'note' covers two zeros: with no site at all it names the construction paths this fact cannot see and the markup views naming the type; with injectedIntoCount 0 it names those of its interfaces something is injected under - a DI consumer takes the interface, so query that name. 'nearest' gives a close declared name when no site was found and the name matches no declaration.
Read-only; works on a recalled session. typeName is matched on its simple name: namespace and generic arguments are dropped, namesakes are unioned, and an external type ('List', 'HttpClient') is a valid query. scope is 'solution' or a namespace prefix on the SITE's namespace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scope | No | 'solution' (default) or a namespace prefix (e.g. 'MyApp.Core') to narrow which sites are scanned. | solution |
| typeName | Yes | The type whose instantiation/injection sites to find (simple name; namespace + generic args are normalized away, e.g. 'OrderService' or 'List'). | |
| sessionId | Yes | The session_id returned by analyze_solution. Also takes an absolute .sln/.slnx/.slnf path, analyzed on first use. |