I implemented this code, looking at a dependency injection program as an example. I wanted to confirm with you all whether this implementation is the right way of doing the same.
namespace TestAsyncProjectWithDI
{
public interface IReadFileTypes
{
void ReadUsingFileSteamAsync();
}
public class ReadfileFromSystem: IReadFileTypes
{
private readonly StreamReader _reader =null;
public ReadfileFromSystem(StreamReader reader)
{
_reader = reader;
}
public async void ReadUsingFileSteamAsync()
{
await Task.Run(()=> Console.WriteLine("Reading the content of File: {0}", _reader.ReadToEnd()));
Console.ReadLine();
}
}
public class Builder
{
public IReadFileTypes ReadFileTypes { get; set; }
private string path = "C:\\Brackets\\Projects\\index2.html";
public Builder()
{
ReadFileTypes = new ReadfileFromSystem(new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read)));
}
}
public class Program
{
private readonly IReadFileTypes _readFileTypes = null;
public Program(IReadFileTypes readFileTypes)
{
this._readFileTypes = readFileTypes;
}
public void FunctionInvoke()
{
_readFileTypes.ReadUsingFileSteamAsync();
}
}
//starting point of the class
public class Default
{
static void Main(string[] args)
{
var build = new Builder();
var obj = new Program(build.ReadFileTypes);
obj.FunctionInvoke();
Console.ReadLine();
}
}
}