Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Simple Injector integration package added. #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Snap.SimpleInjector/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("Snap.SimpleInjector")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Snap.SimpleInjector")]
[assembly: AssemblyCopyright("Copyright © Tyler Brinks 2014")]
[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("0b56faaa-6910-4d62-812e-cd30814ceff7")]

// 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.7.*")]
[assembly: AssemblyFileVersion("1.7.*")]
11 changes: 11 additions & 0 deletions Snap.SimpleInjector/SampleSimpleInjectorAopConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snap.SimpleInjector
{
class SampleSimpleInjectorAopConfig
{
}
}
90 changes: 90 additions & 0 deletions Snap.SimpleInjector/SimpleInjectorAspectContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
Snap v1.0

Copyright (c) 2010 Tyler Brinks

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using System;
using System.Linq.Expressions;
using Castle.DynamicProxy;
using CommonServiceLocator.SimpleInjectorAdapter;
using SimpleInjector;

namespace Snap.SimpleInjector
{
/// <summary>
/// Simple Injector Aspect Container for AoP interception registration.
/// </summary>
public class SimpleInjectorAspectContainer : AspectContainer
{
private readonly ProxyFactory _proxyFactory = new ProxyFactory(new ProxyGenerator());

private readonly Func<object, object> _createProxy;

/// <summary>
/// Initializes a new instance of the <see cref="AutofacAspectContainer"/> class.
/// </summary>
/// <param name="container">The builder.</param>
public SimpleInjectorAspectContainer(Container container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}

Proxy = new MasterProxy();
Container = container;

Proxy = new MasterProxy { Container = new SimpleInjectorServiceLocatorAdapter(container) };

_createProxy = instanceToProxy => _proxyFactory.CreateProxy(instanceToProxy, Proxy);

container.ExpressionBuilding += Intercept;
}

void Intercept(object sender, ExpressionBuildingEventArgs e)
{
if (AspectUtility.IsDecorated(e.KnownImplementationType, Proxy.Configuration))
{
e.Expression = Expression.Convert(
Expression.Invoke(Expression.Constant(_createProxy), e.Expression),
e.RegisteredServiceType);
}
}

/// <summary>
/// Gets or sets the container builder.
/// </summary>
/// <value>The builder.</value>
public Container Container { get; private set; }

/// <summary>
/// Sets the aspect configuration.
/// </summary>
/// <param name="config">The config.</param>
public override void SetConfiguration(AspectConfiguration config)
{
Proxy.Configuration = config;
Container.RegisterSingle<MasterProxy>((MasterProxy)Proxy);
config.Container = this;
}
}
}
148 changes: 148 additions & 0 deletions Snap.SimpleInjector/Snap.SimpleInjector.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8ADE2FD7-93B9-4936-8B7B-34DB14443C9A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Snap.SimpleInjector</RootNamespace>
<AssemblyName>Snap.SimpleInjector</AssemblyName>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<BuildPackage>false</BuildPackage>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'NET40-Debug|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\NET40-Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;DOTNET40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'NET40-Release|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\NET40-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NET35-Debug|AnyCPU'">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\NET35-Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;DOTNET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NET35-Release|AnyCPU'">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\NET35-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<FrameworkPackageDir Condition="'$(TargetFrameworkVersion)' == 'v4.0'">NET40</FrameworkPackageDir>
<FrameworkPackageDir Condition="'$(TargetFrameworkVersion)' == 'v3.5'">NET35</FrameworkPackageDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NET45-Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\NET45-Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;DOTNET40</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NET45-Release|AnyCPU'">
<OutputPath>bin\NET45-Release\</OutputPath>
<DefineConstants>TRACE;DOTNET40</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core">
<HintPath>..\packages\Castle.Core.3.2.2\lib\net40-client\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="CommonServiceLocator.SimpleInjectorAdapter">
<HintPath>..\packages\CommonServiceLocator.SimpleInjectorAdapter.2.6.1\lib\portable-net4+sl4+wp8+win8+wpa81\CommonServiceLocator.SimpleInjectorAdapter.dll</HintPath>
</Reference>
<Reference Include="Fasterflect">
<HintPath>..\packages\fasterflect.2.1.3\lib\net40\Fasterflect.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Portable.CommonServiceLocator.1.2.2\lib\net35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector">
<HintPath>..\packages\SimpleInjector.2.6.1\lib\net40-client\SimpleInjector.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector.Diagnostics">
<HintPath>..\packages\SimpleInjector.2.6.1\lib\net40-client\SimpleInjector.Diagnostics.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SampleSimpleInjectorAopConfig.cs" />
<Compile Include="SimpleInjectorAspectContainer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Snap\Snap.csproj">
<Project>{C1B09D15-F861-48F4-8DA3-FEC0E03CA0FC}</Project>
<Name>Snap</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.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>
9 changes: 9 additions & 0 deletions Snap.SimpleInjector/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.2.2" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" />
<package id="CommonServiceLocator.SimpleInjectorAdapter" version="2.6.1" targetFramework="net40" />
<package id="fasterflect" version="2.1.3" targetFramework="net40" />
<package id="Portable.CommonServiceLocator" version="1.2.2" targetFramework="net40" />
<package id="SimpleInjector" version="2.6.1" targetFramework="net40" />
</packages>
Loading