@@ -72,7 +72,68 @@ public AutoSubstituteBuilder ConfigureBuilder(Action<ContainerBuilder> action)
72
72
}
73
73
74
74
/// <summary>
75
- /// Register the specified implementation type to the container as the specified service type and resolve it using the given parameters.
75
+ /// Register the specified implementation type to the container as itself with the given parameterst.
76
+ /// </summary>
77
+ /// <typeparam name="TService">The type to register the implementation as</typeparam>
78
+ /// <typeparam name="TImplementation">The implementation type</typeparam>
79
+ /// <param name="parameters">Optional constructor parameters</param>
80
+ /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
81
+ public AutoSubstituteBuilder Provide < TService > ( params Parameter [ ] parameters )
82
+ => Provide < TService , TService > ( out _ , parameters ) ;
83
+
84
+ /// <summary>
85
+ /// Register the type with the given factory to the container.
86
+ /// </summary>
87
+ /// <typeparam name="TService">The type to register the implementation as</typeparam>
88
+ /// <param name="providedValue">Parameter to obtain a provided value.</param>
89
+ /// <param name="factory">The factory method to produce the service.</param>
90
+ /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
91
+ public AutoSubstituteBuilder Provide < TService > ( out IProvidedValue < TService > providedValue , Func < IComponentContext , TService > factory )
92
+ {
93
+ var key = new object ( ) ;
94
+
95
+ _builder . Register ( factory )
96
+ . Keyed < TService > ( key )
97
+ . As < TService > ( )
98
+ . InstancePerLifetimeScope ( ) ;
99
+
100
+ providedValue = CreateProvidedValue < TService > ( c => c . ResolveKeyed < TService > ( key ) ) ;
101
+
102
+ return this ;
103
+ }
104
+
105
+ /// <summary>
106
+ /// Register the type with the given factory to the container.
107
+ /// </summary>
108
+ /// <typeparam name="TService">The type to register the implementation as</typeparam>
109
+ /// <param name="factory">The factory method to produce the service.</param>
110
+ /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
111
+ public AutoSubstituteBuilder Provide < TService > ( Func < IComponentContext , TService > factory )
112
+ => Provide ( out _ , factory ) ;
113
+
114
+ /// <summary>
115
+ /// Register the specified implementation type to the container as itself with the given parameters.
116
+ /// </summary>
117
+ /// <typeparam name="TService">The type to register the implementation as</typeparam>
118
+ /// <typeparam name="TImplementation">The implementation type</typeparam>
119
+ /// <param name="providedValue">Parameter to obtain a provided value.</param>
120
+ /// <param name="parameters">Optional constructor parameters</param>
121
+ /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
122
+ public AutoSubstituteBuilder Provide < TService > ( out IProvidedValue < TService > providedValue , params Parameter [ ] parameters )
123
+ => Provide < TService , TService > ( out providedValue , parameters ) ;
124
+
125
+ /// <summary>
126
+ /// Register the specified implementation type to the container as the specified service type with the given parameterst.
127
+ /// </summary>
128
+ /// <typeparam name="TService">The type to register the implementation as</typeparam>
129
+ /// <typeparam name="TImplementation">The implementation type</typeparam>
130
+ /// <param name="parameters">Optional constructor parameters</param>
131
+ /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
132
+ public AutoSubstituteBuilder Provide < TService , TImplementation > ( params Parameter [ ] parameters )
133
+ => Provide < TService , TImplementation > ( out _ , parameters ) ;
134
+
135
+ /// <summary>
136
+ /// Register the specified implementation type to the container as the specified service type with the given parameterst.
76
137
/// </summary>
77
138
/// <typeparam name="TService">The type to register the implementation as</typeparam>
78
139
/// <typeparam name="TImplementation">The implementation type</typeparam>
@@ -159,6 +220,8 @@ public SubstituteForBuilder<TService> SubstituteForPartsOf<TService>(params obje
159
220
/// <typeparam name="TService">The type to register and return a substitute for</typeparam>
160
221
/// <param name="parameters">Any constructor parameters that Autofac can't resolve automatically</param>
161
222
/// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
223
+ [ Obsolete ( "Use a Provide method instead" ) ]
224
+ [ System . ComponentModel . EditorBrowsable ( System . ComponentModel . EditorBrowsableState . Never ) ]
162
225
public AutoSubstituteBuilder ResolveAndSubstituteFor < TService > ( params Parameter [ ] parameters ) where TService : class
163
226
{
164
227
_builder . RegisterType < TService > ( )
0 commit comments