-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathDbSource.cs
More file actions
57 lines (50 loc) · 1.69 KB
/
Copy pathDbSource.cs
File metadata and controls
57 lines (50 loc) · 1.69 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
using Microsoft.Extensions.Logging;
using SmartCode.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using SmartSql.Configuration;
using SmartSql.DataSource;
namespace SmartCode.Db
{
public class DbSource : IDataSource
{
public DbSource(
Project project
, ILoggerFactory loggerFactory
, IPluginManager pluginManager
)
{
Project = project;
LoggerFactory = loggerFactory;
PluginManager = pluginManager;
}
public bool Initialized { get; private set; }
public virtual string Name { get; private set; } = "Db";
public DbRepository DbRepository { get; protected set; }
public SmartSqlConfig SmartSqlConfig => DbRepository.SqlMapper.SmartSqlConfig;
public Database Database => SmartSqlConfig.Database;
public SmartSql.DataSource.DbProvider DbProvider => Database.DbProvider;
public WriteDataSource WriteDataSource => Database.Write;
public Project Project { get; }
public ILoggerFactory LoggerFactory { get; }
public IPluginManager PluginManager { get; }
public void Initialize(IDictionary<string, object> parameters)
{
if (parameters != null)
{
if (parameters.Value("Name", out string name))
{
Name = name;
}
}
this.Initialized = true;
}
public virtual Task InitData()
{
DbRepository = new DbRepository(Project.DataSource, LoggerFactory);
return Task.CompletedTask;
}
}
}