Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

something test something #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,25 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers = ''
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers = ''
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers = ''
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.pascal_case.required_prefix = ''
dotnet_naming_style.pascal_case.required_suffix = ''
dotnet_naming_style.pascal_case.word_separator = ''
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix = ''
dotnet_naming_style.begins_with_i.word_separator = ''
dotnet_naming_style.begins_with_i.required_prefix =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

20 changes: 20 additions & 0 deletions ApiTest/ApiTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeepL.Extensions.Microsoft.DependencyInjection\DeepL.Extensions.DependencyInjection.csproj" />
<ProjectReference Include="..\DeepLTests\DeepLTests.csproj" />
<ProjectReference Include="..\DeepL\DeepL.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions ApiTest/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 DeepL SE (https://www.deepl.com)
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.

using DeepL;
using DeepL.Model;
using Microsoft.AspNetCore.Mvc;

namespace ApiTest.Controllers;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase {
private readonly ITranslator _translatr;

public WeatherForecastController(ITranslator translatr) {
_translatr = translatr;
}

[HttpGet]
public async Task<Usage> Test() => await _translatr.GetUsageAsync();
}
34 changes: 34 additions & 0 deletions ApiTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 DeepL SE (https://www.deepl.com)
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.

using DeepL.Extensions.DependencyInjection;

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.AddDeepL(translator => {
translator.AuthKey = ":fx";
});

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();
41 changes: 41 additions & 0 deletions ApiTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:27056",
"sslPort": 44334
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5129",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7155;http://localhost:5129",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions ApiTest/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions ApiTest/appsettings.json
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
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>sgKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 DeepL SE (https://www.deepl.com)
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.

using DeepL.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace DeepL.Extensions.DependencyInjection;
public static class ServiceCollectionExtensions {
public static IServiceCollection AddDeepL(
this IServiceCollection services,
Action<TranslatorOptions> translatorOptionsAction,
Action<DeepLDependencyInjectionOptions>? dependencyInjectionOptionsAction = null,
Action<IHttpClientBuilder>? clientBuilderAction = null) {

var dependencyInjectionOptions = new DeepLDependencyInjectionOptions();
dependencyInjectionOptionsAction?.Invoke(dependencyInjectionOptions);

//This solves the constructor issue detailed here - https://github.com/dotnet/extensions/issues/3132#issuecomment-606960048
var clientBuilder = services.AddHttpClient(nameof(DeepLClient));
clientBuilderAction?.Invoke(clientBuilder);


services.AddTransient(provider => {
var options = provider.GetRequiredService<IOptions<TranslatorOptions>>();
var factory = provider.GetRequiredService<IHttpClientFactory>();
return new DeepLClient(factory.CreateClient(nameof(DeepLClient)), options);
});

var translatorOptions = new TranslatorOptions();
translatorOptionsAction.Invoke(translatorOptions);

services.Configure<TranslatorOptions>(options => {
translatorOptionsAction?.Invoke(options);
});

if (dependencyInjectionOptions.UseDefaultResiliencyOptions) {
clientBuilder.AddPolicyHandler(DeepLClient.CreateDefaultPolicy(translatorOptions.PerRetryConnectionTimeout, translatorOptions.MaximumNetworkRetries));
}

services.Add(ServiceDescriptor.Describe(typeof(ITranslator), provider => {
var client = provider.GetRequiredService<DeepLClient>();
return new Translator(client);
}, dependencyInjectionOptions.ServiceLifetime));

return services;
}


public class DeepLDependencyInjectionOptions {
public ServiceLifetime ServiceLifetime { get; set; } = ServiceLifetime.Transient;
public bool UseDefaultResiliencyOptions { get; set; }
}
}
Binary file not shown.
25 changes: 23 additions & 2 deletions DeepL.net.sln
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeepL", "DeepL\DeepL.csproj", "{87DDF1B7-2007-4E90-BDF3-6F6AE465A853}"
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeepL", "DeepL\DeepL.csproj", "{87DDF1B7-2007-4E90-BDF3-6F6AE465A853}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeepLTests", "DeepLTests\DeepLTests.csproj", "{3582DAA3-A216-4D58-83C8-BA91B4EE2260}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeepLTests", "DeepLTests\DeepLTests.csproj", "{3582DAA3-A216-4D58-83C8-BA91B4EE2260}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiTest", "ApiTest\ApiTest.csproj", "{C2B007AD-46BB-4140-82E0-0454783893BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeepL.Extensions.DependencyInjection", "DeepL.Extensions.Microsoft.DependencyInjection\DeepL.Extensions.DependencyInjection.csproj", "{0E43D591-BB48-481F-AC9C-BD5554894EB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -18,5 +25,19 @@ Global
{3582DAA3-A216-4D58-83C8-BA91B4EE2260}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3582DAA3-A216-4D58-83C8-BA91B4EE2260}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3582DAA3-A216-4D58-83C8-BA91B4EE2260}.Release|Any CPU.Build.0 = Release|Any CPU
{C2B007AD-46BB-4140-82E0-0454783893BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2B007AD-46BB-4140-82E0-0454783893BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2B007AD-46BB-4140-82E0-0454783893BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2B007AD-46BB-4140-82E0-0454783893BE}.Release|Any CPU.Build.0 = Release|Any CPU
{0E43D591-BB48-481F-AC9C-BD5554894EB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E43D591-BB48-481F-AC9C-BD5554894EB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E43D591-BB48-481F-AC9C-BD5554894EB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E43D591-BB48-481F-AC9C-BD5554894EB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {738E9B2C-7F3D-45CC-86FF-63B1881D80B5}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions DeepL/AssemblyDeclerations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2022 DeepL SE (https://www.deepl.com)
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("DeepL.Extensions.DependencyInjection, PublicKey=002400000480000094000000060200000024000052534131000400000100010099b45c9a28f6c8d626fc3aad5d807934b47a06214a400e45cec5e61214c1e56b3bf5f118a85b6e65c7a76cdbfbaaebfc2bd95e248e6f81ecc414718107d3e408ed6a58eb95e7b31479a46b41633d1e373df1e79fd8a90840624b81b9f3f019583bef44698a16304eac1d552d81e3a17173c8d17397242a29b394a0d0cf59edbf")]
Loading