Skip to content

Commit b699eaa

Browse files
committed
Added sample which uses the appsettings.json based configuration.
1 parent a48b0b1 commit b699eaa

File tree

22 files changed

+414
-105
lines changed

22 files changed

+414
-105
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace WebAppPluginsLibrary
4+
{
5+
public class CustomPlugin
6+
{
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Weikio.PluginFramework.Abstractions;
7+
using Weikio.PluginFramework.AspNetCore;
8+
using Weikio.PluginFramework.Samples.Shared;
9+
10+
namespace WebAppWithAppSettings.Controllers
11+
{
12+
[ApiController]
13+
[Route("[controller]")]
14+
public class CalculatorController : ControllerBase
15+
{
16+
private readonly IEnumerable<Plugin> _plugins;
17+
private readonly IServiceProvider _serviceProvider;
18+
private readonly PluginProvider _pluginProvider;
19+
20+
public CalculatorController(IEnumerable<Plugin> plugins, IServiceProvider serviceProvider, PluginProvider pluginProvider)
21+
{
22+
_plugins = plugins;
23+
_serviceProvider = serviceProvider;
24+
_pluginProvider = pluginProvider;
25+
}
26+
27+
[HttpGet]
28+
public string Get()
29+
{
30+
var result = new StringBuilder();
31+
32+
result.AppendLine("All:");
33+
foreach (var plugin in _plugins)
34+
{
35+
result.AppendLine($"{plugin.Name}: {plugin.Version}, Tags: {string.Join(", ", plugin.Tags)}");
36+
}
37+
38+
var mathPlugins = _pluginProvider.GetByTag("MathOperator");
39+
var value1 = 10;
40+
var value2 = 20;
41+
42+
result.AppendLine($"Math operations with values {value1} and {value2}");
43+
44+
foreach (var mathPlugin in mathPlugins)
45+
{
46+
var mathPluginInstance = _serviceProvider.Create<IOperator>(mathPlugin);
47+
48+
var mathResult = mathPluginInstance.Calculate(value1, value2);
49+
result.AppendLine($"{mathPlugin.Name}: {mathResult}");
50+
}
51+
52+
return result.ToString();
53+
}
54+
}
55+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace WebAppWithAppSettings
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"WebAppWithAppSettings": {
5+
"commandName": "Project",
6+
"launchBrowser": true,
7+
"launchUrl": "Calculator",
8+
"environmentVariables": {
9+
"ASPNETCORE_ENVIRONMENT": "Development"
10+
},
11+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
12+
}
13+
}
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Hosting;
5+
using Weikio.PluginFramework.Samples.Shared;
6+
using Weikio.PluginFramework.TypeFinding;
7+
8+
namespace WebAppWithAppSettings
9+
{
10+
public class Startup
11+
{
12+
public void ConfigureServices(IServiceCollection services)
13+
{
14+
TypeFinderOptions.Defaults.TypeFinderCriterias.Add(TypeFinderCriteriaBuilder.Create().Implements<IOperator>().Tag("MathOperator"));
15+
TypeFinderOptions.Defaults.TypeFinderCriterias.Add(TypeFinderCriteriaBuilder.Create().Tag("All"));
16+
services.AddPluginFramework();
17+
18+
services.AddControllers();
19+
}
20+
21+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
22+
{
23+
if (env.IsDevelopment())
24+
{
25+
app.UseDeveloperExceptionPage();
26+
}
27+
28+
app.UseHttpsRedirection();
29+
30+
app.UseRouting();
31+
32+
app.UseAuthorization();
33+
34+
app.UseEndpoints(endpoints =>
35+
{
36+
endpoints.MapControllers();
37+
});
38+
}
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Weikio.PluginFramework.AspNetCore\Weikio.PluginFramework.AspNetCore.csproj" />
9+
<ProjectReference Include="..\Shared\Weikio.PluginFramework.Samples.SharedPlugins\Weikio.PluginFramework.Samples.SharedPlugins.csproj" />
10+
<ProjectReference Include="..\Shared\Weikio.PluginFramework.Samples.Shared\Weikio.PluginFramework.Samples.Shared.csproj" />
11+
<ProjectReference Include="..\WebAppPluginsLibrary\WebAppPluginsLibrary.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Content Update="Properties\launchSettings.json">
16+
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
17+
</Content>
18+
</ItemGroup>
19+
20+
21+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"PluginFramework": {
3+
"Catalogs": [
4+
{
5+
"Type": "Folder",
6+
"Path": "..\\Shared\\Weikio.PluginFramework.Samples.SharedPlugins\\bin\\debug\\netcoreapp3.1"
7+
},
8+
{
9+
"Type": "Assembly",
10+
"Path": ".\\bin\\Debug\\netcoreapp3.1\\WebAppPluginsLibrary.dll"
11+
}
12+
]
13+
}
14+
}

src/PluginFramework.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsPluginsLibrary", ".
6363
EndProject
6464
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Weikio.PluginFramework.Configuration", "Weikio.PluginFramework.Configuration\Weikio.PluginFramework.Configuration.csproj", "{882BB58E-D256-4BBF-8C5F-80C4FA39B775}"
6565
EndProject
66+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAppWithAppSettings", "..\samples\WebAppWithAppSettings\WebAppWithAppSettings.csproj", "{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE}"
67+
EndProject
68+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAppPluginsLibrary", "..\samples\WebAppPluginsLibrary\WebAppPluginsLibrary.csproj", "{38CCE0F7-F998-4766-A14A-44C047E8D0AA}"
69+
EndProject
6670
Global
6771
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6872
Debug|Any CPU = Debug|Any CPU
@@ -173,6 +177,14 @@ Global
173177
{882BB58E-D256-4BBF-8C5F-80C4FA39B775}.Debug|Any CPU.Build.0 = Debug|Any CPU
174178
{882BB58E-D256-4BBF-8C5F-80C4FA39B775}.Release|Any CPU.ActiveCfg = Release|Any CPU
175179
{882BB58E-D256-4BBF-8C5F-80C4FA39B775}.Release|Any CPU.Build.0 = Release|Any CPU
180+
{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
181+
{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE}.Debug|Any CPU.Build.0 = Debug|Any CPU
182+
{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE}.Release|Any CPU.ActiveCfg = Release|Any CPU
183+
{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE}.Release|Any CPU.Build.0 = Release|Any CPU
184+
{38CCE0F7-F998-4766-A14A-44C047E8D0AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
185+
{38CCE0F7-F998-4766-A14A-44C047E8D0AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
186+
{38CCE0F7-F998-4766-A14A-44C047E8D0AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
187+
{38CCE0F7-F998-4766-A14A-44C047E8D0AA}.Release|Any CPU.Build.0 = Release|Any CPU
176188
EndGlobalSection
177189
GlobalSection(SolutionProperties) = preSolution
178190
HideSolutionNode = FALSE
@@ -200,6 +212,8 @@ Global
200212
{A7EC9D91-CED0-43E7-BAB3-3B72230BFC0B} = {FF3A507D-D242-44F6-8940-49E0B51B6F02}
201213
{6D392453-FC9E-45AD-A9A7-7596A93B3E6C} = {FF3A507D-D242-44F6-8940-49E0B51B6F02}
202214
{E92B0C5D-FFAC-4AB9-B069-869AEED565B0} = {FF3A507D-D242-44F6-8940-49E0B51B6F02}
215+
{A5FAE1A5-74A0-4A83-9520-DCABF6610ADE} = {FF3A507D-D242-44F6-8940-49E0B51B6F02}
216+
{38CCE0F7-F998-4766-A14A-44C047E8D0AA} = {FF3A507D-D242-44F6-8940-49E0B51B6F02}
203217
EndGlobalSection
204218
GlobalSection(ExtensibilityGlobals) = postSolution
205219
SolutionGuid = {AAEBC2B4-FB52-4272-8C25-571FB3CA01E5}

0 commit comments

Comments
 (0)