Skip to content

Commit

Permalink
Merge pull request #5 from drwatson1/rel-2.2
Browse files Browse the repository at this point in the history
Rel 2.2
  • Loading branch information
drwatson1 authored Aug 14, 2020
2 parents 606a406 + b5b8f47 commit a399fde
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 48 deletions.
2 changes: 1 addition & 1 deletion ProjectTemplates/How to create new template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After making any changes do:
1. Select Release configuration for a solution
1. Select ReferenceProject in "Solution Explorer" and click "Project/Export Template..." menu item from the VS main menu
1. In the appeared dialog box select "Project template" option and "ReferenceProject" in the combobox below and click Next
1. Set the value `ASP.Net Core RESTful Service` as a template name and the `Project template to create production-ready RESTful service based on ASP.Net Core v2.X. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features` as a description
1. Set the value `ASP.Net Core RESTful Service` as a template name and theProject template to create production-ready RESTful service based on ASP.Net Core v3.1. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features `` as a description
1. Don't foget to replace .Net Core version in the description above to the appropriate one.
1. Clear checkbox "Automatically import the template into Visual Studio" if you don't want immediately import it and click Finish button
1. Extract all files from the created zip-archive to any folder as you want. Typically, the file can be found in `C:\Users\<YOU>\Documents\Visual Studio 2019\My Exported Templates` folder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using Contrib.Extensions.Configuration;

namespace ReferenceProject.Configuration
{
public static class ApplicationSettings
{
public static void AddSettings(this IServiceCollection services)
{
// Uses AutoBind and SubstituteVariables from https://github.com/drwatson1/configuration-extensions project
services.AddOptions<Settings.Products>()
.AutoBind()
.SubstituteVariables();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ReferenceProject
{
public static class DependenciesConfig
public static class SwaggerConfig
{
/// <summary>
/// Add Swagger middleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ReferenceProject.Repo;
using System;
using System.Collections.Generic;
Expand All @@ -14,15 +15,17 @@ namespace ReferenceProject.Controllers
[Produces("application/json")]
public class ProductsController: ControllerBase
{
Repo.IProductsRepo ProductsRepo { get; }
IProductsRepo ProductsRepo { get; }
IOptionsSnapshot<Settings.Products> Settings { get; }
IMapper Mapper { get; }
ILogger Logger { get; }

public ProductsController(IProductsRepo productsRepo, IMapper mapper, ILogger<ProductsController> logger)
public ProductsController(IProductsRepo productsRepo, IOptionsSnapshot<Settings.Products> options, IMapper mapper, ILogger<ProductsController> logger)
{
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
Mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
ProductsRepo = productsRepo ?? throw new ArgumentNullException(nameof(productsRepo));
Settings = options ?? throw new ArgumentNullException(nameof(options));
}

/// <summary>
Expand Down Expand Up @@ -111,5 +114,17 @@ public IActionResult ThrowAnException()
{
throw new Exception("Example exception");
}

/// <summary>
/// Demonstrate how to use application settings
/// </summary>
/// <returns>Application settings</returns>
/// <remarks>Don't do this in production! You can unintentionally unclose sensitive information</remarks>
[HttpGet("Settings")]
[ProducesResponseType(StatusCodes.Status200OK)]
public Settings.Products GetSettings()
{
return Settings.Value;
}
}
}
15 changes: 9 additions & 6 deletions ProjectTemplates/ReferenceProject/ReferenceProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac.Configuration" Version="4.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Autofac.Configuration" Version="5.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Contrib.Extensions.Configuration.AutoBind" Version="1.0.0" />
<PackageReference Include="Contrib.Extensions.Configuration.VariablesSubstitution" Version="1.1.0" />
<PackageReference Include="DotNetEnv" Version="1.4.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Filters.Expressions" Version="2.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

Expand Down
22 changes: 0 additions & 22 deletions ProjectTemplates/ReferenceProject/Settings.cs

This file was deleted.

8 changes: 8 additions & 0 deletions ProjectTemplates/ReferenceProject/Settings/Products.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ReferenceProject.Settings
{
public class Products
{
public string TempFolder { get; set; }
public string BackendServiceUrl { get; set; }
}
}
9 changes: 5 additions & 4 deletions ProjectTemplates/ReferenceProject/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Autofac;
using Autofac.Configuration;
using Autofac.Core;
using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
Expand All @@ -15,6 +16,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using ReferenceProject.Configuration;
using ReferenceProject.Filters;
using ReferenceProject.Modules;
using System.IO;
Expand All @@ -37,10 +39,7 @@ public Startup(IConfiguration configuration, IHostEnvironment env)

// https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#using-environment-variables-in-configuration-options
var envPath = Path.Combine(env.ContentRootPath, ".env");
if (File.Exists(envPath))
{
DotNetEnv.Env.Load(envPath);
}
DotNetEnv.Env.Load(envPath);

// See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#content-formatting
JsonConvert.DefaultSettings = () =>
Expand Down Expand Up @@ -97,6 +96,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddRouting();
services.AddControllers();
services.AddHealthChecks();

services.AddSettings();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Debug",
"System": "Debug"
}
"Default": "Debug"
}
}
}
25 changes: 19 additions & 6 deletions ProjectTemplates/ReferenceProject/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Warning",
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting": "Information",
"System": "Warning"
}
},
"Filter": [],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%AppData%/Logs/ReferenceProject.log",
"rollingInterval": "Day",
"buffered": false
"rollOnFileSizeLimit": true,
"fileSizeLimitBytes": 10485760,
"retainedFileCountLimit": 10,
"buffered": false,
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "Console"
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [
"FromLogContext"
]
},
"Products": {
"TempFolder": "%TEMP%",
"BackendServiceUrl": "http://%gateway%/backend"
},
"AllowedHosts": "*",
"CoolServiceEndpoint": "http://%ENDPOINT_HOST%/cool",
"AnotherServiceEndpoint": "http://%ENDPOINT_HOST%/another",
"Urls": "http://localhost:5000"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="ASP.Net Core RESTful Service Template-1" Version="2.1" Language="en-US" Publisher="Sergey Tregub" />
<Identity Id="ASP.Net Core RESTful Service Template-1" Version="2.2" Language="en-US" Publisher="Sergey Tregub" />
<DisplayName>ASP.Net Core 3.1 RESTful Service Template</DisplayName>
<Description xml:space="preserve">Project template to create production-ready RESTful service based on ASP.Net Core 3.1. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features</Description>
<MoreInfo>https://github.com/drwatson1/AspNet-Core-REST-Service</MoreInfo>
Expand Down

0 comments on commit a399fde

Please sign in to comment.