Skip to content

Commit 432a4ba

Browse files
committed
1. remove unnecessary dependency libs
2. add DefaultSmartCodeAppBuilder
1 parent 6c7ee22 commit 432a4ba

File tree

7 files changed

+50
-41
lines changed

7 files changed

+50
-41
lines changed

src/SmartCode.App/SmartCode.App.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
10-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
11-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.1" />
12-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
13-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
14-
<PackageReference Include="RazorLight" Version="2.0.0-beta1" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
1511
</ItemGroup>
1612
<ItemGroup>
1713
<ProjectReference Include="..\SmartCode\SmartCode.csproj" />

src/SmartCode.App/SmartCodeApp.cs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
1-
using Microsoft.Extensions.Configuration;
2-
using System;
3-
using System.Collections.Generic;
1+
using System;
42
using Microsoft.Extensions.DependencyInjection;
53
using Microsoft.Extensions.Logging;
64
using System.Threading.Tasks;
75
using SmartCode.Configuration;
86
using System.IO;
97
using SmartCode.Configuration.ConfigBuilders;
108
using System.Reflection;
11-
using System.Linq;
129

1310
namespace SmartCode.App
1411
{
1512
public class SmartCodeApp
1613
{
17-
const string APP_SETTINGS_PATH = "appsettings.json";
18-
const string SMARTCODE_KEY = "SmartCode";
19-
public IConfigurationRoot Configuration { get; private set; }
20-
public SmartCodeOptions SmartCodeOptions { get; private set; }
14+
public SmartCodeOptions SmartCodeOptions { get; }
2115
public String AppDirectory { get { return AppDomain.CurrentDomain.BaseDirectory; } }
2216
public IConfigBuilder ConfigBuilder { get; private set; }
23-
public IServiceCollection Services { get; private set; }
17+
public IServiceCollection Services { get { return SmartCodeOptions.Services; } }
2418
public IServiceProvider ServiceProvider { get; private set; }
2519
public Project Project { get; private set; }
26-
public string ConfigPath { get; }
20+
public string ConfigPath { get { return SmartCodeOptions.ConfigPath; } }
2721
public ILogger<SmartCodeApp> Logger { get; private set; }
28-
public SmartCodeApp(String configPath)
22+
public SmartCodeApp(SmartCodeOptions smartCodeOptions)
2923
{
30-
ConfigPath = configPath;
24+
SmartCodeOptions = smartCodeOptions;
3125
BuildProject();
32-
InitConfig();
3326
RegisterServices();
3427
}
3528

@@ -55,25 +48,11 @@ private void BuildProject()
5548
}
5649
Project = ConfigBuilder.Build();
5750
}
58-
private void InitConfig()
59-
{
60-
var appSettingsbuilder = new ConfigurationBuilder()
61-
.SetBasePath(AppDirectory)
62-
.AddJsonFile(APP_SETTINGS_PATH, false, true);
63-
Configuration = appSettingsbuilder.Build();
64-
SmartCodeOptions = Configuration.GetSection(SMARTCODE_KEY).Get<SmartCodeOptions>();
65-
}
6651

6752
private void RegisterServices()
6853
{
69-
Services = new ServiceCollection();
7054
Services.AddSingleton<SmartCodeOptions>(SmartCodeOptions);
7155
Services.AddSingleton<Project>(Project);
72-
Services.AddLogging((loggerBuilder) =>
73-
{
74-
var loggingConfig = Configuration.GetSection("Logging");
75-
loggerBuilder.AddConfiguration(loggingConfig).AddConsole();
76-
});
7756
RegisterPlugins();
7857
Services.AddSingleton<IPluginManager, PluginManager>();
7958
Services.AddSingleton<IProjectBuilder, ProjectBuilder>();
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
using System;
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45

56
namespace SmartCode.App
67
{
78
public class SmartCodeOptions
89
{
9-
public string Name { get; set; } = "SmartCode";
10-
public string Author { get; set; } = "Ahoo Wang";
10+
public string Name { get; } = "SmartCode";
11+
public string Author { get; } = "Ahoo Wang";
1112
public string Version { get; set; } = "1.0.0";
12-
public string Github { get; set; } = "https://github.com/Ahoo-Wang/SmartCode";
13+
public string Github { get; } = "https://github.com/Ahoo-Wang/SmartCode";
14+
public String ConfigPath { get; set; }
15+
public IServiceCollection Services { get; set; } = new ServiceCollection();
1316
public IEnumerable<PluginConfig> Plugins { get; set; }
1417
}
1518
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Logging;
4+
using SmartCode.App;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace SmartCode.CLI
10+
{
11+
public class DefaultSmartCodeAppBuilder
12+
{
13+
const string APP_SETTINGS_PATH = "appsettings.json";
14+
const string SMARTCODE_KEY = "SmartCode";
15+
public String AppDirectory { get { return AppDomain.CurrentDomain.BaseDirectory; } }
16+
17+
public SmartCodeApp Build(string configPath)
18+
{
19+
var appSettingsbuilder = new ConfigurationBuilder()
20+
.SetBasePath(AppDirectory)
21+
.AddJsonFile(APP_SETTINGS_PATH, false, true);
22+
var configuration = appSettingsbuilder.Build();
23+
var smartCodeOptions = configuration.GetSection(SMARTCODE_KEY).Get<SmartCodeOptions>();
24+
smartCodeOptions.ConfigPath = configPath;
25+
smartCodeOptions.Services.AddLogging((loggerBuilder) =>
26+
{
27+
var loggingConfig = configuration.GetSection("Logging");
28+
loggerBuilder.AddConfiguration(loggingConfig).AddConsole();
29+
});
30+
return new SmartCodeApp(smartCodeOptions);
31+
}
32+
}
33+
}

src/SmartCode.CLI/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static async Task Main(string[] args)
3636
configPath = DEFAULT_CONFIG_PATH;
3737
}
3838
}
39-
SmartCodeApp app = new SmartCodeApp(configPath);
39+
SmartCodeApp app = new DefaultSmartCodeAppBuilder().Build(configPath);
4040
await app.Run();
4141
Console.ReadLine();
4242
}

src/SmartCode.CLI/SmartCode.CLI.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<RepositoryType>Github</RepositoryType>
2121
<PackageTags>SmartCode SmartSql</PackageTags>
2222
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
23-
<Version>1.3.4</Version>
23+
<Version>1.3.6</Version>
2424
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartCode/master/doc/Logo.png</PackageIconUrl>
2525
</PropertyGroup>
2626

@@ -31,12 +31,10 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
3534
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
3635
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.1" />
3736
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
3837
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
39-
<PackageReference Include="RazorLight" Version="2.0.0-beta1" />
4038
</ItemGroup>
4139

4240
<ItemGroup>

src/SmartCode.Db/SmartCode.Db.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="MySql.Data" Version="8.0.12" />
1212
<PackageReference Include="Npgsql" Version="4.0.3" />
1313
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.3" />
14-
<PackageReference Include="SmartSql" Version="3.7.9" />
14+
<PackageReference Include="SmartSql" Version="3.7.10" />
1515
<PackageReference Include="SmartSql.Options" Version="1.4.0" />
1616
</ItemGroup>
1717

0 commit comments

Comments
 (0)