Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
7 changes: 6 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="SimpleResults.AspNetCore" Version="1.0.0" />
<PackageVersion Include="DotEnv.Core" Version="3.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.10.0" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageVersion Include="NUnit.Analyzers" Version="3.5.0" />
<PackageVersion Include="coverlet.msbuild" Version="3.1.2" />
</ItemGroup>
</Project>
</Project>
74 changes: 74 additions & 0 deletions samples/CPlugin.Net.Examples.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CPlugin.Net.Attributes", "..\src\Attributes\CPlugin.Net.Attributes.csproj", "{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CPlugin.Net", "..\src\Core\CPlugin.Net.csproj", "{116B353F-FC68-4412-8A2D-34DA0BE88060}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{BBDE7F3C-2A41-40B6-B609-839D09676D0E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "HostApplications\ConsoleApp\ConsoleApp.csproj", "{3E943746-09CD-430E-9BBF-67DBBF9F5CEF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "HostApplications\WebApi\WebApi.csproj", "{C221B4F0-857F-4380-B5AD-E4B2BBA65622}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonPlugin", "Plugins\JsonPlugin\JsonPlugin.csproj", "{C5B8EF73-7DB5-441F-AE38-0988751A896B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OldJsonPlugin", "Plugins\OldJsonPlugin\OldJsonPlugin.csproj", "{1ADE3B86-00EF-4976-8B67-09B360B149FA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppointmentPlugin", "Plugins\AppointmentPlugin\AppointmentPlugin.csproj", "{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DA150C23-F1A9-42CF-899C-6C4E6B940E72}"
ProjectSection(SolutionItems) = preProject
..\Directory.Build.props = ..\Directory.Build.props
Plugins\Directory.Build.props = Plugins\Directory.Build.props
..\Directory.Packages.props = ..\Directory.Packages.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9737294-F5EA-4EA0-8BF2-2BF5C3954DD9}.Release|Any CPU.Build.0 = Release|Any CPU
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBDE7F3C-2A41-40B6-B609-839D09676D0E}.Release|Any CPU.Build.0 = Release|Any CPU
{3E943746-09CD-430E-9BBF-67DBBF9F5CEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E943746-09CD-430E-9BBF-67DBBF9F5CEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E943746-09CD-430E-9BBF-67DBBF9F5CEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E943746-09CD-430E-9BBF-67DBBF9F5CEF}.Release|Any CPU.Build.0 = Release|Any CPU
{C221B4F0-857F-4380-B5AD-E4B2BBA65622}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C221B4F0-857F-4380-B5AD-E4B2BBA65622}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C221B4F0-857F-4380-B5AD-E4B2BBA65622}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C221B4F0-857F-4380-B5AD-E4B2BBA65622}.Release|Any CPU.Build.0 = Release|Any CPU
{C5B8EF73-7DB5-441F-AE38-0988751A896B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5B8EF73-7DB5-441F-AE38-0988751A896B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5B8EF73-7DB5-441F-AE38-0988751A896B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5B8EF73-7DB5-441F-AE38-0988751A896B}.Release|Any CPU.Build.0 = Release|Any CPU
{1ADE3B86-00EF-4976-8B67-09B360B149FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ADE3B86-00EF-4976-8B67-09B360B149FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ADE3B86-00EF-4976-8B67-09B360B149FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ADE3B86-00EF-4976-8B67-09B360B149FA}.Release|Any CPU.Build.0 = Release|Any CPU
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2832E5C3-660E-49B9-8E62-03B11A8CC6D7}.Release|Any CPU.Build.0 = Release|Any CPU
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Debug|Any CPU.Build.0 = Debug|Any CPU
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.ActiveCfg = Release|Any CPU
{116B353F-FC68-4412-8A2D-34DA0BE88060}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67EE578E-EE0A-4E98-AE5A-1771751D8B5F}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions samples/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions samples/Contracts/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts;

public interface ICommand
{
string Name { get; }
string Description { get; }
int Execute();
}
10 changes: 10 additions & 0 deletions samples/Contracts/IWebStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Extensions.DependencyInjection;

namespace Contracts;

