Skip to content

Commit e058231

Browse files
author
Jeff Treuting
committed
Added cofig and factory classes to non NuGet projects as well
1 parent 2620356 commit e058231

16 files changed

Lines changed: 342 additions & 129 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Configuration;
3+
using SharpRepository.Repository;
4+
using SharpRepository.Repository.Configuration;
5+
6+
namespace SharpRepository.Db4oRepository
7+
{
8+
public class Db4oConfigRepositoryFactory : ConfigRepositoryFactory
9+
{
10+
public Db4oConfigRepositoryFactory(IRepositoryConfiguration config)
11+
: base(config)
12+
{
13+
}
14+
15+
public override IRepository<T, TKey> GetInstance<T, TKey>()
16+
{
17+
// check for required parameters
18+
if (String.IsNullOrEmpty(RepositoryConfiguration["directory"]))
19+
{
20+
throw new ConfigurationErrorsException("The directory attribute is required in order to use the Db4oRepository via the configuration file.");
21+
}
22+
23+
return new Db4oRepository<T, TKey>(RepositoryConfiguration["directory"]);
24+
}
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using SharpRepository.Repository.Configuration;
2+
3+
namespace SharpRepository.Db4oRepository
4+
{
5+
public class Db4oRepositoryConfiguration : RepositoryConfiguration
6+
{
7+
public Db4oRepositoryConfiguration(string name, string directory)
8+
: base(name)
9+
{
10+
Directory = directory;
11+
Factory = typeof(Db4oConfigRepositoryFactory);
12+
}
13+
14+
public string Directory
15+
{
16+
set { Attributes["directory"] = value; }
17+
}
18+
}
19+
}
Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,71 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{12DD3830-5A12-484C-98B4-D30811DEC8A9}</ProjectGuid>
9-
<OutputType>Library</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>SharpRepository.Db4oRepository</RootNamespace>
12-
<AssemblyName>SharpRepository.Db4oRepository</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<FileAlignment>512</FileAlignment>
15-
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<DebugSymbols>true</DebugSymbols>
18-
<DebugType>full</DebugType>
19-
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
22-
<ErrorReport>prompt</ErrorReport>
23-
<WarningLevel>4</WarningLevel>
24-
</PropertyGroup>
25-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<DebugType>pdbonly</DebugType>
27-
<Optimize>true</Optimize>
28-
<OutputPath>bin\Release\</OutputPath>
29-
<DefineConstants>TRACE</DefineConstants>
30-
<ErrorReport>prompt</ErrorReport>
31-
<WarningLevel>4</WarningLevel>
32-
</PropertyGroup>
33-
<ItemGroup>
34-
<Reference Include="Db4objects.Db4o">
35-
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.dll</HintPath>
36-
</Reference>
37-
<Reference Include="Db4objects.Db4o.Linq">
38-
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Linq.dll</HintPath>
39-
</Reference>
40-
<Reference Include="System" />
41-
<Reference Include="System.Core" />
42-
</ItemGroup>
43-
<ItemGroup>
44-
<Compile Include="..\CommonAssembly.cs">
45-
<Link>Properties\CommonAssembly.cs</Link>
46-
</Compile>
47-
<Compile Include="Properties\AssemblyInfo.cs" />
48-
<Compile Include="Db4ORepository.cs" />
49-
<Compile Include="Db4ORepositoryBase.cs" />
50-
</ItemGroup>
51-
<ItemGroup>
52-
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
53-
<Project>{710DEE79-25CE-4F68-B8B1-D08A135AD154}</Project>
54-
<Name>SharpRepository.Repository</Name>
55-
</ProjectReference>
56-
</ItemGroup>
57-
<ItemGroup>
58-
<None Include="packages.config" />
59-
</ItemGroup>
60-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
61-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
62-
Other similar extension points exist, see Microsoft.Common.targets.
63-
<Target Name="BeforeBuild">
64-
</Target>
65-
<Target Name="AfterBuild">
66-
</Target>
67-
-->
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{12DD3830-5A12-484C-98B4-D30811DEC8A9}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>SharpRepository.Db4oRepository</RootNamespace>
12+
<AssemblyName>SharpRepository.Db4oRepository</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="Db4objects.Db4o">
35+
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.dll</HintPath>
36+
</Reference>
37+
<Reference Include="Db4objects.Db4o.Linq">
38+
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Linq.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.configuration" />
42+
<Reference Include="System.Core" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="..\CommonAssembly.cs">
46+
<Link>Properties\CommonAssembly.cs</Link>
47+
</Compile>
48+
<Compile Include="Db4oConfigRepositoryFactory.cs" />
49+
<Compile Include="Db4oRepositoryConfiguration.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
<Compile Include="Db4ORepository.cs" />
52+
<Compile Include="Db4ORepositoryBase.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
56+
<Project>{710DEE79-25CE-4F68-B8B1-D08A135AD154}</Project>
57+
<Name>SharpRepository.Repository</Name>
58+
</ProjectReference>
59+
</ItemGroup>
60+
<ItemGroup>
61+
<None Include="packages.config" />
62+
</ItemGroup>
63+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
64+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
65+
Other similar extension points exist, see Microsoft.Common.targets.
66+
<Target Name="BeforeBuild">
67+
</Target>
68+
<Target Name="AfterBuild">
69+
</Target>
70+
-->
6871
</Project>

SharpRepository.Ef5Repository/Ef5RepositoryConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public Ef5RepositoryConfiguration(string name, string connectionStringOrName)
1515
}
1616

1717
public Ef5RepositoryConfiguration(string name, string connectionStringOrName, Type dbContextType, string cachingStrategy=null, string cachingProvider=null)
18+
: base(name)
1819
{
19-
Name = name;
2020
ConnectionStringOrName = connectionStringOrName;
2121
DbContextType = dbContextType;
2222
CachingStrategy = cachingStrategy;

SharpRepository.EfRepository/EfRepositoryConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public EfRepositoryConfiguration(string name, string connectionStringOrName)
1515
}
1616

1717
public EfRepositoryConfiguration(string name, string connectionStringOrName, Type dbContextType, string cachingStrategy=null, string cachingProvider=null)
18+
: base(name)
1819
{
19-
Name = name;
2020
ConnectionStringOrName = connectionStringOrName;
2121
DbContextType = dbContextType;
2222
CachingStrategy = cachingStrategy;

SharpRepository.InMemoryRepository/InMemoryRepositoryConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace SharpRepository.InMemoryRepository
55
public class InMemoryRepositoryConfiguration : RepositoryConfiguration
66
{
77
public InMemoryRepositoryConfiguration(string name, string cachingStrategy=null, string cachingProvider=null)
8+
: base(name)
89
{
9-
Name = name;
1010
CachingStrategy = cachingStrategy;
1111
CachingProvider = cachingProvider;
1212
Factory = typeof(InMemoryConfigRepositoryFactory);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Linq;
5+
using System.Text;
6+
using SharpRepository.Repository;
7+
using SharpRepository.Repository.Configuration;
8+
9+
namespace SharpRepository.MongoDbRepository
10+
{
11+
public class MongoDbConfigRepositoryFactory : ConfigRepositoryFactory
12+
{
13+
public MongoDbConfigRepositoryFactory(IRepositoryConfiguration config)
14+
: base(config)
15+
{
16+
}
17+
18+
public override IRepository<T, TKey> GetInstance<T, TKey>()
19+
{
20+
// check for required parameters
21+
if (String.IsNullOrEmpty(RepositoryConfiguration["connectionString"]))
22+
{
23+
throw new ConfigurationErrorsException("The connectionString attribute is required in order to use the MongoDbRepository via the configuration file.");
24+
}
25+
26+
return new MongoDbRepository<T, TKey>(RepositoryConfiguration["connectionString"]);
27+
}
28+
}
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using SharpRepository.Repository.Configuration;
2+
3+
namespace SharpRepository.MongoDbRepository
4+
{
5+
public class MongoDbRepositoryConfiguration : RepositoryConfiguration
6+
{
7+
public MongoDbRepositoryConfiguration(string name, string connectionString)
8+
: base(name)
9+
{
10+
ConnectionString = connectionString;
11+
}
12+
13+
public string ConnectionString
14+
{
15+
set { Attributes["connectionString"] = value; }
16+
}
17+
}
18+
}

SharpRepository.MongoDbRepository/SharpRepository.MongoDbRepository.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<Compile Include="..\CommonAssembly.cs">
4949
<Link>CommonAssembly.cs</Link>
5050
</Compile>
51+
<Compile Include="MongoDbConfigRepositoryFactory.cs" />
52+
<Compile Include="MongoDbRepositoryConfiguration.cs" />
5153
<Compile Include="MongoDbRepositoryManager.cs" />
5254
<Compile Include="Properties\AssemblyInfo.cs" />
5355
<Compile Include="MongoDbRepository.cs" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Raven.Client.Document;
3+
using SharpRepository.Repository;
4+
using SharpRepository.Repository.Configuration;
5+
6+
namespace SharpRepository.RavenDbRepository
7+
{
8+
public class RavenDbConfigRepositoryFactory : ConfigRepositoryFactory
9+
{
10+
public RavenDbConfigRepositoryFactory(IRepositoryConfiguration config)
11+
: base(config)
12+
{
13+
}
14+
15+
public override IRepository<T, TKey> GetInstance<T, TKey>()
16+
{
17+
var documentStore =new DocumentStore();
18+
19+
if (!String.IsNullOrEmpty(RepositoryConfiguration["connectionStringName"]))
20+
{
21+
documentStore.ConnectionStringName = RepositoryConfiguration["connectionStringName"];
22+
}
23+
else if (!String.IsNullOrEmpty(RepositoryConfiguration["url"]))
24+
{
25+
documentStore.Url = RepositoryConfiguration["url"];
26+
}
27+
28+
return new RavenDbRepository<T, TKey>(documentStore);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)