|
7 | 7 | $h=When this occurs: you want to reuse base setup state without passing a separate context instance. |
8 | 8 | $h=What it solves: lets dependent compositions access base setup members directly (Unity-friendly, no constructor args). |
9 | 9 | $h=How it is solved in the example: uses DependsOn(..., SetupContextKind.Members) and sets members on the composition instance. The name parameter is optional; methods are declared partial and implemented by the user. |
10 | | -$f= |
11 | | -$f=What it shows: |
12 | | -$f=- Setup context members copied into the dependent composition. |
13 | | -$f=- Realistic scenario: configuring database connection and logging for a data service. |
14 | | -$f= |
15 | | -$f=Important points: |
16 | | -$f=- The composition remains parameterless and can be configured via its own members. |
17 | | -$f= |
18 | | -$f=Example demonstrates: |
19 | | -$f= 1. BaseComposition provides database connection settings, default timeout, and a protected diagnostics field |
20 | | -$f= 2. Dependent Composition adds logging level and max retries configuration |
21 | | -$f= 3. DataService uses all settings including the protected field for conditional output |
22 | | -$f= 4. Protected field 'EnableDiagnostics' from BaseComposition is accessible in Composition via DependsOn |
23 | | -$f= 5. Composition's constructor sets EnableDiagnostics to true to enable detailed status |
24 | | -$f= |
| 10 | +$h=The composition stays parameterless, so a host that instantiates it by convention - a UI framework, a test fixture - can still configure it through properties. |
| 11 | +$f=BaseComposition provides database connection settings, default timeout, and a protected diagnostics field; Composition adds a logging level and a max retry count; DataService reads all of them, including the protected field copied by the context. |
| 12 | +$f=Use this when a base setup's state is assigned after construction: the copied members become properties of the dependent composition, so the object initializer in the test is the normal way to supply configuration. |
| 13 | +$f=Members are copied by declaration, so the dependent composition needs a partial declaration of every referenced method that the base implements itself - here `GetDefaultTimeout`. |
25 | 14 | $f=Note: SetupContextKind.Members copies both public and protected members to the dependent composition. |
26 | | -$f= |
27 | | -$f=Useful when: |
28 | | -$f=- Base setup has instance members initialized by the host or framework. |
29 | | -$f=- You need to extend configuration with additional settings in derived compositions. |
| 15 | +$f=Prefer `SetupContextKind.Argument` ([setup context](dependent-compositions-with-setup-context.md)) when the base instance must stay the single owner of the state, because copied members are independent values on the dependent composition. |
30 | 16 | $f= |
31 | 17 | */ |
32 | 18 |
|
|
0 commit comments