Commit cd4f0f00 authored by Robert Rudman's avatar Robert Rudman

Add credentials file, get dependency injection and configuration setup.

parent e7b90a4e
......@@ -331,4 +331,5 @@ ASALocalRun/
.mfractor/
# Local History for Visual Studio
.localhistory/
\ No newline at end of file
.localhistory/
/StackExchangeChat.Console/appsettings.dev.json
namespace StackExchangeChat.Console
using System.IO;
using System.Net.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StackExchangeChat.Console.AppSettings;
namespace StackExchangeChat.Console
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
var serviceCollection = new ServiceCollection();
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true)
.AddJsonFile("appsettings.dev.json", true);
IConfiguration config = builder.Build();
var credentials = new Credentials();
config.Bind("ChatCredentials", credentials);
serviceCollection.AddTransient<HttpClient>();
serviceCollection.AddSingleton(_ => config);
serviceCollection.AddSingleton(_ => credentials);
var serviceProvider = serviceCollection.BuildServiceProvider();
var chatClient = new ChatClient(serviceProvider);
}
}
}
......@@ -5,4 +5,25 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0-preview3-35497" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchangeChat\StackExchangeChat.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
{
"ChatCredentials": {
"UserName": "",
"Password": ""
}
}
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>
\ No newline at end of file
......@@ -2,7 +2,13 @@
namespace StackExchangeChat
{
public class Class1
public class ChatClient
{
private readonly IServiceProvider _serviceProvider;
public ChatClient(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
}
}
namespace StackExchangeChat.Console.AppSettings
{
public class Credentials
{
public string Username { get; set; }
public string Password { get; set; }
}
}
......@@ -4,4 +4,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0-preview3-35497" />
</ItemGroup>
</Project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment