main
Yik Teng Hie 3 years ago
commit 467e2c689f

4
.gitignore vendored

@ -0,0 +1,4 @@
.vs/
bin/
obj/
packages/

@ -0,0 +1,40 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Util", "Util\Util.csproj", "{A847BA71-AFF1-48AF-AEA5-99F131882E09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEFDemo", "MEFDemo\MEFDemo.csproj", "{86A1EB30-75C4-4AC9-9955-0F6033013B73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proxy", "Proxy\Proxy.csproj", "{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEFDemo.unittest", "MEFDemo.unittest\MEFDemo.unittest.csproj", "{6FD344AD-8D18-4431-B095-273A130BE7BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A847BA71-AFF1-48AF-AEA5-99F131882E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A847BA71-AFF1-48AF-AEA5-99F131882E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A847BA71-AFF1-48AF-AEA5-99F131882E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A847BA71-AFF1-48AF-AEA5-99F131882E09}.Release|Any CPU.Build.0 = Release|Any CPU
{86A1EB30-75C4-4AC9-9955-0F6033013B73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86A1EB30-75C4-4AC9-9955-0F6033013B73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86A1EB30-75C4-4AC9-9955-0F6033013B73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86A1EB30-75C4-4AC9-9955-0F6033013B73}.Release|Any CPU.Build.0 = Release|Any CPU
{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}.Release|Any CPU.Build.0 = Release|Any CPU
{6FD344AD-8D18-4431-B095-273A130BE7BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FD344AD-8D18-4431-B095-273A130BE7BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FD344AD-8D18-4431-B095-273A130BE7BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FD344AD-8D18-4431-B095-273A130BE7BD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6FD344AD-8D18-4431-B095-273A130BE7BD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MEFDemo.unittest</RootNamespace>
<AssemblyName>MEFDemo.unittest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</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="Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="MEFDemoProxyIntegrationTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MEFDemo\MEFDemo.csproj">
<Project>{86a1eb30-75c4-4ac9-9955-0f6033013b73}</Project>
<Name>MEFDemo</Name>
</ProjectReference>
<ProjectReference Include="..\Proxy\Proxy.csproj">
<Project>{ff9b1521-799c-4e56-8d9c-25fbf9bf2abe}</Project>
<Name>Proxy</Name>
</ProjectReference>
<ProjectReference Include="..\Util\Util.csproj">
<Project>{a847ba71-aff1-48af-aea5-99f131882e09}</Project>
<Name>Util</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<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>

@ -0,0 +1,59 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Proxy;
using Rhino.Mocks;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using Util;
namespace MEFDemo.unittest
{
[TestClass]
public class MEFDemoProxyIntegrationTest
{
private CompositionContainer CreateIsolatedContainer(INetwork fakeNetwork = null)
{
if (fakeNetwork == null) fakeNetwork = MockRepository.GenerateMock<INetwork>();
//slower, but more robust:
//var catalog = new AggregateCatalog();
//var assemblyDirectory = ".";
//catalog.Catalogs.Add(new DirectoryCatalog(assemblyDirectory));
var catalog = new TypeCatalog(typeof(INetwork), typeof(MachineChecker));
var container = new CompositionContainer(catalog);
container.ComposeExportedValue<INetwork>(fakeNetwork);
return container;
}
[TestMethod]
public void Isolate_from_Network()
{
var fakeNetwork = MockRepository.GenerateMock<INetwork>();
var container = CreateIsolatedContainer(fakeNetwork);
Program.Run(container);
fakeNetwork.AssertWasCalled(x => x.IsLocalMachine(Arg<string>.Is.Anything));
}
[TestMethod]
public void OnLocalMachine_Run_returns_Local()
{
var fakseLocalMachineNetwork = MockRepository.GenerateMock<INetwork>();
fakseLocalMachineNetwork.Stub(x => x.IsLocalMachine(Arg<string>.Is.Anything)).Return(true);
var container = CreateIsolatedContainer(fakseLocalMachineNetwork);
var result = Program.Run(container);
Assert.IsTrue(result.ToLower().Contains("local"));
}
[TestMethod]
public void OnUnknownMachine_Run_returns_Foreign()
{
var container = CreateIsolatedContainer();
var result = Program.Run(container);
Assert.IsTrue(result.ToLower().Contains("foreign"));
}
}
}

@ -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("MEFDemo.unittest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MEFDemo.unittest")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("c91a3836-e553-4fd8-af4a-5784110633f4")]
// 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")]

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RhinoMocks" version="3.6.1" targetFramework="net40" />
</packages>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Comment CommentText="MEFDemo.exe">
<Position X="0.5" Y="0.51" Height="0.406" Width="1.523" />
</Comment>
<Comment CommentText="Proxy.dll">
<Position X="2.74" Y="0.51" Height="0.406" Width="1.523" />
</Comment>
<Comment CommentText="Util.dll">
<Position X="5" Y="0.5" Height="0.406" Width="1.523" />
</Comment>
<Class Name="MEFDemo.Program">
<Position X="0.5" Y="1" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAI=</HashCode>
<FileName>Program.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Util.Network" Collapsed="true">
<Position X="5" Y="2.5" Width="1.5" />
<TypeIdentifier />
<Lollipop Position="0.2" />
</Class>
<Class Name="Proxy.MachineChecker">
<Position X="2.75" Y="1" Width="1.5" />
<Members>
<Method Name="MachineChecker" Hidden="true" />
<Property Name="Network" Hidden="true" />
</Members>
<TypeIdentifier />
</Class>
<Interface Name="Util.INetwork">
<Position X="5" Y="1" Width="1.5" />
<TypeIdentifier />
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>{86A1EB30-75C4-4AC9-9955-0F6033013B73}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MEFDemo</RootNamespace>
<AssemblyName>MEFDemo</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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.ComponentModel.Composition" />
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Proxy\Proxy.csproj">
<Project>{ff9b1521-799c-4e56-8d9c-25fbf9bf2abe}</Project>
<Name>Proxy</Name>
</ProjectReference>
<ProjectReference Include="..\Util\Util.csproj">
<Project>{a847ba71-aff1-48af-aea5-99f131882e09}</Project>
<Name>Util</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram1.cd" />
</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>

@ -0,0 +1,39 @@
using Proxy;
using System;
using System.ComponentModel.Composition.Hosting;
using System.Diagnostics;
using Util;
namespace MEFDemo
{
public class Program
{
public static void Main(string[] args)
{
var stopwatch = Stopwatch.StartNew();
var catalog = new AggregateCatalog();
var assemblyDirectory = ".";
catalog.Catalogs.Add(new DirectoryCatalog(assemblyDirectory));
var container = new CompositionContainer(catalog);
Console.WriteLine("Setup : {0}", stopwatch.Elapsed);
Run(container);
Console.ReadLine();
}
public static string Run(CompositionContainer container)
{
var stopwatch = Stopwatch.StartNew();
var machineChecker = container.GetExport<MachineChecker>();
Console.WriteLine("Export: {0}", stopwatch.Elapsed);
stopwatch.Restart();
var check = machineChecker.Value.Check("localhost");
Console.WriteLine("{0,8}{1}", check, stopwatch.Elapsed);
stopwatch.Stop();
return check;
}
}
}

@ -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("MEFDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MEFDemo")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("8695dd48-e914-4bca-aefd-fd15f7e08904")]
// 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")]

@ -0,0 +1,29 @@
using System.ComponentModel.Composition;
using Util;
namespace Proxy
{
[Export]
public class MachineChecker
{
public INetwork Network { get; set; }
[ImportingConstructor]
public MachineChecker(INetwork network)
{
Network = network;
}
public string Check(string machine)
{
if (Network.IsLocalMachine(machine))
{
return string.Format("Local : ");
}
else
{
return string.Format("Foreign:");
}
}
}
}

@ -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("Proxy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Proxy")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("ead96a3a-6e77-4096-ba8b-e2c108ab67a2")]
// 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")]

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>{FF9B1521-799C-4E56-8D9C-25FBF9BF2ABE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Proxy</RootNamespace>
<AssemblyName>Proxy</AssemblyName>
<TargetFrameworkVersion>v4.0</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.ComponentModel.Composition" />
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MachineChecker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Util\Util.csproj">
<Project>{a847ba71-aff1-48af-aea5-99f131882e09}</Project>
<Name>Util</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>

@ -0,0 +1,5 @@
# MEF Demo
- Microsofts solution for dependency injection is called **Managed Extensibility Framework** (MEF)
- [Reference]https://erictummers.com/2015/06/15/first-look-at-managed-extensibility-framework-mef/
- Simple Console to demo MEF pattern

@ -0,0 +1,28 @@
using System;
using System.ComponentModel.Composition;
namespace Util
{
public interface INetwork
{
bool IsLocalMachine(string machine);
}
[Export(typeof(INetwork))]
public class Network : INetwork
{
public bool IsLocalMachine(string machine)
{
try
{
var localMachine = System.Net.Dns.GetHostName();
var entry = System.Net.Dns.GetHostEntry(machine);
return entry.HostName.Equals(localMachine);
}
catch (Exception)
{
return false;
}
}
}
}

@ -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("Util")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Util")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("1050533b-51ef-40c1-8929-ebc4eedf84d1")]
// 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")]

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>{A847BA71-AFF1-48AF-AEA5-99F131882E09}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Util</RootNamespace>
<AssemblyName>Util</AssemblyName>
<TargetFrameworkVersion>v4.0</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.ComponentModel.Composition" />
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Network.cs" />
<Compile Include="Properties\AssemblyInfo.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>
Loading…
Cancel
Save