Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tibi committed Aug 14, 2023
0 parents commit d07c548
Show file tree
Hide file tree
Showing 16 changed files with 882 additions and 0 deletions.
477 changes: 477 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions After/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
internal class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string EmailAddress { get; set; }
public string MobileNo { get; set; }
public string Address { get; set; }
}
}
18 changes: 18 additions & 0 deletions After/EmailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
internal class EmailService: IMessageService
{
public string EmailAddress { get; set; }

public void Send()
{
Console.WriteLine($"E-mail is sent to {EmailAddress}");
}
}
}
13 changes: 13 additions & 0 deletions After/IMessageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
internal interface IMessageService
{
void Send();
}
}
26 changes: 26 additions & 0 deletions After/NotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
class NotificationService
{
public readonly List<IMessageService> _services;

public NotificationService(List<IMessageService> services)
{
_services = services;
}

public void Notify()
{
foreach (var service in _services)
{
service.Send();
}
}
}
}
41 changes: 41 additions & 0 deletions After/Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
internal static class Repository
{
public static List<Customer> Customers =>
new List<Customer>()
{
new Customer
{
Id = 1,
Name = "John Doe",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 123-4567",
Address = "123 2nd Avenue California, USA"
},
new Customer
{
Id = 2,
Name = "Sarah MC",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 124-4567",
Address = "345 4th Avenue Florida, USA"
},
new Customer
{
Id = 3,
Name = "Steve Pado",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 123-4567",
Address = "678 3rd Avenue Chicago, USA"
}
};

}
}
18 changes: 18 additions & 0 deletions After/SMSService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.After
{
internal class SMSService: IMessageService
{
public string MobileNo { get; set; }

public void Send()
{
Console.WriteLine($"SMS is sent to {MobileNo}");
}
}
}
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
17 changes: 17 additions & 0 deletions Before/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.Before
{
internal class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string EmailAddress { get; set; }
public string MobileNo { get; set; }
public string Address { get; set; }
}
}
18 changes: 18 additions & 0 deletions Before/EmailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.Before
{
internal class EmailService
{
public string EmailAddress { get; set; }

public void Send()
{
Console.WriteLine($"E-mail is sent to {EmailAddress}");
}
}
}
34 changes: 34 additions & 0 deletions Before/NotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.Before
{
class NotificationService
{
private readonly Customer customer;
private readonly EmailService emailService;
private readonly SMSService smsService;

public NotificationService(Customer customer)
{
emailService = new EmailService
{
EmailAddress = customer.EmailAddress
};

smsService = new SMSService
{
MobileNo = customer.MobileNo
};
}

public void Notify()
{
emailService.Send();
smsService.Send();
}
}
}
41 changes: 41 additions & 0 deletions Before/Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.Before
{
internal static class Repository
{
public static List<Customer> Customers =>
new List<Customer>()
{
new Customer
{
Id = 1,
Name = "John Doe",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 123-4567",
Address = "123 2nd Avenue California, USA"
},
new Customer
{
Id = 2,
Name = "Sarah MC",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 124-4567",
Address = "345 4th Avenue Florida, USA"
},
new Customer
{
Id = 3,
Name = "Steve Pado",
EmailAddress = "[email protected]",
MobileNo = "+1 (606) 123-4567",
Address = "678 3rd Avenue Chicago, USA"
}
};

}
}
18 changes: 18 additions & 0 deletions Before/SMSService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion.Before
{
internal class SMSService
{
public string MobileNo { get; set; }

public void Send()
{
Console.WriteLine($"SMS is sent to {MobileNo}");
}
}
}
65 changes: 65 additions & 0 deletions DependencyInversion.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CFEE2B3E-E75C-4E4F-8922-18E3E38CDA0E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>DependencyInversion</RootNamespace>
<AssemblyName>DependencyInversion</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="After\Customer.cs" />
<Compile Include="After\EmailService.cs" />
<Compile Include="After\IMessageService.cs" />
<Compile Include="After\NotificationService.cs" />
<Compile Include="After\Repository.cs" />
<Compile Include="After\SMSService.cs" />
<Compile Include="Before\Customer.cs" />
<Compile Include="Before\EmailService.cs" />
<Compile Include="Before\NotificationService.cs" />
<Compile Include="Before\Repository.cs" />
<Compile Include="Before\SMSService.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
37 changes: 37 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInversion
{
class Program
{
static void Main(string[] args)
{
//var customers = Before.Repository.Customers;
//foreach (var customer in customers)
//{
// var notificationService = new Before.NotificationService(customer);
// notificationService.Notify();
//}

var customers = After.Repository.Customers;
foreach (var customer in customers)
{
var messageService = new List<After.IMessageService>
{
new After.SMSService { MobileNo = customer.MobileNo},
new After.EmailService { EmailAddress = customer.EmailAddress}
};

var notificationService = new After.NotificationService(messageService);
notificationService.Notify();

}

Console.ReadKey();
}
}
}
Loading

0 comments on commit d07c548

Please sign in to comment.