Skip to content

Commit

Permalink
Merge pull request #59 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Add more samples for Dependency injection
  • Loading branch information
Ali-YousefiTelori authored Sep 14, 2023
2 parents 009c99d + 0a26b68 commit 50a43e6
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBinarySerialization, BinaryGoProvider>();
builder.Services.AddScoped<IBinarySerializationProvider, BinaryGoProvider>();

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.BinaryGo" Version="0.0.0.2" />
<PackageReference Include="EasyMicroservices.Serialization.BinaryGo" Version="0.0.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();

}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.BinaryGo" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.Serialization.DependencyInjection" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.MessagePack" Version="0.0.0.2" />
<PackageReference Include="EasyMicroservices.Serialization.MessagePack" Version="0.0.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Json" Version="0.0.0.5" />
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Json" Version="0.0.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Xml" Version="0.0.0.2" />
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Xml" Version="0.0.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.YamlDotNet" Version="0.0.0.2" />
<PackageReference Include="EasyMicroservices.Serialization.YamlDotNet" Version="0.0.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
28 changes: 20 additions & 8 deletions Samples/CSharp/ASPCore/WebAPISampleProject/WebAPISampleProject.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 50a43e6

Please sign in to comment.