diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Controllers/BinaryGoController.cs b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Controllers/BinaryGoController.cs index 7b7252f..2339817 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Controllers/BinaryGoController.cs +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Controllers/BinaryGoController.cs @@ -12,9 +12,9 @@ namespace WebAPISampleProject.BinaryGo.Controllers; [ApiController] public class BinaryGoController : ControllerBase { - private readonly IBinarySerialization _binarySerialization; + private readonly IBinarySerializationProvider _binarySerialization; - public BinaryGoController(IBinarySerialization binarySerialization) + public BinaryGoController(IBinarySerializationProvider binarySerialization) { _binarySerialization = binarySerialization; } diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Program.cs b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Program.cs index 04d48f8..32db80e 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Program.cs +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/Program.cs @@ -9,7 +9,7 @@ // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/WebAPISampleProject.BinaryGo.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/WebAPISampleProject.BinaryGo.csproj index 93117b4..a4dcb71 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/WebAPISampleProject.BinaryGo.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.BinaryGo/WebAPISampleProject.BinaryGo.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Controllers/DIController.cs b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Controllers/DIController.cs new file mode 100644 index 0000000..2b302cb --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Controllers/DIController.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Common.Models; +using EasyMicroservices.Serialization.Interfaces; +using Microsoft.AspNetCore.Mvc; + + +namespace WebAPISampleProject.BinaryGo.Controllers; + +[Route("api/[controller]")] +[ApiController] +public class DIController : ControllerBase +{ + private readonly IBinarySerializationProvider _binarySerialization; + private readonly ITextSerializationProvider _textSerialization; + + public DIController(IBinarySerializationProvider binarySerialization, ITextSerializationProvider textSerialization) + { + _binarySerialization = binarySerialization; + _textSerialization = textSerialization; + } + + [Route("Serialize")] + [HttpGet] + public IActionResult Serialize() + { + Customer model = new Customer() { Age = 51, FirstName = "Elon", LastName = "Musk" }; + var result = _textSerialization.Serialize(model); + var binary = _binarySerialization.Serialize(model); + return Ok(result); + } +} diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Program.cs b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Program.cs new file mode 100644 index 0000000..3f188c5 --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Program.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace WebAPISampleProject.DependencyInjection +{ + public class Program + { + public static void Main(string[] args) + { + + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + builder.Services.AddSerialization(o => + { + o.UseBinaryGo(); + o.UseNewtonsoftJson(); + }); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + app.MapControllers(); + + + app.Run(); + + } + } +} diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Properties/launchSettings.json b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Properties/launchSettings.json new file mode 100644 index 0000000..45dfd18 --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:41852", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger/index.html", + "applicationUrl": "http://localhost:5223", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger/index.html", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/WebAPISampleProject.DependencyInjection.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/WebAPISampleProject.DependencyInjection.csproj new file mode 100644 index 0000000..7482fc6 --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/WebAPISampleProject.DependencyInjection.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + + + + + + + + + + + + + + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.Development.json b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.json b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.DependencyInjection/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.MessagePack/WebAPISampleProject.MessagePack.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.MessagePack/WebAPISampleProject.MessagePack.csproj index ba01400..b7fd66a 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.MessagePack/WebAPISampleProject.MessagePack.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.MessagePack/WebAPISampleProject.MessagePack.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/Controllers/NewtonSoftJsonController.cs b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/Controllers/NewtonSoftJsonController.cs index d0e9c97..412f032 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/Controllers/NewtonSoftJsonController.cs +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/Controllers/NewtonSoftJsonController.cs @@ -12,9 +12,9 @@ namespace WebAPISampleProject.NewtonSoft.Json.Controllers [ApiController] public class NewtonSoftJsonController : ControllerBase { - private readonly ITextSerialization _textSerialization; + private readonly ITextSerializationProvider _textSerialization; - public NewtonSoftJsonController(ITextSerialization textSerialization) + public NewtonSoftJsonController(ITextSerializationProvider textSerialization) { _textSerialization = textSerialization; } diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/WebAPISampleProject.NewtonSoft.Json.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/WebAPISampleProject.NewtonSoft.Json.csproj index 0faaaca..dabef51 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/WebAPISampleProject.NewtonSoft.Json.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.NewtonSoft.Json/WebAPISampleProject.NewtonSoft.Json.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Json/WebAPISampleProject.System.Text.Json.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Json/WebAPISampleProject.System.Text.Json.csproj index 7da9edc..b04c165 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Json/WebAPISampleProject.System.Text.Json.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Json/WebAPISampleProject.System.Text.Json.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Xml/WebAPISampleProject.System.Text.Xml.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Xml/WebAPISampleProject.System.Text.Xml.csproj index 7d410df..9e3e66f 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Xml/WebAPISampleProject.System.Text.Xml.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.Text.Xml/WebAPISampleProject.System.Text.Xml.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.YamlDotNet/WebAPISampleProject.System.YamlDotNet.csproj b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.YamlDotNet/WebAPISampleProject.System.YamlDotNet.csproj index de9cde3..c8a29cd 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.YamlDotNet/WebAPISampleProject.System.YamlDotNet.csproj +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.System.YamlDotNet/WebAPISampleProject.System.YamlDotNet.csproj @@ -7,7 +7,7 @@ - + diff --git a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.sln b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.sln index 1aafbc2..0131d38 100644 --- a/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.sln +++ b/Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.sln @@ -1,20 +1,25 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.BinaryGo", "WebAPISampleProject.BinaryGo\WebAPISampleProject.BinaryGo.csproj", "{F603C96F-5577-4B8C-A306-549E0CA7152B}" +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34018.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.BinaryGo", "WebAPISampleProject.BinaryGo\WebAPISampleProject.BinaryGo.csproj", "{F603C96F-5577-4B8C-A306-549E0CA7152B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.MessagePack", "WebAPISampleProject.MessagePack\WebAPISampleProject.MessagePack.csproj", "{A1CC73D8-23BF-4827-AC4E-82C86AF591EF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.MessagePack", "WebAPISampleProject.MessagePack\WebAPISampleProject.MessagePack.csproj", "{A1CC73D8-23BF-4827-AC4E-82C86AF591EF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{F7966FE8-0D7C-4F72-9096-BFC51CCBC37F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{F7966FE8-0D7C-4F72-9096-BFC51CCBC37F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.MemoryPack", "WebAPISampleProject.MemoryPack\WebAPISampleProject.MemoryPack.csproj", "{1A5784AC-360B-4125-AB44-7731CE42FC4D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.MemoryPack", "WebAPISampleProject.MemoryPack\WebAPISampleProject.MemoryPack.csproj", "{1A5784AC-360B-4125-AB44-7731CE42FC4D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.NewtonSoft.Json", "WebAPISampleProject.NewtonSoft.Json\WebAPISampleProject.NewtonSoft.Json.csproj", "{5C52E3C0-A61F-46FF-8058-7BBB9E305175}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.NewtonSoft.Json", "WebAPISampleProject.NewtonSoft.Json\WebAPISampleProject.NewtonSoft.Json.csproj", "{5C52E3C0-A61F-46FF-8058-7BBB9E305175}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.System.Text.Json", "WebAPISampleProject.System.Text.Json\WebAPISampleProject.System.Text.Json.csproj", "{A22533D2-41D5-4790-AAF3-DAA9A980CF1F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.System.Text.Json", "WebAPISampleProject.System.Text.Json\WebAPISampleProject.System.Text.Json.csproj", "{A22533D2-41D5-4790-AAF3-DAA9A980CF1F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.System.Text.Xml", "WebAPISampleProject.System.Text.Xml\WebAPISampleProject.System.Text.Xml.csproj", "{0BBD61EB-BD84-4AA1-B451-9E9043A1EBC4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.System.Text.Xml", "WebAPISampleProject.System.Text.Xml\WebAPISampleProject.System.Text.Xml.csproj", "{0BBD61EB-BD84-4AA1-B451-9E9043A1EBC4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.System.YamlDotNet", "WebAPISampleProject.System.YamlDotNet\WebAPISampleProject.System.YamlDotNet.csproj", "{3425E080-5DF6-45D8-9538-B74E1E8A8C39}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPISampleProject.System.YamlDotNet", "WebAPISampleProject.System.YamlDotNet\WebAPISampleProject.System.YamlDotNet.csproj", "{3425E080-5DF6-45D8-9538-B74E1E8A8C39}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPISampleProject.DependencyInjection", "WebAPISampleProject.DependencyInjection\WebAPISampleProject.DependencyInjection.csproj", "{BAE024EF-23E4-4CBE-99E3-A25CBDB955D1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -54,5 +59,12 @@ Global {3425E080-5DF6-45D8-9538-B74E1E8A8C39}.Debug|Any CPU.Build.0 = Debug|Any CPU {3425E080-5DF6-45D8-9538-B74E1E8A8C39}.Release|Any CPU.ActiveCfg = Release|Any CPU {3425E080-5DF6-45D8-9538-B74E1E8A8C39}.Release|Any CPU.Build.0 = Release|Any CPU + {BAE024EF-23E4-4CBE-99E3-A25CBDB955D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAE024EF-23E4-4CBE-99E3-A25CBDB955D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAE024EF-23E4-4CBE-99E3-A25CBDB955D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAE024EF-23E4-4CBE-99E3-A25CBDB955D1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal