From cc0c2f123f1733bca58c5aa5ebc20ec208c30db3 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:27:01 -0500 Subject: [PATCH 1/9] chore: Update Directory.Build.props --- Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Build.props b/Directory.Build.props index 16477fa..a670ccb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,7 @@ net7.0 + latest enable disable True From 93c491fbbc271fc08b57b6d6ad26111113d9290c Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:28:09 -0500 Subject: [PATCH 2/9] chore: Add new NuGet packages --- Directory.Packages.props | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 1d3e922..263eda4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,6 +5,11 @@ + + + + + @@ -12,4 +17,4 @@ - + \ No newline at end of file From 272ae91f699ba270442dfffa87eb46330d700364 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:29:16 -0500 Subject: [PATCH 3/9] chore: Create solution file for the samples --- samples/CPlugin.Net.Examples.sln | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 samples/CPlugin.Net.Examples.sln diff --git a/samples/CPlugin.Net.Examples.sln b/samples/CPlugin.Net.Examples.sln new file mode 100644 index 0000000..4f011d6 --- /dev/null +++ b/samples/CPlugin.Net.Examples.sln @@ -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 From 90aac684353491928d5eee936d2d4b1e31e4ecc1 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:33:37 -0500 Subject: [PATCH 4/9] chore: Add global settings for all plugins --- samples/Plugins/Directory.Build.props | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 samples/Plugins/Directory.Build.props diff --git a/samples/Plugins/Directory.Build.props b/samples/Plugins/Directory.Build.props new file mode 100644 index 0000000..9977cf6 --- /dev/null +++ b/samples/Plugins/Directory.Build.props @@ -0,0 +1,32 @@ + + + + + + + true + + + + + false + + runtime + + + + false + + runtime + + + \ No newline at end of file From 2984e5df8fb5b0ab3f5a1be8731be5264471d0aa Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:37:32 -0500 Subject: [PATCH 5/9] docs: Add sample plugins --- .../Plugins/AppointmentPlugin/Appointment.cs | 9 +++++ .../AppointmentController.cs | 18 +++++++++ .../AppointmentPlugin.csproj | 14 +++++++ .../AppointmentPlugin/AppointmentService.cs | 22 ++++++++++ .../Plugins/AppointmentPlugin/GlobalUsings.cs | 5 +++ samples/Plugins/AppointmentPlugin/Startup.cs | 40 +++++++++++++++++++ samples/Plugins/JsonPlugin/CreateJson.cs | 33 +++++++++++++++ samples/Plugins/JsonPlugin/GlobalUsings.cs | 5 +++ samples/Plugins/JsonPlugin/JsonPlugin.csproj | 12 ++++++ samples/Plugins/OldJsonPlugin/CreateJson.cs | 31 ++++++++++++++ samples/Plugins/OldJsonPlugin/GlobalUsings.cs | 5 +++ .../OldJsonPlugin/OldJsonPlugin.csproj | 12 ++++++ 12 files changed, 206 insertions(+) create mode 100644 samples/Plugins/AppointmentPlugin/Appointment.cs create mode 100644 samples/Plugins/AppointmentPlugin/AppointmentController.cs create mode 100644 samples/Plugins/AppointmentPlugin/AppointmentPlugin.csproj create mode 100644 samples/Plugins/AppointmentPlugin/AppointmentService.cs create mode 100644 samples/Plugins/AppointmentPlugin/GlobalUsings.cs create mode 100644 samples/Plugins/AppointmentPlugin/Startup.cs create mode 100644 samples/Plugins/JsonPlugin/CreateJson.cs create mode 100644 samples/Plugins/JsonPlugin/GlobalUsings.cs create mode 100644 samples/Plugins/JsonPlugin/JsonPlugin.csproj create mode 100644 samples/Plugins/OldJsonPlugin/CreateJson.cs create mode 100644 samples/Plugins/OldJsonPlugin/GlobalUsings.cs create mode 100644 samples/Plugins/OldJsonPlugin/OldJsonPlugin.csproj diff --git a/samples/Plugins/AppointmentPlugin/Appointment.cs b/samples/Plugins/AppointmentPlugin/Appointment.cs new file mode 100644 index 0000000..62abf63 --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/Appointment.cs @@ -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; } +} diff --git a/samples/Plugins/AppointmentPlugin/AppointmentController.cs b/samples/Plugins/AppointmentPlugin/AppointmentController.cs new file mode 100644 index 0000000..f29b50b --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/AppointmentController.cs @@ -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 Get() + => _appointmentService.GetAll(); + + [HttpGet("{id}")] + public Result Get(string id) + => _appointmentService.GetById(id); +} diff --git a/samples/Plugins/AppointmentPlugin/AppointmentPlugin.csproj b/samples/Plugins/AppointmentPlugin/AppointmentPlugin.csproj new file mode 100644 index 0000000..79344fa --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/AppointmentPlugin.csproj @@ -0,0 +1,14 @@ + + + + $(SolutionDir)HostApplications/WebApi/bin/$(Configuration)/$(TargetFramework)/plugins/$(MSBuildProjectName) + Library + true + false + + + + + + + diff --git a/samples/Plugins/AppointmentPlugin/AppointmentService.cs b/samples/Plugins/AppointmentPlugin/AppointmentService.cs new file mode 100644 index 0000000..16187d1 --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/AppointmentService.cs @@ -0,0 +1,22 @@ +namespace AppointmentPlugin; + +public class AppointmentService +{ + private readonly List _appointments; + public AppointmentService(List appointments) => _appointments = appointments; + + public ListedResult GetAll() + => Result.Success(_appointments); + + public Result GetById(string id) + { + if (string.IsNullOrWhiteSpace(id)) + return Result.Invalid("ID is required"); + + var appointment = _appointments.Find(u => u.Id == id); + if (appointment is null) + return Result.NotFound(); + + return Result.Success(appointment); + } +} diff --git a/samples/Plugins/AppointmentPlugin/GlobalUsings.cs b/samples/Plugins/AppointmentPlugin/GlobalUsings.cs new file mode 100644 index 0000000..126715b --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/GlobalUsings.cs @@ -0,0 +1,5 @@ +global using Microsoft.AspNetCore.Mvc; +global using Contracts; +global using AppointmentPlugin; +global using CPlugin.Net; +global using SimpleResults; diff --git a/samples/Plugins/AppointmentPlugin/Startup.cs b/samples/Plugins/AppointmentPlugin/Startup.cs new file mode 100644 index 0000000..f5198db --- /dev/null +++ b/samples/Plugins/AppointmentPlugin/Startup.cs @@ -0,0 +1,40 @@ +[assembly: Plugin(typeof(Startup))] + +namespace AppointmentPlugin; + +public class Startup : IWebStartup +{ + public string Name => "appointment"; + public string Description => "Expose endpoints."; + + public void ConfigureServices(IServiceCollection services) + { + services.AddTransient(); + + var appointments = new List + { + new() + { + Id = Guid.NewGuid().ToString(), + DoctorName = "Bob", + PatientName = "Alice", + Date = new DateOnly(2023, 01, 01) + }, + new() + { + Id = Guid.NewGuid().ToString(), + DoctorName = "Dave", + PatientName = "Martin", + Date = new DateOnly(2023, 01, 05) + }, + new() + { + Id = Guid.NewGuid().ToString(), + DoctorName = "Steven", + PatientName = "Smith", + Date = new DateOnly(2023, 01, 10) + }, + }; + services.AddSingleton(appointments); + } +} diff --git a/samples/Plugins/JsonPlugin/CreateJson.cs b/samples/Plugins/JsonPlugin/CreateJson.cs new file mode 100644 index 0000000..33b5e14 --- /dev/null +++ b/samples/Plugins/JsonPlugin/CreateJson.cs @@ -0,0 +1,33 @@ +[assembly: Plugin(typeof(CreateJson))] + +namespace JsonPlugin; + +public class CreateJson : ICommand +{ + public string Name => "json"; + public string Description => "Outputs JSON value."; + + private class Info + { + public string JsonVersion; + public string JsonLocation; + public string Machine; + public string User; + public DateTime Date; + } + + public int Execute() + { + Assembly jsonAssembly = typeof(JsonConvert).Assembly; + var info = new Info + { + JsonVersion = jsonAssembly.FullName, + JsonLocation = jsonAssembly.Location, + Machine = Environment.MachineName, + User = Environment.UserName, + Date = DateTime.Now + }; + Console.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented)); + return 0; + } +} diff --git a/samples/Plugins/JsonPlugin/GlobalUsings.cs b/samples/Plugins/JsonPlugin/GlobalUsings.cs new file mode 100644 index 0000000..ba6a8b3 --- /dev/null +++ b/samples/Plugins/JsonPlugin/GlobalUsings.cs @@ -0,0 +1,5 @@ +global using Contracts; +global using CPlugin.Net; +global using JsonPlugin; +global using Newtonsoft.Json; +global using System.Reflection; diff --git a/samples/Plugins/JsonPlugin/JsonPlugin.csproj b/samples/Plugins/JsonPlugin/JsonPlugin.csproj new file mode 100644 index 0000000..acdfdf5 --- /dev/null +++ b/samples/Plugins/JsonPlugin/JsonPlugin.csproj @@ -0,0 +1,12 @@ + + + + $(SolutionDir)HostApplications/ConsoleApp/bin/$(Configuration)/$(TargetFramework)/plugins/$(MSBuildProjectName) + false + + + + + + + diff --git a/samples/Plugins/OldJsonPlugin/CreateJson.cs b/samples/Plugins/OldJsonPlugin/CreateJson.cs new file mode 100644 index 0000000..6d3806b --- /dev/null +++ b/samples/Plugins/OldJsonPlugin/CreateJson.cs @@ -0,0 +1,31 @@ +[assembly: Plugin(typeof(CreateJson))] + +namespace OldJsonPlugin; + +public class CreateJson : ICommand +{ + public string Name => "oldjson"; + public string Description => "Outputs JSON value."; + + private class Info + { + public string JsonVersion; + public string JsonLocation; + public string Machine; + public DateTime Date; + } + + public int Execute() + { + Assembly jsonAssembly = typeof(JsonConvert).Assembly; + var info = new Info + { + JsonVersion = jsonAssembly.FullName, + JsonLocation = jsonAssembly.Location, + Machine = Environment.MachineName, + Date = DateTime.Now + }; + Console.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented)); + return 0; + } +} diff --git a/samples/Plugins/OldJsonPlugin/GlobalUsings.cs b/samples/Plugins/OldJsonPlugin/GlobalUsings.cs new file mode 100644 index 0000000..19fd52b --- /dev/null +++ b/samples/Plugins/OldJsonPlugin/GlobalUsings.cs @@ -0,0 +1,5 @@ +global using Contracts; +global using CPlugin.Net; +global using OldJsonPlugin; +global using Newtonsoft.Json; +global using System.Reflection; diff --git a/samples/Plugins/OldJsonPlugin/OldJsonPlugin.csproj b/samples/Plugins/OldJsonPlugin/OldJsonPlugin.csproj new file mode 100644 index 0000000..f93ee78 --- /dev/null +++ b/samples/Plugins/OldJsonPlugin/OldJsonPlugin.csproj @@ -0,0 +1,12 @@ + + + + $(SolutionDir)HostApplications/ConsoleApp/bin/$(Configuration)/$(TargetFramework)/plugins/$(MSBuildProjectName) + false + + + + + + + From e1f3e3354724638b0822a9502c9e99fc79b77eba Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:38:37 -0500 Subject: [PATCH 6/9] docs: Add sample contracts that are shared between plugins and the host app --- samples/Contracts/Contracts.csproj | 12 ++++++++++++ samples/Contracts/ICommand.cs | 8 ++++++++ samples/Contracts/IWebStartup.cs | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 samples/Contracts/Contracts.csproj create mode 100644 samples/Contracts/ICommand.cs create mode 100644 samples/Contracts/IWebStartup.cs diff --git a/samples/Contracts/Contracts.csproj b/samples/Contracts/Contracts.csproj new file mode 100644 index 0000000..78ea792 --- /dev/null +++ b/samples/Contracts/Contracts.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + latest + + + + + + + diff --git a/samples/Contracts/ICommand.cs b/samples/Contracts/ICommand.cs new file mode 100644 index 0000000..7bcaadc --- /dev/null +++ b/samples/Contracts/ICommand.cs @@ -0,0 +1,8 @@ +namespace Contracts; + +public interface ICommand +{ + string Name { get; } + string Description { get; } + int Execute(); +} diff --git a/samples/Contracts/IWebStartup.cs b/samples/Contracts/IWebStartup.cs new file mode 100644 index 0000000..3a1b38c --- /dev/null +++ b/samples/Contracts/IWebStartup.cs @@ -0,0 +1,10 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Contracts; + +public interface IWebStartup +{ + string Name { get; } + string Description { get; } + void ConfigureServices(IServiceCollection services); +} From 981bdfb70f19e46d8b022f1641be477ff0b6028a Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:40:36 -0500 Subject: [PATCH 7/9] docs: Add host applications as samples --- samples/HostApplications/ConsoleApp/.env | 1 + .../ConsoleApp/ConsoleApp.csproj | 16 ++++++++ .../ConsoleApp/GlobalUsings.cs | 3 ++ .../HostApplications/ConsoleApp/Program.cs | 12 ++++++ .../Controllers/WeatherForecastController.cs | 31 ++++++++++++++ .../HostApplications/WebApi/GlobalUsings.cs | 6 +++ samples/HostApplications/WebApi/Program.cs | 41 +++++++++++++++++++ .../WebApi/Properties/launchSettings.json | 41 +++++++++++++++++++ .../WebApi/WeatherForecast.cs | 12 ++++++ samples/HostApplications/WebApi/WebApi.csproj | 18 ++++++++ .../WebApi/appsettings.Development.json | 8 ++++ .../HostApplications/WebApi/appsettings.json | 12 ++++++ 12 files changed, 201 insertions(+) create mode 100644 samples/HostApplications/ConsoleApp/.env create mode 100644 samples/HostApplications/ConsoleApp/ConsoleApp.csproj create mode 100644 samples/HostApplications/ConsoleApp/GlobalUsings.cs create mode 100644 samples/HostApplications/ConsoleApp/Program.cs create mode 100644 samples/HostApplications/WebApi/Controllers/WeatherForecastController.cs create mode 100644 samples/HostApplications/WebApi/GlobalUsings.cs create mode 100644 samples/HostApplications/WebApi/Program.cs create mode 100644 samples/HostApplications/WebApi/Properties/launchSettings.json create mode 100644 samples/HostApplications/WebApi/WeatherForecast.cs create mode 100644 samples/HostApplications/WebApi/WebApi.csproj create mode 100644 samples/HostApplications/WebApi/appsettings.Development.json create mode 100644 samples/HostApplications/WebApi/appsettings.json diff --git a/samples/HostApplications/ConsoleApp/.env b/samples/HostApplications/ConsoleApp/.env new file mode 100644 index 0000000..08df5e1 --- /dev/null +++ b/samples/HostApplications/ConsoleApp/.env @@ -0,0 +1 @@ +PLUGINS=OldJsonPlugin.dll JsonPlugin.dll \ No newline at end of file diff --git a/samples/HostApplications/ConsoleApp/ConsoleApp.csproj b/samples/HostApplications/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..685c991 --- /dev/null +++ b/samples/HostApplications/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,16 @@ + + + + Exe + + + + + + + + + + + + diff --git a/samples/HostApplications/ConsoleApp/GlobalUsings.cs b/samples/HostApplications/ConsoleApp/GlobalUsings.cs new file mode 100644 index 0000000..40307ff --- /dev/null +++ b/samples/HostApplications/ConsoleApp/GlobalUsings.cs @@ -0,0 +1,3 @@ +global using Contracts; +global using CPlugin.Net; +global using DotEnv.Core; diff --git a/samples/HostApplications/ConsoleApp/Program.cs b/samples/HostApplications/ConsoleApp/Program.cs new file mode 100644 index 0000000..1a5697c --- /dev/null +++ b/samples/HostApplications/ConsoleApp/Program.cs @@ -0,0 +1,12 @@ +// 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); +var contracts = PluginLoader.Load(); +foreach(ICommand contract in contracts) +{ + contract.Execute(); +} diff --git a/samples/HostApplications/WebApi/Controllers/WeatherForecastController.cs b/samples/HostApplications/WebApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..5ce71f5 --- /dev/null +++ b/samples/HostApplications/WebApi/Controllers/WeatherForecastController.cs @@ -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 _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public ListedResult 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); + } +} diff --git a/samples/HostApplications/WebApi/GlobalUsings.cs b/samples/HostApplications/WebApi/GlobalUsings.cs new file mode 100644 index 0000000..00014dc --- /dev/null +++ b/samples/HostApplications/WebApi/GlobalUsings.cs @@ -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; diff --git a/samples/HostApplications/WebApi/Program.cs b/samples/HostApplications/WebApi/Program.cs new file mode 100644 index 0000000..3a79bc4 --- /dev/null +++ b/samples/HostApplications/WebApi/Program.cs @@ -0,0 +1,41 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +var jsonConfiguration = new CPluginJsonConfiguration(builder.Configuration); +PluginLoader.SetConfiguration(jsonConfiguration); +var contracts = PluginLoader.Load(); +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 controller 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(); diff --git a/samples/HostApplications/WebApi/Properties/launchSettings.json b/samples/HostApplications/WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..b857a27 --- /dev/null +++ b/samples/HostApplications/WebApi/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/samples/HostApplications/WebApi/WeatherForecast.cs b/samples/HostApplications/WebApi/WeatherForecast.cs new file mode 100644 index 0000000..dafa103 --- /dev/null +++ b/samples/HostApplications/WebApi/WeatherForecast.cs @@ -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; } +} diff --git a/samples/HostApplications/WebApi/WebApi.csproj b/samples/HostApplications/WebApi/WebApi.csproj new file mode 100644 index 0000000..7436b5d --- /dev/null +++ b/samples/HostApplications/WebApi/WebApi.csproj @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/samples/HostApplications/WebApi/appsettings.Development.json b/samples/HostApplications/WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/samples/HostApplications/WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/samples/HostApplications/WebApi/appsettings.json b/samples/HostApplications/WebApi/appsettings.json new file mode 100644 index 0000000..cbf19de --- /dev/null +++ b/samples/HostApplications/WebApi/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "Plugins": [ + "AppointmentPlugin.dll" + ] +} From 0d50a575f9a1e75aa5edef781fe7fa48d0a23769 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:50:23 -0500 Subject: [PATCH 8/9] style: Update comment --- samples/HostApplications/WebApi/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/HostApplications/WebApi/Program.cs b/samples/HostApplications/WebApi/Program.cs index 3a79bc4..1fca19d 100644 --- a/samples/HostApplications/WebApi/Program.cs +++ b/samples/HostApplications/WebApi/Program.cs @@ -13,7 +13,7 @@ IMvcBuilder mvcBuilder = builder.Services.AddControllers(); foreach (Assembly assembly in PluginLoader.Assemblies) { - // This allows to register the controller for each loaded assembly. + // This allows to register the controllers for each loaded assembly. mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(assembly)); } From 2d830d370f7744c7c53ad28289ee636d58cc9600 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 14 Nov 2023 12:56:13 -0500 Subject: [PATCH 9/9] style: Add comment to specify where the plugin files are obtained from --- samples/HostApplications/ConsoleApp/Program.cs | 1 + samples/HostApplications/WebApi/Program.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/samples/HostApplications/ConsoleApp/Program.cs b/samples/HostApplications/ConsoleApp/Program.cs index 1a5697c..cc03969 100644 --- a/samples/HostApplications/ConsoleApp/Program.cs +++ b/samples/HostApplications/ConsoleApp/Program.cs @@ -5,6 +5,7 @@ var envConfiguration = new CPluginEnvConfiguration(); PluginLoader.SetConfiguration(envConfiguration); +// Loads the plugins from the .env file. var contracts = PluginLoader.Load(); foreach(ICommand contract in contracts) { diff --git a/samples/HostApplications/WebApi/Program.cs b/samples/HostApplications/WebApi/Program.cs index 1fca19d..c63f901 100644 --- a/samples/HostApplications/WebApi/Program.cs +++ b/samples/HostApplications/WebApi/Program.cs @@ -4,6 +4,7 @@ var jsonConfiguration = new CPluginJsonConfiguration(builder.Configuration); PluginLoader.SetConfiguration(jsonConfiguration); +// Loads the plugins from the appsettings.json file. var contracts = PluginLoader.Load(); foreach(IWebStartup contract in contracts) {