Skip to content

Commit

Permalink
Refactored DI container to use modules for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeHahn committed Sep 15, 2013
1 parent e8dc92f commit c8d7469
Show file tree
Hide file tree
Showing 35 changed files with 140 additions and 194 deletions.
8 changes: 4 additions & 4 deletions HyperToken.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperToken_WinForms_GUI", "HyperToken_WinForms_GUI\HyperToken_WinForms_GUI.csproj", "{6E23681C-544E-44B7-81E1-9086F5BFF888}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperToken.WinFormsGUI", "HyperToken_WinForms_GUI\HyperToken.WinFormsGUI.csproj", "{6E23681C-544E-44B7-81E1-9086F5BFF888}"
ProjectSection(ProjectDependencies) = postProject
{18AE5954-CB94-41E2-942D-59BFE225ABC1} = {18AE5954-CB94-41E2-942D-59BFE225ABC1}
EndProjectSection
Expand Down Expand Up @@ -94,9 +94,9 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
BuildVersion_UseGlobalSettings = False
BuildVersion_UpdateFileVersion = False
BuildVersion_UpdateAssemblyVersion = False
BuildVersion_BuildVersioningStyle = None.None.None.None
BuildVersion_UpdateAssemblyVersion = False
BuildVersion_UpdateFileVersion = False
BuildVersion_UseGlobalSettings = False
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion HyperToken.sln.DotSettings
@@ -1,2 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Terminal_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Terminal_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/AboutBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/AboutBox.cs
Expand Up @@ -5,7 +5,7 @@
using Anotar.NLog;
using Terminal_Interface;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public partial class AboutBox : Form, IAboutBox
{
Expand Down
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/CurrentDeviceSerialStatusLabel.cs
Expand Up @@ -7,7 +7,7 @@
using Terminal_Interface;
using Menu = Terminal_GUI_Interface.Menu;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class CurrentDeviceSerialStatusLabel : IStatusbarExtension
{
Expand Down
5 changes: 2 additions & 3 deletions HyperToken_WinForms_GUI/FileSendGUI.cs
Expand Up @@ -7,12 +7,11 @@
using Terminal_Interface;
using Terminal_Interface.Enums;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class FileSendGUI : IFileSender, IToolbarExtension
public class FileSendGUI : IToolbarExtension
{
private ToolStripItem _toolBarItem;
public FileSendState FileSendState { get; set; }

public ToolStripItem ToolBarItem
{
Expand Down
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/Helpers/GetDescription.cs
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel;
using System.Reflection;

namespace HyperToken_WinForms_GUI.Helpers
namespace HyperToken.WinFormsGUI.Helpers
{
public static class EnumHelper
{
Expand Down
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{6E23681C-544E-44B7-81E1-9086F5BFF888}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HyperToken_WinForms_GUI</RootNamespace>
<AssemblyName>HyperToken_WinForms_GUI</AssemblyName>
<RootNamespace>HyperToken.WinFormsGUI</RootNamespace>
<AssemblyName>HyperToken.WinFormsGUI</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
Expand Down Expand Up @@ -55,7 +55,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand Down Expand Up @@ -112,11 +112,17 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Anotar.NLog">
<HintPath>..\packages\Anotar.NLog.Fody.2.3.0.0\Lib\portable-net4+sl4+wp7\Anotar.NLog.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Autofac">
<HintPath>..\packages\Autofac.3.1.1\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="MRG.Controls.UI, Version=1.0.39.1212, Culture=neutral, processorArchitecture=MSIL">
<HintPath>Binaries\MRG.Controls.UI.dll</HintPath>
Expand Down Expand Up @@ -176,6 +182,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerialStatusbarGUI.cs" />
<Compile Include="WinformsMainMenuExtender.cs" />
<Compile Include="WinFormsModule.cs" />
<EmbeddedResource Include="AboutBox.resx">
<DependentUpon>AboutBox.cs</DependentUpon>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -315,12 +322,11 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.MonthAndDayStamp" />
<UserProperties BuildVersion_BuildVersioningStyle="None.None.Increment.MonthAndDayStamp" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UseGlobalSettings="True" />
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PostBuildEvent>xcopy $(ProjectDir)bin\$(ConfigurationName) $(SolutionDir)Terminal\bin\$(ConfigurationName) /C /Y</PostBuildEvent>
</PropertyGroup>
<Import Project="Fody.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/Initializer.cs
Expand Up @@ -6,7 +6,7 @@
using NLog;
using Terminal_Interface;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class Initializer : IInitable
{
Expand Down
4 changes: 2 additions & 2 deletions HyperToken_WinForms_GUI/LoggingGui.cs
Expand Up @@ -6,14 +6,14 @@
using System.Windows.Forms;
using Anotar;
using Anotar.NLog;
using HyperToken_WinForms_GUI.Properties;
using HyperToken.WinFormsGUI.Properties;
using Terminal_GUI_Interface;
using Terminal_Interface;
using Terminal_Interface.Enums;
using Terminal_Interface.Exceptions;
using Menu = Terminal_GUI_Interface.Menu;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class LoggingGui : IMainMenuExtension, IStatusbarExtension
{
Expand Down
6 changes: 3 additions & 3 deletions HyperToken_WinForms_GUI/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions HyperToken_WinForms_GUI/MainForm.cs
Expand Up @@ -7,7 +7,7 @@
using System.Windows.Forms;
using Anotar.NLog;
using CustomControls;
using HyperToken_WinForms_GUI.Properties;
using HyperToken.WinFormsGUI.Properties;
using Terminal_GUI_Interface;
using Terminal_Interface;
using Terminal_Interface.Enums;
Expand All @@ -18,13 +18,12 @@
// TODO Add 'human readable version' for Rob
// TODO Custom Baud setting

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public partial class MainForm : Form, ITerminal, INotifyPropertyChanged
public partial class MainForm : Form, ITerminal
{
private readonly IAboutBox _aboutBox;
private readonly ILogger _logger;
private readonly IFileSender _fileSender;
private readonly CurrentDataDevice _currentDataDevice;
private readonly WinformsMainMenuExtender _mainMenuExtender;
private readonly IEnumerable<IStatusbarExtension> _statusbarExtensions;
Expand All @@ -36,15 +35,13 @@ public partial class MainForm : Form, ITerminal, INotifyPropertyChanged

public MainForm(IAboutBox aboutBox,
ILogger logger,
IFileSender fileSender,
CurrentDataDevice dataDevice,
WinformsMainMenuExtender mainMenuExtender,
IEnumerable<IStatusbarExtension> statusbarExtensions,
IEnumerable<IToolbarExtension> toolbarExtensions)
{
_aboutBox = aboutBox;
_logger = logger;
_fileSender = fileSender;
_mainMenuExtender = mainMenuExtender;
_statusbarExtensions = statusbarExtensions;
_toolbarExtensions = toolbarExtensions;
Expand Down
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/PacketParserGUI.cs
Expand Up @@ -9,7 +9,7 @@
using Terminal_Interface;
using NLog;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class PacketParserGUI : GenericSettingsMenu, IMainMenuExtension
{
Expand Down
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/PretendStatusbarButton.cs
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Windows.Forms;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
internal class PretendStatusbarButton : ToolStripStatusLabel
{
Expand Down
6 changes: 3 additions & 3 deletions HyperToken_WinForms_GUI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions HyperToken_WinForms_GUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/SerialStatusbarGUI.cs
Expand Up @@ -9,7 +9,7 @@
using Terminal_Interface;
using NLog;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
// TODO Refactor this to use Menu and move it into Terminal\GUI
public abstract class SerialStatusBarExtension : IStatusbarExtension
Expand Down
35 changes: 35 additions & 0 deletions HyperToken_WinForms_GUI/WinFormsModule.cs
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Terminal_GUI_Interface;
using Terminal_Interface;

namespace HyperToken.WinFormsGUI
{
public class WinFormsModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<Initializer>().As<IInitable>();
builder.RegisterType<MainForm>().As<ITerminal>();
builder.RegisterType<AboutBox>().As<IAboutBox>();

builder.RegisterType<WinformsMainMenuExtender>();

builder.RegisterType<LoggingGui>().As<IMainMenuExtension>().SingleInstance();
builder.RegisterType<LoggingGui>().As<IStatusbarExtension>().SingleInstance();
builder.RegisterType<PacketParserGUI>().As<IMainMenuExtension>().SingleInstance();
builder.RegisterType<FileSendGUI>().As<IToolbarExtension>().SingleInstance();

builder.RegisterType<SerialStatusbarPortMenu>().As<IStatusbarExtension>();
builder.RegisterType<SerialStatusbarStatusLabel>().As<IStatusbarExtension>();
builder.RegisterType<SerialStatusbarBaudMenu>().As<IStatusbarExtension>();

builder.RegisterType<SerialStatusbarPortMenu>();
builder.RegisterType<SerialStatusbarBaudMenu>();
builder.RegisterType<CurrentDeviceSerialStatusLabel>().As<IStatusbarExtension>();
}
}
}
2 changes: 1 addition & 1 deletion HyperToken_WinForms_GUI/WinformsMainMenuExtender.cs
Expand Up @@ -8,7 +8,7 @@
using Anotar;
using Menu = Terminal_GUI_Interface.Menu;

namespace HyperToken_WinForms_GUI
namespace HyperToken.WinFormsGUI
{
public class WinformsMainMenuExtender
{
Expand Down
1 change: 1 addition & 0 deletions HyperToken_WinForms_GUI/packages.config
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Anotar.NLog.Fody" version="2.3.0.0" targetFramework="net40" />
<package id="Autofac" version="3.1.1" targetFramework="net40" />
<package id="Fody" version="1.15.0.0" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="NLog.Config" version="2.0.0.2000" targetFramework="net40" />
Expand Down
6 changes: 3 additions & 3 deletions Hypertoken_Installer/Hypertoken_Installer.wixproj
Expand Up @@ -58,12 +58,12 @@
<RefProjectOutputGroups>Binaries;Symbols</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
<ProjectReference Include="..\HyperToken_WinForms_GUI\HyperToken_WinForms_GUI.csproj">
<Name>HyperToken_WinForms_GUI</Name>
<ProjectReference Include="..\HyperToken_WinForms_GUI\HyperToken.WinFormsGUI.csproj">
<Name>HyperToken.WinFormsGUI</Name>
<Project>{6e23681c-544e-44b7-81e1-9086f5bff888}</Project>
<Private>True</Private>
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Symbols</RefProjectOutputGroups>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
<ProjectReference Include="..\ITerminal\Terminal_Interface.csproj">
Expand Down
5 changes: 0 additions & 5 deletions ITerminal/IDataDevice.cs
Expand Up @@ -57,9 +57,4 @@ public interface IEchoer
{
EchoState EchoState { get; set; }
}

public interface IFileSender
{
FileSendState FileSendState { get; set; }
}
}

0 comments on commit c8d7469

Please sign in to comment.