Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<PackageReference Include="DNTFrameworkCore.Web.EntityFramework" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:43573",
"sslPort": 44365
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -21,10 +21,10 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/",
"applicationUrl": "https://localhost:6001;http://localhost:6000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:6001;http://localhost:6000"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static void AddWeb(this IServiceCollection services)
options.UseDefaultFilteredPagedQueryModelBinder();
options.Filters.Add<GlobalExceptionFilter>();
})
.AddApiExplorer()
.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.SwaggerUI;
using Swashbuckle.AspNetCore.Swagger;
using System.Collections.Generic;

namespace DNTFrameworkCoreTemplateAPI.API
{
Expand Down Expand Up @@ -63,6 +66,39 @@ public void ConfigureServices(IServiceCollection services)
services.AddResources();
services.AddWeb();
services.AddJwtAuthentication(Configuration);

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("api", new Info
{
Version = "api",
Title = "Services",
Description = "DNTFramework API Services",
Contact = new Contact
{
Email = "[email protected]",
Name = "GholamReza Rabbal",
Url = "http://www.dotnettips.info/user/%D8%BA%D9%84%D8%A7%D9%85%D8%B1%D8%B6%D8%A7%20%D8%B1%D8%A8%D8%A7%D9%84"
}
});

c.AddSecurityDefinition("Bearer", new ApiKeyScheme()
{
In = "header",
Description = "JWT Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
Name = "Authorization",
Type = "apiKey"
});

c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
{"oauth2", new string[] { }}
});

c.EnableAnnotations();

});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -116,6 +152,21 @@ await context.Response.WriteAsync(JsonConvert.SerializeObject(new
app.UseMvc();
app.UseSignalR(routes => { routes.MapHub<NotificationHub>("/api/notificationhub"); });
app.UseEFSecondLevelCache();

app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = httpReq.Host.Value);
c.RouteTemplate = "api-docs/{documentName}/swagger.json";

});

app.UseSwaggerUI(c =>
{
c.ShowExtensions();
c.SwaggerEndpoint($"/api-docs/api/swagger.json", "api");
c.DocExpansion(DocExpansion.None);
c.DocumentTitle = "Services";
});
}
}
}