Skip to content

Commit cb5f752

Browse files
author
Jeff Treuting
committed
Added StructureMap initialization extension helpers
Now your SM initialization can look as simple as this: x.ForRepositoriesUseSharpRepository(); Or x.ForRepositoriesUseSharpRepository("inMemoryRepository); to pick out a specific named repository from the configuration file
1 parent eb91769 commit cb5f752

10 files changed

Lines changed: 4110 additions & 15 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpRepository.Ioc.StructureMap")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpRepository.Ioc.StructureMap")]
13+
[assembly: AssemblyCopyright("Copyright © 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("0b6bc72d-739c-4afb-8485-d9c5bb8d59d5")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SharpRepository.Ioc.StructureMap</RootNamespace>
11+
<AssemblyName>SharpRepository.Ioc.StructureMap</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="StructureMap">
34+
<HintPath>..\packages\structuremap.2.6.4.1\lib\net40\StructureMap.dll</HintPath>
35+
</Reference>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Compile Include="StructureMapExtensions.cs" />
41+
<Compile Include="Properties\AssemblyInfo.cs" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<None Include="packages.config" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
48+
<Project>{710dee79-25ce-4f68-b8b1-d08a135ad154}</Project>
49+
<Name>SharpRepository.Repository</Name>
50+
</ProjectReference>
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
54+
Other similar extension points exist, see Microsoft.Common.targets.
55+
<Target Name="BeforeBuild">
56+
</Target>
57+
<Target Name="AfterBuild">
58+
</Target>
59+
-->
60+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using SharpRepository.Repository;
2+
using SharpRepository.Repository.Configuration;
3+
using StructureMap;
4+
using StructureMap.Pipeline;
5+
6+
namespace SharpRepository.Ioc.StructureMap
7+
{
8+
public static class StructureMapExtensions
9+
{
10+
public static LambdaInstance<object> ForRepositoriesUseSharpRepository(this IInitializationExpression initialization, string repositoryName = null)
11+
{
12+
initialization.Scan(scan => scan.IncludeNamespaceContainingType<IAmInRepository>());
13+
14+
return initialization.For(typeof(IRepository<,>))
15+
.Use(context =>
16+
{
17+
var entityType = context.BuildStack.Current.RequestedType.GetGenericArguments()[0];
18+
var keyType = context.BuildStack.Current.RequestedType.GetGenericArguments()[1];
19+
20+
return RepositoryFactory.GetInstance(entityType, keyType, repositoryName);
21+
}
22+
);
23+
}
24+
25+
public static LambdaInstance<object> ForRepositoriesUseSharpRepository(this IInitializationExpression initialization, ISharpRepositoryConfiguration configuration)
26+
{
27+
initialization.Scan(scan => scan.IncludeNamespaceContainingType<IAmInRepository>());
28+
29+
return initialization.For(typeof(IRepository<,>))
30+
.Use(context =>
31+
{
32+
var entityType = context.BuildStack.Current.RequestedType.GetGenericArguments()[0];
33+
var keyType = context.BuildStack.Current.RequestedType.GetGenericArguments()[1];
34+
35+
return RepositoryFactory.GetInstance(entityType, keyType, configuration);
36+
}
37+
);
38+
}
39+
}
40+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="structuremap" version="2.6.4.1" targetFramework="net45" />
4+
</packages>

SharpRepository.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpRepository.Caching.Win
4444
EndProject
4545
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Caching Providers", "Caching Providers", "{FB7E3040-CA92-4B81-86E6-106E2FDD745E}"
4646
EndProject
47+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ioc", "Ioc", "{7D84196E-1183-46E8-944F-C43B0627B931}"
48+
EndProject
49+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpRepository.Ioc.StructureMap", "SharpRepository.Ioc.StructureMap\SharpRepository.Ioc.StructureMap.csproj", "{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}"
50+
EndProject
4751
Global
4852
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4953
Debug|Any CPU = Debug|Any CPU
@@ -106,6 +110,10 @@ Global
106110
{F025C038-9F9A-4730-9A03-3E3E6101E249}.Debug|Any CPU.Build.0 = Debug|Any CPU
107111
{F025C038-9F9A-4730-9A03-3E3E6101E249}.Release|Any CPU.ActiveCfg = Release|Any CPU
108112
{F025C038-9F9A-4730-9A03-3E3E6101E249}.Release|Any CPU.Build.0 = Release|Any CPU
113+
{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
114+
{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}.Debug|Any CPU.Build.0 = Debug|Any CPU
115+
{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}.Release|Any CPU.ActiveCfg = Release|Any CPU
116+
{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812}.Release|Any CPU.Build.0 = Release|Any CPU
109117
EndGlobalSection
110118
GlobalSection(SolutionProperties) = preSolution
111119
HideSolutionNode = FALSE
@@ -118,5 +126,6 @@ Global
118126
{1174F5B3-D3BE-453D-BD9F-D54EEFB0ADFE} = {FB7E3040-CA92-4B81-86E6-106E2FDD745E}
119127
{F025C038-9F9A-4730-9A03-3E3E6101E249} = {FB7E3040-CA92-4B81-86E6-106E2FDD745E}
120128
{06111314-669B-4E35-A0B9-AF67FA3F0FFD} = {FB7E3040-CA92-4B81-86E6-106E2FDD745E}
129+
{0B4BDC6D-6030-48FD-B22A-F9A9A7A00812} = {7D84196E-1183-46E8-944F-C43B0627B931}
121130
EndGlobalSection
122131
EndGlobal

packages/repositories.config

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<repositories>
3-
<repository path="..\SharpRepository.Caching.AppFabric\packages.config" />
4-
<repository path="..\SharpRepository.Caching.Memcached\packages.config" />
5-
<repository path="..\SharpRepository.Caching.Redis\packages.config" />
6-
<repository path="..\SharpRepository.Caching.WindowsAzure\packages.config" />
7-
<repository path="..\SharpRepository.Db4oRepository\packages.config" />
8-
<repository path="..\SharpRepository.Ef5Repository\packages.config" />
9-
<repository path="..\SharpRepository.EfRepository\packages.config" />
10-
<repository path="..\SharpRepository.MongoDbRepository\packages.config" />
11-
<repository path="..\SharpRepository.RavenDbRepository\packages.config" />
12-
<repository path="..\SharpRepository.Repository\packages.config" />
13-
<repository path="..\SharpRepository.Samples\packages.config" />
14-
<repository path="..\SharpRepository.Tests.Integration\packages.config" />
15-
<repository path="..\SharpRepository.Tests\packages.config" />
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<repositories>
3+
<repository path="..\SharpRepository.Caching.AppFabric\packages.config" />
4+
<repository path="..\SharpRepository.Caching.Memcached\packages.config" />
5+
<repository path="..\SharpRepository.Caching.Redis\packages.config" />
6+
<repository path="..\SharpRepository.Caching.WindowsAzure\packages.config" />
7+
<repository path="..\SharpRepository.Db4oRepository\packages.config" />
8+
<repository path="..\SharpRepository.Ef5Repository\packages.config" />
9+
<repository path="..\SharpRepository.EfRepository\packages.config" />
10+
<repository path="..\SharpRepository.Ioc.StructureMap\packages.config" />
11+
<repository path="..\SharpRepository.MongoDbRepository\packages.config" />
12+
<repository path="..\SharpRepository.RavenDbRepository\packages.config" />
13+
<repository path="..\SharpRepository.Repository\packages.config" />
14+
<repository path="..\SharpRepository.Samples\packages.config" />
15+
<repository path="..\SharpRepository.Tests.Integration\packages.config" />
16+
<repository path="..\SharpRepository.Tests\packages.config" />
1617
</repositories>

0 commit comments

Comments
 (0)