Skip to content

Commit

Permalink
Refactored Project towards the Dependency Inversion Principle
Browse files Browse the repository at this point in the history
  • Loading branch information
zs40x committed Feb 14, 2016
1 parent a8b884e commit 3b5e721
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 20 deletions.
56 changes: 56 additions & 0 deletions Core/Core.csproj
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Core</RootNamespace>
<AssemblyName>Core</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<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="Interfaces\SendMail.cs" />
<Compile Include="Model\User.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\NotificationService.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
7 changes: 7 additions & 0 deletions Core/Interfaces/SendMail.cs
@@ -0,0 +1,7 @@
namespace Core.Interfaces
{
public interface SendMail
{
void sendMail(string recipient, string subject, string message);
}
}
@@ -1,7 +1,7 @@

namespace UserEMailNotificationSender.Model
namespace Core.Model
{
class User
public class User
{
public User() { }

Expand Down
36 changes: 36 additions & 0 deletions Core/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Core")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2b2221bd-375b-47e8-b7d0-1ab7a0d38262")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -1,11 +1,16 @@
using UserEMailNotificationSender.Infrastucture;
using UserEMailNotificationSender.Model;
using Core.Interfaces;
using Core.Model;

namespace UserEMailNotificationSender.BL
namespace Core.Services
{
class SMTPNotificationSender
public class NotificationService
{
SMTPClient smtpClient = new SMTPClient();
SendMail sendMail;

public NotificationService(SendMail _sendMail)
{
sendMail = _sendMail;
}

public void sendNotificationForUser(User userToNotify)
{
Expand All @@ -18,7 +23,7 @@ public void sendNotificationForUser(User userToNotify)
message += " -> Additional Information for Premium Users!";
}

smtpClient.sendMail(userToNotify.EMailAddress, "Notification", message);
sendMail.sendMail(userToNotify.EMailAddress, "Notification", message);
}
}
}
12 changes: 12 additions & 0 deletions DependencyInversionPrinciple.sln
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserEMailNotificationSender", "UserEMailNotificationSender\UserEMailNotificationSender.csproj", "{A599922A-A028-43B8-A845-7C73E83074C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{162EF39C-810F-4A46-A42D-21AE01023A00}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{A599922A-A028-43B8-A845-7C73E83074C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A599922A-A028-43B8-A845-7C73E83074C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A599922A-A028-43B8-A845-7C73E83074C0}.Release|Any CPU.Build.0 = Release|Any CPU
{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B2221BD-375B-47E8-B7D0-1AB7A0D38262}.Release|Any CPU.Build.0 = Release|Any CPU
{162EF39C-810F-4A46-A42D-21AE01023A00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{162EF39C-810F-4A46-A42D-21AE01023A00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{162EF39C-810F-4A46-A42D-21AE01023A00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{162EF39C-810F-4A46-A42D-21AE01023A00}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
60 changes: 60 additions & 0 deletions Infrastructure/Infrastructure.csproj
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{162EF39C-810F-4A46-A42D-21AE01023A00}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Infrastructure</RootNamespace>
<AssemblyName>Infrastructure</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<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="Properties\AssemblyInfo.cs" />
<Compile Include="Services\SMTPClient.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{2b2221bd-375b-47e8-b7d0-1ab7a0d38262}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions Infrastructure/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Infrastructure")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Infrastructure")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("162ef39c-810f-4a46-a42d-21ae01023a00")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -1,8 +1,9 @@
using System;
using Core.Interfaces;
using System;

namespace UserEMailNotificationSender.Infrastucture
namespace Infrastucture.Services
{
class SMTPClient
public class SMTPClient : SendMail
{
public void sendMail(string recipient, string subject, string message)
{
Expand Down
11 changes: 6 additions & 5 deletions UserEMailNotificationSender/Program.cs
@@ -1,16 +1,17 @@
using System;
using UserEMailNotificationSender.BL;
using UserEMailNotificationSender.Model;
using Core.Model;
using Core.Services;
using Infrastucture.Services;
using System;

namespace UserEMailNotificationSender
{
class Program
public class Program
{
static void Main(string[] args)
{
User aUser = new User("TheUser", "the_user@mail_service.com", false);

SMTPNotificationSender sender = new SMTPNotificationSender();
NotificationService sender = new NotificationService(new SMTPClient());
sender.sendNotificationForUser(aUser);


Expand Down
14 changes: 10 additions & 4 deletions UserEMailNotificationSender/UserEMailNotificationSender.csproj
Expand Up @@ -43,16 +43,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BL\SMTPNotificationSender.cs" />
<Compile Include="Infrastucture\SMTPClient.cs" />
<Compile Include="Model\User.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{2b2221bd-375b-47e8-b7d0-1ab7a0d38262}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj">
<Project>{162ef39c-810f-4a46-a42d-21ae01023a00}</Project>
<Name>Infrastructure</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 3b5e721

Please sign in to comment.