-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Less an issue, more a question:
I'm trying to use NativeAOT in various projects, and eventually encountered an InvalidOperationException when attempting to construct UriReplacementHandler<UriReplacementHandlerOption>. Subsequent investigation found that (the royal) you fixed this problem in commit a2800ab, by:
- Obsoleting
KiotaClientFactory.GetDefaultHandlerTypes(). - Introducing
KiotaClientFactory.GetDefaultHandlerActivatableTypes(). - Introducing a new
KiotaClientFactory.ActivatableTypetype.
I understand (3), as it provides a useful place to use [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] so that constructors on UriReplacementHandler<UriReplacementHandlerOption> would be preserved.
However, as a "student" trying to better understand the ins, outs, why's, wherefores, etc. of supporting NativeAOT, I have to wonder:
Why did you do it this way?
One and a half alternatives come to mind.
Firstly, you could have used DynamicDependencyAttribute on the existing KiotaClientFactory.GetDefaultHandlerTypes() method:
partial class KiotaClientFactory
{
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(UriReplacementHandler<UriReplacementHandlerOption>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(RetryHandler))]
// β¦
public static IList<Type> GetDefaultHandlerTypes()
{
return new List<Type> {
typeof(UriReplacementHandler<UriReplacementHandlerOption>),
typeof(RetryHandler),
// β¦
};
}
}Pro: you're not "breaking" or obsoleting API. Consumers need only update the NuGet package version, and it just works.
Con: whenever you add a new type to the body of GetDefaultHandlerTypes(), you need to remember to add a [DynamicDependency] attribute. That's fair, but IMHO the Pro more than makes up for it.
The "and a half" solution is that I think you could have added KiotaClientFactory.GetDefaultHandlerActivatableTypes() as you did, and also update KiotaClientFactory.GetDefaultHandlerTypes() to chain to GetDefaultHandlerActivatableTypes():
partial class KiotaClientFactory
{
public static IList<Type> GetDefaultHandlerTypes()
=> GetDefaultHandlerActivatableTypes().Select(at => at.Type).ToList();
}I believe that this would still "appease" NativeAOT and cause the UriReplacementHandler<UriReplacementHandlerOption>/etc. constructors to be preserved, and also maintain backward compatibility: you wouldn't be required to use the new KiotaClientFactory.GetDefaultHandlerActivatableTypes() method to get NativeAOT support.
Is there a reason this wasn't done or wouldn't work?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status