public interface IWebStartup
{
string Name { get; }
string Description { get; }
void ConfigureServices(IServiceCollection services);
}
1 change: 1 addition & 0 deletions samples/HostApplications/ConsoleApp/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLUGINS=OldJsonPlugin.dll JsonPlugin.dll
16 changes: 16 additions & 0 deletions samples/HostApplications/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotEnv.Core" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Core\CPlugin.Net.csproj" />
<ProjectReference Include="..\..\Contracts\Contracts.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions samples/HostApplications/ConsoleApp/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using Contracts;
global using CPlugin.Net;
global using DotEnv.Core;
13 changes: 13 additions & 0 deletions samples/HostApplications/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://aka.ms/new-console-template for more information
new EnvLoader().Load();
Console.WriteLine("PLUGINS=" + EnvReader.Instance["PLUGINS"]);
Console.WriteLine();

var envConfiguration = new CPluginEnvConfiguration();
PluginLoader.SetConfiguration(envConfiguration);
// Loads the plugins from the .env file.
var contracts = PluginLoader.Load<ICommand>();
foreach(ICommand contract in contracts)
{
contract.Execute();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace WebApi.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public ListedResult<WeatherForecast> Get()
{
var data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
return Result.Success(data);
}
}
6 changes: 6 additions & 0 deletions samples/HostApplications/WebApi/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global using System.Reflection;
global using Contracts;
global using CPlugin.Net;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.ApplicationParts;
global using SimpleResults;
42 changes: 42 additions & 0 deletions samples/HostApplications/WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

var jsonConfiguration = new CPluginJsonConfiguration(builder.Configuration);
PluginLoader.SetConfiguration(jsonConfiguration);
// Loads the plugins from the appsettings.json file.
var contracts = PluginLoader.Load<IWebStartup>();
foreach(IWebStartup contract in contracts)
{
contract.ConfigureServices(builder.Services);
}

IMvcBuilder mvcBuilder = builder.Services.AddControllers();
foreach (Assembly assembly in PluginLoader.Assemblies)
{
// This allows to register the controllers for each loaded assembly.
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(assembly));
}

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseRequestLocalization("en");

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions samples/HostApplications/WebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57919",
"sslPort": 44392
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5158",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7049;http://localhost:5158",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
12 changes: 12 additions & 0 deletions samples/HostApplications/WebApi/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace WebApi;

public class WeatherForecast
{
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
18 changes: 18 additions & 0 deletions samples/HostApplications/WebApi/WebApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="SimpleResults.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Core\CPlugin.Net.csproj" />
<ProjectReference Include="..\..\Contracts\Contracts.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions samples/HostApplications/WebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
12 changes: 12 additions & 0 deletions samples/HostApplications/WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Plugins": [
"AppointmentPlugin.dll"
]
}
9 changes: 9 additions & 0 deletions samples/Plugins/AppointmentPlugin/Appointment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AppointmentPlugin;

public class Appointment
{
public string Id { get; init; }
public string DoctorName { get; init; }
public string PatientName { get; init; }
public DateOnly Date { get; init; }
}
18 changes: 18 additions & 0 deletions samples/Plugins/AppointmentPlugin/AppointmentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace AppointmentPlugin;

[TranslateResultToActionResult]
[ApiController]
[Route("[controller]")]
public class AppointmentController : ControllerBase
{
private readonly AppointmentService _appointmentService;
public AppointmentController(AppointmentService appointmentService) => _appointmentService = appointmentService;

[HttpGet]
public ListedResult<Appointment> Get()
=> _appointmentService.GetAll();

[HttpGet("{id}")]
public Result<Appointment> Get(string id)
=> _appointmentService.GetById(id);
}
14 changes: 14 additions & 0 deletions samples/Plugins/AppointmentPlugin/AppointmentPlugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutDir>$(SolutionDir)HostApplications/WebApi/bin/$(Configuration)/$(TargetFramework)/plugins/$(MSBuildProjectName)</OutDir>
<OutputType>Library</OutputType>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SimpleResults.AspNetCore" Version="2.2.1" />
</ItemGroup>

</Project>
Loading