Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static IServiceCollection AddRequiredMvcComponents(this IServiceCollectio
var mvcBuilder = services.AddMvcCore(options => {
//options.Filters.Add<ApiExceptionFilter>();
});
mvcBuilder.AddApiExplorer(); //for swagger
mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
mvcBuilder.AddJsonFormatters();
return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.Extensions.Http.Polly">
<Version>2.2.0</Version>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"O2NextGen.SmallTalk.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
34 changes: 24 additions & 10 deletions src/Services/smalltalk/O2NextGen.SmallTalk.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Polly;
using System;
using System.Threading.Tasks;
using Swashbuckle.AspNetCore.Swagger;

namespace O2NextGen.SmallTalk.Api
{
Expand All @@ -24,6 +25,17 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddRequiredMvcComponents();
services.AddBusiness();
services.AddSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SwaggerDoc("v1", new Info()
{
Title = "O2NextGen Platform. SmallTalk HTTP API",
Version = "v1",
Description = "SmallTalk API Service. The service allows you to create chats",
TermsOfService = "Terms of Service"
});
});
services.AddApplicationServices(Configuration);
}

Expand All @@ -39,12 +51,14 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
}

app.UseStaticFiles();
app.UseSwagger()
.UseSwaggerUI(c => { c.SwaggerEndpoint($"/swagger/v1/swagger.json", "SmallTalk API V1"); });

app.Use(async (context, next) =>
{
context.Response.OnStarting(() =>
{
context.Response.Headers.Add("X-Power-By", "O2NextGen: SmallTalk Api");
context.Response.Headers.Add("X-Power-By", "O2NextGen: SmallTalk API");
return Task.CompletedTask;
});

Expand All @@ -54,25 +68,25 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseMvc();
}
}

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection AddApplicationServices(this IServiceCollection services,
IConfiguration configuration)
{
//register delegating handlers
// services.AddTransient<HttpClientAuthorizationDelegatingHandler>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

//register http services
services
.AddHttpClient<ISignalRService, SignalRService>("Signal-R", client =>
{
client.BaseAddress = new Uri(configuration.GetValue<string>("urls:SignalRUrl"));
})
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(5, arrempt => TimeSpan.FromSeconds(arrempt * 2)
));
.AddHttpClient<ISignalRService, SignalRService>("Signal-R",
client => { client.BaseAddress = new Uri(configuration.GetValue<string>("urls:SignalRUrl")); })
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(5,
arrempt => TimeSpan.FromSeconds(arrempt * 2)
));

return services;
}
}
}

}