Skip to content

Commit 49f0d2c

Browse files
committed
Update README and BREAKING_CHANGES
1 parent 8a83838 commit 49f0d2c

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

AutofacContrib.NSubstitute/AutoSubstitute.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Autofac;
22
using Autofac.Core;
3-
using Autofac.Features.ResolveAnything;
43
using System;
54

65
namespace AutofacContrib.NSubstitute
@@ -32,7 +31,8 @@ public class AutoSubstitute : IDisposable
3231
/// </summary>
3332
public AutoSubstitute()
3433
{
35-
Container = Configure().InternalBuild();
34+
Container = Configure()
35+
.InternalBuild();
3636
}
3737

3838
/// <summary>

BREAKING_CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
AutofacContrib.NSubstitute (AutoSubstitute) Breaking Changes
22
============================================================
33

4+
Version 6.0.0
5+
-------------
6+
7+
Removed `AutoSubstitute.Provide(...)` methods and added `AutoSubstitute.Configure()` with a builder pattern.
8+
9+
### Reason
10+
Autofac now enforces immutability and containers cannot be changed after being built.
11+
12+
### Workaround
13+
Update usage of `.Provide(...)` to use the builder pattern instead.
14+
415
Version 4.0.0
516
-------------
617

README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ And then the following tests:
117117
public void Example_test_with_concrete_type_provided()
118118
{
119119
const int val = 3;
120-
var autoSubstitute = new AutoSubstitute();
120+
using var autoSubstitute = AutoSubstitute.Configure()
121+
.Provide<IDependency2, Dependency2>(out _)
122+
.Build();
121123
autoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val); // This shouldn't do anything because of the next line
122-
autoSubstitute.Provide<IDependency2, Dependency2>();
123124
autoSubstitute.Resolve<IDependency1>().SomeMethod(Arg.Any<int>()).Returns(c => c.Arg<int>());
124125

125126
var result = autoSubstitute.Resolve<MyClass>().AMethod();
@@ -132,9 +133,10 @@ public void Example_test_with_concrete_object_provide()
132133
{
133134
const int val1 = 3;
134135
const int val2 = 2;
135-
var autoSubstitute = new AutoSubstitute();
136+
using var autoSubstitute = AutoSubstitute.Configure()
137+
.Provide(new ConcreteClass(val2))
138+
.Build();
136139
autoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val1);
137-
autoSubstitute.Provide(new ConcreteClass(val2));
138140

139141
var result = autoSubstitute.Resolve<MyClassWithConcreteDependency>().AMethod();
140142

@@ -151,9 +153,10 @@ public void Example_test_with_substitute_for_concrete()
151153
const int val1 = 3;
152154
const int val2 = 2;
153155
const int val3 = 10;
154-
var autoSubstitute = new AutoSubstitute();
156+
using var autoSubstitute = AutoSubstitute.Configure()
157+
.SubstituteFor<ConcreteClass>(val2).Configure(c => c.Add(Arg.Any<int>()).Returns(val3))
158+
.Build();
155159
autoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val1);
156-
autoSubstitute.SubstituteFor<ConcreteClass>(val2).Add(Arg.Any<int>()).Returns(val3);
157160

158161
var result = autoSubstitute.Resolve<MyClassWithConcreteDependency>().AMethod();
159162

@@ -206,10 +209,9 @@ public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
206209
const int val1 = 2;
207210
const int val2 = 3;
208211
const int val3 = 4;
209-
var AutoSubstitute = new AutoSubstitute();
210-
// Much better / more maintainable than:
211-
//AutoSubstitute.SubstituteFor<ConcreteClassWithDependency>(AutoSubstitute.Resolve<IDependency1>(), val1);
212-
AutoSubstitute.ResolveAndSubstituteFor<ConcreteClassWithDependency>(new TypedParameter(typeof(int), val1));
212+
using var AutoSubstitute = AutoSubstitute.Configure()
213+
.ResolveAndSubstituteFor<ConcreteClassWithDependency>(new TypedParameter(typeof(int), val1))
214+
.Build();
213215
AutoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val2);
214216
AutoSubstitute.Resolve<IDependency1>().SomeMethod(val1).Returns(val3);
215217

0 commit comments

Comments
 (0)