DI Example

This commit is contained in:
Luke Malpass
2018-06-13 07:29:08 +01:00
parent 9178d853d6
commit c97c685af9
13 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DependencyExample.Core\DependencyExample.Core.csproj" />
<ProjectReference Include="..\DependencyExample.FileManager\DependencyExample.FileManager.csproj" />
<ProjectReference Include="..\DependencyExample.Logger\DependencyExample.Logger.csproj" />
<ProjectReference Include="..\DependencyExample.MemoryFileManager\DependencyExample.MockFileManager.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,34 @@
using System;
namespace DependencyExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// Inject specific services
DependencyProvider.FileManager = new MockFileManager { FailOnPurpose = true };
DependencyProvider.Logger = new Logger();
// Write some file, and read it back
var data = "this is my test";
var path = @"C:\Users\Luke\Desktop\test.txt";
// Log
DependencyProvider.Logger.LogMessage($"Writing `{data}` to `{path}`");
// Write
DependencyProvider.FileManager.WriteFileData(path, data);
// Read back
var readBack = DependencyProvider.FileManager.GetFileData(path);
// Log
DependencyProvider.Logger.LogMessage($"Read back `{readBack}`");
Console.Read();
}
}
}