44
55using System ;
66using System . Collections . Generic ;
7+ using System . Diagnostics . CodeAnalysis ;
78using System . Net ;
89using System . Net . Http ;
910using Microsoft . Kiota . Abstractions ;
@@ -126,6 +127,7 @@ public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? o
126127 /// </summary>
127128 /// <returns>A list of all the default handlers</returns>
128129 /// <remarks>Order matters</remarks>
130+ [ Obsolete ( "Use GetDefaultHandlerActivatableTypes instead" ) ]
129131 public static IList < System . Type > GetDefaultHandlerTypes ( )
130132 {
131133 return new List < System . Type >
@@ -140,6 +142,72 @@ public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? o
140142 } ;
141143 }
142144
145+ /// <summary>
146+ /// Gets the default handler types.
147+ /// </summary>
148+ /// <returns>A list of all the default handlers</returns>
149+ /// <remarks>Order matters</remarks>
150+ public static IList < ActivatableType > GetDefaultHandlerActivatableTypes ( )
151+ {
152+ return new List < ActivatableType > ( )
153+ {
154+ new ( typeof ( UriReplacementHandler < UriReplacementHandlerOption > ) ) ,
155+ new ( typeof ( RetryHandler ) ) ,
156+ new ( typeof ( RedirectHandler ) ) ,
157+ new ( typeof ( ParametersNameDecodingHandler ) ) ,
158+ new ( typeof ( UserAgentHandler ) ) ,
159+ new ( typeof ( HeadersInspectionHandler ) ) ,
160+ new ( typeof ( BodyInspectionHandler ) ) ,
161+ } ;
162+ }
163+
164+ /// <summary>
165+ /// Provides DI-safe trim annotations for an underlying type.
166+ /// Required due to https://github.com/dotnet/runtime/issues/110239
167+ /// </summary>
168+ public readonly struct ActivatableType
169+ {
170+ #if NET5_0_OR_GREATER
171+ /// <summary>
172+ /// Provides DI-safe trim annotations for an underlying type.
173+ /// </summary>
174+ /// <param name="type">The type to be wrapped.</param>
175+ public ActivatableType ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type type )
176+ {
177+ Type = type ;
178+ }
179+
180+ /// <summary>
181+ /// The underlying type.
182+ /// </summary>
183+ [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicConstructors ) ]
184+ public readonly Type Type ;
185+
186+ #else
187+ /// <summary>
188+ /// Provides DI-safe trim annotations for an underlying type.
189+ /// </summary>
190+ /// <param name="type">The type to be wrapped.</param>
191+ public ActivatableType ( Type type )
192+ {
193+ Type = type ;
194+ }
195+
196+ /// <summary>
197+ /// The underlying type.
198+ /// </summary>
199+ public readonly Type Type ;
200+ #endif
201+
202+ /// <summary>
203+ /// Implicitly converts from the wrapper to the underlying type.
204+ /// </summary>
205+ /// <param name="type">An instance of <see cref="ActivatableType"/></param>
206+ /// <returns>The <see cref="Type"/></returns>
207+ public static implicit operator Type ( ActivatableType type ) => type . Type ;
208+ }
209+
210+
143211 /// <summary>
144212 /// Creates a <see cref="DelegatingHandler"/> to use for the <see cref="HttpClient" /> from the provided <see cref="DelegatingHandler"/> instances. Order matters.
145213 /// </summary>
0 commit comments