forked from SharpRepository/SharpRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEfCoreRepositoryConfiguration.cs
More file actions
85 lines (71 loc) · 3.24 KB
/
Copy pathEfCoreRepositoryConfiguration.cs
File metadata and controls
85 lines (71 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.EntityFrameworkCore;
using SharpRepository.Repository;
using SharpRepository.Repository.Configuration;
using System;
namespace SharpRepository.EfCoreRepository
{
public class EfCoreRepositoryConfiguration : RepositoryConfiguration
{
protected DbContext DbContext { get; set; }
public EfCoreRepositoryConfiguration(string name)
: this(name, null, null)
{
}
public EfCoreRepositoryConfiguration(string name, DbContext dbContext)
: this(name, null, null)
{
DbContext = dbContext;
}
public EfCoreRepositoryConfiguration(string name, string cachingStrategy = null, string cachingProvider = null)
: base(name)
{
CachingStrategy = cachingStrategy;
CachingProvider = cachingProvider;
Factory = typeof(EfCoreConfigRepositoryFactory);
}
public EfCoreRepositoryConfiguration(string name, DbContext dbContext, string cachingStrategy = null, string cachingProvider = null)
: base(name)
{
CachingStrategy = cachingStrategy;
CachingProvider = cachingProvider;
DbContext = dbContext;
Factory = typeof(EfCoreConfigRepositoryFactory);
}
public string ConnectionStringOrName
{
set { Attributes["connectionString"] = value; }
}
public override IRepository<T> GetInstance<T>()
{
// load up the factory if it exists and use it
var factory = DbContext != null ?
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this, DbContext) :
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this);
return factory.GetInstance<T>();
}
public override IRepository<T, TKey> GetInstance<T, TKey>()
{
// load up the factory if it exists and use it
var factory = DbContext != null ?
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this, DbContext) :
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this);
return factory.GetInstance<T, TKey>();
}
public override ICompoundKeyRepository<T, TKey, TKey2> GetInstance<T, TKey, TKey2>()
{
// load up the factory if it exists and use it
var factory = DbContext != null ?
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this, DbContext) :
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this);
return factory.GetInstance<T, TKey, TKey2>();
}
public override ICompoundKeyRepository<T, TKey, TKey2, TKey3> GetInstance<T, TKey, TKey2, TKey3>()
{
// load up the factory if it exists and use it
var factory = DbContext != null ?
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this, DbContext) :
(IConfigRepositoryFactory)Activator.CreateInstance(Factory, this);
return factory.GetInstance<T, TKey, TKey2, TKey3>();
}
}
}