Add project files.
This commit is contained in:
30
StandardConsole/Program.cs
Normal file
30
StandardConsole/Program.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using StandardConsole.Repositories;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IHost host = CreateHostBuilder(args).Build();
|
||||||
|
var worker = ActivatorUtilities.CreateInstance<Worker>((IServiceProvider)host.Services);
|
||||||
|
worker.Run();
|
||||||
|
|
||||||
|
static IHostBuilder CreateHostBuilder(string[] args)
|
||||||
|
{
|
||||||
|
return Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureAppConfiguration((context, configuration) =>
|
||||||
|
{
|
||||||
|
configuration.Sources.Clear();
|
||||||
|
var environmentName = Environment.GetEnvironmentVariable("DOTNETCORE_ENVIRONMENT");
|
||||||
|
configuration.AddJsonFile("appsettings.json",optional: true, reloadOnChange: true);
|
||||||
|
configuration.AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true);
|
||||||
|
configuration.AddCommandLine(args);
|
||||||
|
|
||||||
|
})
|
||||||
|
.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
services.AddScoped<ISampleRepository, SampleRepository>();
|
||||||
|
});
|
||||||
|
}
|
||||||
18
StandardConsole/Properties/launchSettings.json
Normal file
18
StandardConsole/Properties/launchSettings.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"StandardConsole": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "key1=val1 key2=val2",
|
||||||
|
"environmentVariables": {
|
||||||
|
"DOTNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ProductVersion": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "key1=val1 key2=val2",
|
||||||
|
"environmentVariables": {
|
||||||
|
"DOTNETCORE_ENVIRONMENT": "Production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
StandardConsole/Repositories/ISampleRepository.cs
Normal file
7
StandardConsole/Repositories/ISampleRepository.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace StandardConsole.Repositories
|
||||||
|
{
|
||||||
|
public interface ISampleRepository
|
||||||
|
{
|
||||||
|
void DoSomething();
|
||||||
|
}
|
||||||
|
}
|
||||||
28
StandardConsole/Repositories/SampleRepository.cs
Normal file
28
StandardConsole/Repositories/SampleRepository.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StandardConsole.Repositories;
|
||||||
|
|
||||||
|
public class SampleRepository : ISampleRepository
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ILogger<SampleRepository> _logger;
|
||||||
|
|
||||||
|
public void DoSomething()
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"{nameof(SampleRepository)}.Dosomething - just did something");
|
||||||
|
var connString = _configuration.GetConnectionString("DefaultConnection");
|
||||||
|
_logger.LogInformation($"The Connection string from Sample Repository: {connString}");
|
||||||
|
}
|
||||||
|
public SampleRepository(IConfiguration configuration, ILogger<SampleRepository> logger)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
StandardConsole/StandardConsole.csproj
Normal file
27
StandardConsole/StandardConsole.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.Production.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="appsettings.Development.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
29
StandardConsole/Worker.cs
Normal file
29
StandardConsole/Worker.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using StandardConsole.Repositories;
|
||||||
|
|
||||||
|
public class Worker
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ILogger<Worker> _logger;
|
||||||
|
private readonly ISampleRepository _sampleRepository;
|
||||||
|
|
||||||
|
public Worker(IConfiguration configuration, ILogger<Worker> logger, ISampleRepository sampleRepository)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
_sampleRepository = sampleRepository;
|
||||||
|
}
|
||||||
|
public void Run()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Hello, world!!!");
|
||||||
|
var connString = _configuration.GetConnectionString("DefaultConnection");
|
||||||
|
_logger.LogInformation($"Connection string: {connString}");
|
||||||
|
_logger.LogInformation($"key1: {_configuration["key1"]}");
|
||||||
|
_logger.LogInformation($"key2: {_configuration["key2"]}");
|
||||||
|
|
||||||
|
_sampleRepository.DoSomething();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
StandardConsole/appsettings.Development.json
Normal file
5
StandardConsole/appsettings.Development.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=Devserver;Database=DevDb;User Id==MeMyselfAndI;Password=SuperSecret"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
StandardConsole/appsettings.Production.json
Normal file
5
StandardConsole/appsettings.Production.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=Prodserver;Database=ProdDb;User Id==MeMyselfAndI;Password=SuperSecret"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
StandardConsole/appsettings.json
Normal file
5
StandardConsole/appsettings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server(local);Database=StdDb;User Id==MeMyselfAndI;Password=SuperSecret"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
StandardConsoleApp.sln
Normal file
25
StandardConsoleApp.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.33627.172
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StandardConsole", "StandardConsole\StandardConsole.csproj", "{8C92891D-C347-4A5C-AAE4-D50F705F00A4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {305DAD26-537A-41D7-9A94-9B4911FAF44A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user