-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d07c548
Showing
16 changed files
with
882 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.