AutofacSamples4 implemented
This commit is contained in:
8
AutofacSample3/AutofacSamples4.csproj
Normal file
8
AutofacSample3/AutofacSamples4.csproj
Normal file
@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
53
AutofacSample3/Program.cs
Normal file
53
AutofacSample3/Program.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
|
||||
namespace AutofacSamples4
|
||||
{
|
||||
|
||||
public interface ILog
|
||||
{
|
||||
void Write(string message);
|
||||
}
|
||||
|
||||
public class ConsoleLog : ILog
|
||||
{
|
||||
public ConsoleLog()
|
||||
{
|
||||
Console.WriteLine($"Console log created at {DateTime.Now.Ticks}");
|
||||
}
|
||||
public void Write(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Console.WriteLine($"Console logger no longer required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SMSLog : ILog
|
||||
{
|
||||
private readonly string phoneNumber;
|
||||
|
||||
public SMSLog(string phoneNumber)
|
||||
{
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
public void Write(string message)
|
||||
{
|
||||
Console.WriteLine($"SMS to {phoneNumber} : {message}");
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user