Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.1.1-preview-548" />

 OptionalValueResolver

using System.Linq.Expressions; namespace Stashbox.Resolution.Resolvers { internal class OptionalValueResolver : IResolver { public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) { return typeInfo.DefaultValue.AsConstant(typeInfo.Type); } public bool CanUseForResolution(TypeInformation typeInfo, ResolutionContext resolutionContext) { return typeInfo.HasDefaultValue; } } }