Skip to content

Commit

Permalink
DESIGN: POC Implementation #10
Browse files Browse the repository at this point in the history
  • Loading branch information
LBoullosa committed Feb 17, 2024
1 parent aca7a4d commit c96391c
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 250 deletions.
28 changes: 28 additions & 0 deletions STX.Serialization.POC.NoProvidersReferenced/Program.Exceptions.cs
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 STX.Serialization.POC.NoProvidersReferenced/Program.Tests.cs
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());
});
}
}
}
128 changes: 2 additions & 126 deletions STX.Serialization.POC.NoProvidersReferenced/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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());
});
}

static void Main(string[] args)
{
CallProviderWithoutDISingleProvider();
Expand Down
28 changes: 28 additions & 0 deletions STX.Serialization.POC/Program.Exceptions.cs
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();
}
}
}
Loading

0 comments on commit c96391c

Please sign in to comment.