Find Instantiation Sites
instantiation_sitesFinds where a type is constructed (new, with) and which types inject it as a constructor parameter. Use it to see who creates X before changing a constructor and whether anything but tests builds it.
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 what is registered for it. 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, 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, optional 'note' and 'generatedCodeNote' (its project, or one it compiles against, lacks generated code), createdByCount, createdByTests, injectedIntoCount, injectedIntoTests, sites - a capped envelope: items (at most 200, each name, declaringType, namespace, kind, isTestProject, 'generated' in generator output; created sites first), count, totalFound, truncated - and optional 'nearest'. The four counts are true totals within scope. Test-project sites are included, not filtered: isTestProject marks each. A type the DI container builds has no recorded production site, so 'every site is a test' is not proof.
The 'note' leads with any unread VB, F# or markup code. 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; with every site a test (unscoped), it says so and names the markup views. 'nearest': a close declared name when no site was found and the name matches no declaration.
Read-only; works on a recalled session.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sessionId": "<sessionId>",
"typeName": "<typeName>"
},
"name": "instantiation_sites"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scope | No | 'solution' (default) or a namespace prefix of the SITE's namespace (e.g. 'MyApp.Core') to narrow which sites are scanned. | solution |
| typeName | Yes | The type whose instantiation/injection sites to find, matched on its simple name: generic args are dropped and namesakes are unioned (e.g. 'OrderService'); an external type such as 'List' is a valid query. A qualified form ('Ns.Type', 'Outer.Inner') is read as its simple name where no solution type of that name lies outside it, otherwise declined (a 'note' says so). | |
| sessionId | Yes | The session_id returned by analyze_solution. Also takes an absolute .sln/.slnx/.slnf path, analyzed on first use. |