Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09e7925
commit 5a9d837
Showing
4 changed files
with
23 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/OrleansProviders/Streams/Memory/MemoryMessageBodySerializerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Orleans.Providers | ||
{ | ||
internal static class MemoryMessageBodySerializerFactory<TSerializer> | ||
where TSerializer : class, IMemoryMessageBodySerializer | ||
{ | ||
private static readonly Lazy<ObjectFactory> ObjectFactory = new Lazy<ObjectFactory>( | ||
() => ActivatorUtilities.CreateFactory( | ||
typeof(TSerializer), | ||
Type.EmptyTypes)); | ||
|
||
public static TSerializer GetOrCreateSerializer(IServiceProvider serviceProvider) | ||
{ | ||
return serviceProvider.GetService<TSerializer>() ?? | ||
(TSerializer) ObjectFactory.Value(serviceProvider, null); | ||
} | ||
} | ||
} |