convert to use service

This commit is contained in:
2023-01-05 10:32:21 -05:00
parent 596065b7c8
commit 2caa82b8f4
5 changed files with 51 additions and 19 deletions

View File

@ -0,0 +1,28 @@
namespace BinaryDad.Notes.Services
{
public class FileNoteService : INoteService
{
private readonly string? filePath;
public FileNoteService(IConfiguration configuration)
{
filePath = configuration["ContentFilePath"];
// ensure initialized
if (!File.Exists(filePath))
{
File.WriteAllText(filePath, "Hi! Feel free to start typing. Everything will be saved soon after you are done typing.");
}
}
public string Get()
{
return File.ReadAllText(filePath);
}
public void Save(string content)
{
File.WriteAllText(filePath, content);
}
}
}

8
Services/INoteService.cs Normal file
View File

@ -0,0 +1,8 @@
namespace BinaryDad.Notes.Services
{
public interface INoteService
{
string Get();
void Save(string content);
}
}