Skip to content

Commit 24f5ad8

Browse files
committed
Update README
1 parent 36610b0 commit 24f5ad8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ public void Example_test_with_substitute_for_concrete()
164164
}
165165
```
166166

167+
If you want to configure it with a service from the container, you can use a separate overload:
168+
169+
```c#
170+
[Test]
171+
public void SubstituteForConfigureWithContext()
172+
{
173+
const int val = 2;
174+
175+
using var utoSubstitute = AutoSubstitute.Configure()
176+
.SubstituteFor<ConcreteClass>(val).Configured()
177+
.SubstituteFor<ConcreteClassWithObject>().Configure((s, ctx) =>
178+
{
179+
s.Configure().GetResult().Returns(ctx.Resolve<ConcreteClass>());
180+
})
181+
.Build()
182+
.Container;
183+
184+
var result = utoSubstitute.Resolve<ConcreteClassWithObject>().GetResult();
185+
186+
Assert.AreSame(result, utoSubstitute.Resolve<ConcreteClass>());
187+
}
188+
```
189+
167190
Similarly, you can resolve a concrete type from the autosubstitute container and register that with the underlying container using the `ResolveAndSubstituteFor` method:
168191

169192
```c#

0 commit comments

Comments
 (0)