Lazy-init formatter resolvers in MessagePackHubProtocolOptions (#10929)

This commit is contained in:
Mikael Mengistu 2019-06-06 08:33:32 -07:00 committed by GitHub
parent fdba8a91f9
commit b08577342d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.SignalR
public partial class MessagePackHubProtocolOptions
{
public MessagePackHubProtocolOptions() { }
public System.Collections.Generic.IList<MessagePack.IFormatterResolver> FormatterResolvers { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.Collections.Generic.IList<MessagePack.IFormatterResolver> FormatterResolvers { get { throw null; } set { } }
}
}
namespace Microsoft.AspNetCore.SignalR.Protocol

View File

@ -9,6 +9,25 @@ namespace Microsoft.AspNetCore.SignalR
{
public class MessagePackHubProtocolOptions
{
public IList<IFormatterResolver> FormatterResolvers { get; set; } = MessagePackHubProtocol.CreateDefaultFormatterResolvers();
private IList<IFormatterResolver> _formatterResolvers;
public IList<IFormatterResolver> FormatterResolvers
{
get
{
if (_formatterResolvers == null)
{
// The default set of resolvers trigger a static constructor that throws on AOT environments.
// This gives users the chance to use an AOT friendly formatter.
_formatterResolvers = MessagePackHubProtocol.CreateDefaultFormatterResolvers();
}
return _formatterResolvers;
}
set
{
_formatterResolvers = value;
}
}
}
}