diff --git a/STX.Serialization.POC.NoProvidersReferenced/Program.Exceptions.cs b/STX.Serialization.POC.NoProvidersReferenced/Program.Exceptions.cs new file mode 100644 index 0000000..9c22df8 --- /dev/null +++ b/STX.Serialization.POC.NoProvidersReferenced/Program.Exceptions.cs @@ -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(); + } + } +} diff --git a/STX.Serialization.POC.NoProvidersReferenced/Program.Tests.cs b/STX.Serialization.POC.NoProvidersReferenced/Program.Tests.cs new file mode 100644 index 0000000..4feeb50 --- /dev/null +++ b/STX.Serialization.POC.NoProvidersReferenced/Program.Tests.cs @@ -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(); + + 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(); + + 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(); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + + serializationAbstractionProvider.UseSerializationProvider(spalId: SYSTEMTEXT_SPAL_ID); + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + } +} diff --git a/STX.Serialization.POC.NoProvidersReferenced/Program.cs b/STX.Serialization.POC.NoProvidersReferenced/Program.cs index b6b15e8..2477725 100644 --- a/STX.Serialization.POC.NoProvidersReferenced/Program.cs +++ b/STX.Serialization.POC.NoProvidersReferenced/Program.cs @@ -2,134 +2,10 @@ // 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; -using System.Runtime.CompilerServices; - -namespace STX.Serialization.POC +namespace STX.Serialization.POC.NoProvidersReferenced { - internal class Program + 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 TryCatch(Action action, [CallerMemberName] string testName = "none") - { - try - { - Console.WriteLine(testName); - action(); - } - - catch (Exception exception) - { - Console.WriteLine(exception.Message); - } - - Console.WriteLine(); - } - - 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(); - - 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(); - - 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(); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - - serializationAbstractionProvider.UseSerializationProvider(spalId: SYSTEMTEXT_SPAL_ID); - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - static void Main(string[] args) { CallProviderWithoutDISingleProvider(); diff --git a/STX.Serialization.POC/Program.Exceptions.cs b/STX.Serialization.POC/Program.Exceptions.cs new file mode 100644 index 0000000..e39150a --- /dev/null +++ b/STX.Serialization.POC/Program.Exceptions.cs @@ -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(); + } + } +} diff --git a/STX.Serialization.POC/Program.Tests.cs b/STX.Serialization.POC/Program.Tests.cs new file mode 100644 index 0000000..1cee829 --- /dev/null +++ b/STX.Serialization.POC/Program.Tests.cs @@ -0,0 +1,115 @@ +// ---------------------------------------------------------------------------------- +// 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; +using ProviderNewtonsoft = STX.Serialization.Providers.NewtonsoftJson; +using ProviderSystemTextJson = STX.Serialization.Providers.SystemTextJson; + +namespace STX.Serialization.POC +{ + internal partial class Program + { + private static void CallProviderWithoutDISingleProvider() + { + TryCatch(() => + { + ISerializationAbstractionProvider serializationAbstractionProvider = + new SerializationAbstractionProvider(); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + + private static void CallProviderWithoutDIMultipleProviders() + { + TryCatch(() => + { + ISerializationAbstractionProvider serializationAbstractionProvider = + new SerializationAbstractionProvider(typeof(ProviderNewtonsoft.SerializationProvider)); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + + private static void CallProviderWithoutDIMultipleProvidersSwitching() + { + TryCatch(() => + { + ISerializationAbstractionProvider serializationAbstractionProvider = + new SerializationAbstractionProvider(typeof(ProviderNewtonsoft.SerializationProvider)); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + + serializationAbstractionProvider.UseSerializationProvider(); + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + + private static void CallProviderWithDISingleProvider() + { + TryCatch(() => + { + IServiceCollection services = new ServiceCollection(); + + services + .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + using IServiceScope scope = serviceProvider.CreateScope(); + + ISerializationAbstractionProvider serializationAbstractionProvider = + scope.ServiceProvider + .GetRequiredService(); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + + private static void CallProviderWithDIMultipleProviders() + { + TryCatch(() => + { + IServiceCollection services = new ServiceCollection(); + + services + .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + using IServiceScope scope = serviceProvider.CreateScope(); + + ISerializationAbstractionProvider serializationAbstractionProvider = + scope.ServiceProvider + .GetRequiredService(); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + + private static void CallProviderWithDIMultipleProvidersSwitching() + { + TryCatch(() => + { + IServiceCollection services = new ServiceCollection(); + + services + .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + using IServiceScope scope = serviceProvider.CreateScope(); + + ISerializationAbstractionProvider serializationAbstractionProvider = + scope.ServiceProvider + .GetRequiredService(); + + Console.WriteLine(serializationAbstractionProvider.GetName()); + + serializationAbstractionProvider.UseSerializationProvider(); + Console.WriteLine(serializationAbstractionProvider.GetName()); + }); + } + } +} diff --git a/STX.Serialization.POC/Program.cs b/STX.Serialization.POC/Program.cs index 56bd1cc..ed1883d 100644 --- a/STX.Serialization.POC/Program.cs +++ b/STX.Serialization.POC/Program.cs @@ -2,133 +2,10 @@ // 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; -using System.Runtime.CompilerServices; -using ProviderNewtonsoft = STX.Serialization.Providers.NewtonsoftJson; -using ProviderSystemTextJson = STX.Serialization.Providers.SystemTextJson; - namespace STX.Serialization.POC { - internal class Program + 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(); - } - - private static void CallProviderWithoutDISingleProvider() - { - TryCatch(() => - { - ISerializationAbstractionProvider serializationAbstractionProvider = - new SerializationAbstractionProvider(); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - - private static void CallProviderWithoutDIMultipleProviders() - { - TryCatch(() => - { - ISerializationAbstractionProvider serializationAbstractionProvider = - new SerializationAbstractionProvider(typeof(ProviderNewtonsoft.SerializationProvider)); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - - private static void CallProviderWithoutDIMultipleProvidersSwitching() - { - TryCatch(() => - { - ISerializationAbstractionProvider serializationAbstractionProvider = - new SerializationAbstractionProvider(typeof(ProviderNewtonsoft.SerializationProvider)); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - - serializationAbstractionProvider.UseSerializationProvider(); - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - - private static void CallProviderWithDISingleProvider() - { - TryCatch(() => - { - IServiceCollection services = new ServiceCollection(); - - services - .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); - - IServiceProvider serviceProvider = services.BuildServiceProvider(); - using IServiceScope scope = serviceProvider.CreateScope(); - - ISerializationAbstractionProvider serializationAbstractionProvider = - scope.ServiceProvider - .GetRequiredService(); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - - private static void CallProviderWithDIMultipleProviders() - { - TryCatch(() => - { - IServiceCollection services = new ServiceCollection(); - - services - .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); - - IServiceProvider serviceProvider = services.BuildServiceProvider(); - using IServiceScope scope = serviceProvider.CreateScope(); - - ISerializationAbstractionProvider serializationAbstractionProvider = - scope.ServiceProvider - .GetRequiredService(); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - - private static void CallProviderWithDIMultipleProvidersSwitching() - { - TryCatch(() => - { - IServiceCollection services = new ServiceCollection(); - - services - .RegisterSerializationProviders(defaultProviderType: typeof(ProviderNewtonsoft.SerializationProvider)); - - IServiceProvider serviceProvider = services.BuildServiceProvider(); - using IServiceScope scope = serviceProvider.CreateScope(); - - ISerializationAbstractionProvider serializationAbstractionProvider = - scope.ServiceProvider - .GetRequiredService(); - - Console.WriteLine(serializationAbstractionProvider.GetName()); - - serializationAbstractionProvider.UseSerializationProvider(); - Console.WriteLine(serializationAbstractionProvider.GetName()); - }); - } - static void Main(string[] args) { CallProviderWithoutDISingleProvider();