RkSoftware.RKPlugin
0.5.0
dotnet add package RkSoftware.RKPlugin --version 0.5.0
NuGet\Install-Package RkSoftware.RKPlugin -Version 0.5.0
<PackageReference Include="RkSoftware.RKPlugin" Version="0.5.0" />
<PackageVersion Include="RkSoftware.RKPlugin" Version="0.5.0" />
<PackageReference Include="RkSoftware.RKPlugin" />
paket add RkSoftware.RKPlugin --version 0.5.0
#r "nuget: RkSoftware.RKPlugin, 0.5.0"
#:package RkSoftware.RKPlugin@0.5.0
#addin nuget:?package=RkSoftware.RKPlugin&version=0.5.0
#tool nuget:?package=RkSoftware.RKPlugin&version=0.5.0
RKPlugin
Usage
Applocation Code
Example in a web application
This is the code that calls the "ConfigureServices" method of the plugin library.
var pluginPath = Path.Combine(Assembly.GetEntryAssembly()?.Location!, "../../../../../TestPlugin/bin/Debug/net10.0");
var plugins = PluginLoadContext.LoadExtensions(pluginPath);
foreach (var plugin in plugins)
foreach (var assembly in plugin.Assemblies)
foreach (var type in assembly.GetTypes())
{
var method = type.GetMethod("ConfigureServices");
if (method != null)
{
var result = PluginLoadContext.Invoke(services, method, null, null);
Debug.Write(result);
}
}
Plugin Library Code
Create a class library project
Use the methods of the "PluginServiceCollection" class in the "ConfigureServices" method.
The plugin does not need to reference assemblies such as "Microsoft.Extensions.Http" or "Microsoft.Extensions.DependencyInjection.Abstractions".
public class Class1
{
public static string ConfigureServices(object services)
{
var r01 = PluginServiceCollection.AddHttpClient<ITest, Test>(services, F01)?.ToString();
var r02 = PluginServiceCollection.AddScoped(services, F02)?.ToString();
return string.Join(", ", r02, r02);
}
static Test F01(HttpClient httpClient) => new Test();
static Test F02(IServiceProvider serviceProvider) => new Test();
}
Where to put the class library DLL
The DLL file will be loaded as a plugin by placing it in the path specified in the argument of the PluginLoadContext.LoadExtensions method.
var pluginPath = Path.Combine(Assembly.GetEntryAssembly()?.Location!, "../../../../../TestPlugin/bin/Debug/net10.0");
var plugins = PluginLoadContext.LoadExtensions(pluginPath);
What is implemented
Extension Methods on ServiceCollection
- All Methods.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.