-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
290 additions
and
250 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
STX.Serialization.POC.NoProvidersReferenced/Program.Exceptions.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,28 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace STX.Serialization.POC.NoProvidersReferenced | ||
{ | ||
internal partial class Program | ||
{ | ||
private static void TryCatch(Action action, [CallerMemberName] string testName = "none") | ||
{ | ||
try | ||
{ | ||
Console.WriteLine(testName); | ||
action(); | ||
} | ||
|
||
catch (Exception exception) | ||
{ | ||
Console.WriteLine(exception.Message); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
STX.Serialization.POC.NoProvidersReferenced/Program.Tests.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,116 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using STX.Serialization.Providers; | ||
using STX.Serialization.Providers.Abstractions; | ||
using System; | ||
|
||
namespace STX.Serialization.POC.NoProvidersReferenced | ||
{ | ||
internal partial class Program | ||
{ | ||
const string NEWTONSOFT_SPAL_ID = "STX.Serialization.Providers.NewtonsoftJson"; | ||
const string SYSTEMTEXT_SPAL_ID = "STX.Serialization.Providers.SystemTextJson"; | ||
|
||
private static void CallProviderWithoutDISingleProvider() | ||
{ | ||
TryCatch(() => | ||
{ | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
new SerializationAbstractionProvider(); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
|
||
private static void CallProviderWithoutDIMultipleProviders() | ||
{ | ||
TryCatch(() => | ||
{ | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
new SerializationAbstractionProvider(NEWTONSOFT_SPAL_ID); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
|
||
private static void CallProviderWithoutDIMultipleProvidersSwitching() | ||
{ | ||
TryCatch(() => | ||
{ | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
new SerializationAbstractionProvider(NEWTONSOFT_SPAL_ID); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
serializationAbstractionProvider.UseSerializationProvider(SYSTEMTEXT_SPAL_ID); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
|
||
private static void CallProviderWithDISingleProvider() | ||
{ | ||
TryCatch(() => | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
services | ||
.RegisterSerializationProviders(defaultProviderSPALId: NEWTONSOFT_SPAL_ID); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
using IServiceScope scope = serviceProvider.CreateScope(); | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
scope.ServiceProvider | ||
.GetRequiredService<ISerializationAbstractionProvider>(); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
|
||
private static void CallProviderWithDIMultipleProviders() | ||
{ | ||
TryCatch(() => | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
services | ||
.RegisterSerializationProviders(defaultProviderSPALId: NEWTONSOFT_SPAL_ID); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
using IServiceScope scope = serviceProvider.CreateScope(); | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
scope.ServiceProvider | ||
.GetRequiredService<ISerializationAbstractionProvider>(); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
|
||
private static void CallProviderWithDIMultipleProvidersSwitching() | ||
{ | ||
TryCatch(() => | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
services | ||
.RegisterSerializationProviders(defaultProviderSPALId: NEWTONSOFT_SPAL_ID); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
using IServiceScope scope = serviceProvider.CreateScope(); | ||
ISerializationAbstractionProvider serializationAbstractionProvider = | ||
scope.ServiceProvider | ||
.GetRequiredService<ISerializationAbstractionProvider>(); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
serializationAbstractionProvider.UseSerializationProvider(spalId: SYSTEMTEXT_SPAL_ID); | ||
Console.WriteLine(serializationAbstractionProvider.GetName()); | ||
}); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace STX.Serialization.POC | ||
{ | ||
internal partial class Program | ||
{ | ||
private static void TryCatch(Action action, [CallerMemberName] string testName = "none") | ||
{ | ||
try | ||
{ | ||
Console.WriteLine(testName); | ||
action(); | ||
} | ||
|
||
catch (Exception exception) | ||
{ | ||
Console.WriteLine(exception.Message); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} |
Oops, something went wrong.