You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple library that helps to implement a plugin-based architecture.
15
15
16
16
The purpose of this library is to provide a way to load plugins from a configuration file such as settings.json or .env, to facilitate the exchange of dependencies without having to make changes to the host application.
17
17
18
-
See the [API documentation](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.html) for more information on this project.
18
+
See the [API documentation](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.html) for more information on this project.
19
19
20
20
## Index
21
21
@@ -134,7 +134,7 @@ When implementing this pattern in .NET there can be a number of technical challe
134
134
135
135
- Ideally, plugins should not depend on each other (reduce coupling), but in such cases a mechanism must be found that allows them to communicate with each other (e.g. a message broker).
136
136
137
-
- There are cases where the host application and the plugins have a reference to the same version of a dependency, so in their output directories they will have a copy of the same dependency. This may cause unexpected behavior when running the host application. See this [thread](https://stackoverflow.com/q/75435015) or [this one too](https://github.com/MrDave1999/CPlugin.Net/issues/27).
137
+
- There are cases where the host application and the plugins have a reference to the same version of a dependency, so in their output directories they will have a copy of the same dependency. This may cause unexpected behavior when running the host application. See this [thread](https://stackoverflow.com/q/75435015) or [this one too](https://github.com/DevD4v3/CPlugin.Net/issues/27).
138
138
139
139
To correctly implement this pattern in .NET, it is necessary to know how `AssemblyLoadContext` works. This [article](https://tsuyoshiushio.medium.com/understand-advanced-assemblyloadcontext-with-c-16a9d0cfeae3) explains it very well.
140
140
@@ -150,7 +150,7 @@ You must also install this secondary package that will be used in your plugins:
150
150
```sh
151
151
dotnet add package CPlugin.Net.Attributes
152
152
```
153
-
This package provides only one type: [PluginAttribute](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) and is used only in plugins.
153
+
This package provides only one type: [PluginAttribute](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) and is used only in plugins.
154
154
155
155
## Overview
156
156
@@ -167,7 +167,7 @@ This library provides four main types:
167
167
-`PluginLoader`
168
168
-`TypeFinder`
169
169
170
-
See the [API documentation](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.html) for more information on these types.
170
+
See the [API documentation](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.html) for more information on these types.
171
171
172
172
### Get plugin names from .json file
173
173
@@ -348,17 +348,17 @@ foreach(ICommand command in commands)
348
348
```
349
349
`FindSubtypesOf` method will search for the subtypes of `ICommand` in each plugin that has been loaded; if no subtype is found, it returns an empty enumerable.
350
350
351
-
For this method to work correctly, each plugin must use the [PluginAttribute](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) type to specify the subtypes. This is mandatory because the `TypeFinder` type creates the instances of the subtypes using this attribute.
351
+
For this method to work correctly, each plugin must use the [PluginAttribute](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) type to specify the subtypes. This is mandatory because the `TypeFinder` type creates the instances of the subtypes using this attribute.
352
352
353
353
### Integration with Microsoft.Extensions.DependencyInjection
354
354
355
-
The [TypeFinder](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) type is limited: it does not support dependency injection via constructor. So if the implementation of `ICommand` has a constructor with dependencies you will get a runtime exception that the subtype does not have a parameterless constructor.
355
+
The [TypeFinder](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) type is limited: it does not support dependency injection via constructor. So if the implementation of `ICommand` has a constructor with dependencies you will get a runtime exception that the subtype does not have a parameterless constructor.
356
356
357
-
See this thread for more information: [Add support for dependency injection via constructor](https://github.com/MrDave1999/CPlugin.Net/issues/32)
357
+
See this thread for more information: [Add support for dependency injection via constructor](https://github.com/DevD4v3/CPlugin.Net/issues/32)
358
358
359
359
**Example:**
360
360
361
-
The extension method called [AddSubtypesOf](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.CPluginServiceCollectionExtensions.html) must be invoked after loading the plugins.
361
+
The extension method called [AddSubtypesOf](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.CPluginServiceCollectionExtensions.html) must be invoked after loading the plugins.
362
362
```cs
363
363
varconfigurationRoot=newConfigurationBuilder()
364
364
.AddJsonFile("./appsettings.json")
@@ -379,7 +379,7 @@ foreach(ICommand command in commands)
379
379
380
380
### Apply PluginAttribute type to plugins
381
381
382
-
This attribute must be applied at the assembly level in the plugin project. Do not forget to install the [CPlugin.Net.Attributes](https://www.nuget.org/packages/CPlugin.Net.Attributes) package in the plugin project in order to be able to use the [PluginAttribute](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) type.
382
+
This attribute must be applied at the assembly level in the plugin project. Do not forget to install the [CPlugin.Net.Attributes](https://www.nuget.org/packages/CPlugin.Net.Attributes) package in the plugin project in order to be able to use the [PluginAttribute](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.PluginAttribute.html) type.
383
383
384
384
**Example:**
385
385
```cs
@@ -530,7 +530,7 @@ These are the contracts shared between the host application and the plugins and
530
530
531
531
`<ExcludeAssets>runtime</ExcludeAssets>`. This setting has the same effect as `<Private>false</Private>` but works on package references that the Contracts project or one of its dependencies may include.
532
532
533
-
The `Contracts.dll` assembly must only be copied to the output directory of the host application; otherwise, the [FindSubtypesOf](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) method will always return an empty enumerable.
533
+
The `Contracts.dll` assembly must only be copied to the output directory of the host application; otherwise, the [FindSubtypesOf](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) method will always return an empty enumerable.
@@ -539,9 +539,9 @@ The `Contracts.dll` assembly must only be copied to the output directory of the
539
539
```
540
540
`<ExcludeAssets>runtime</ExcludeAssets>`. This avoids having to copy `CPlugin.Net.Attributes.dll` and its dependencies to the plugin output directory.
541
541
542
-
Some plugins have a reference to the `CPlugin.Net.Attributes` package, so you should not copy the `CPlugin.Net.Attributes.dll` assembly to the plugin output directory. This is because the host application already contains such an assembly; otherwise, the [FindSubtypesOf](https://mrdave1999.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) method will always return an empty enumerable.
542
+
Some plugins have a reference to the `CPlugin.Net.Attributes` package, so you should not copy the `CPlugin.Net.Attributes.dll` assembly to the plugin output directory. This is because the host application already contains such an assembly; otherwise, the [FindSubtypesOf](https://DevD4v3.github.io/CPlugin.Net/api/CPlugin.Net.TypeFinder.html) method will always return an empty enumerable.
543
543
544
-
See this thread: [Why can't I copy assemblies like Example.Contracts.dll and CPlugin.Net.Attributes.dll to the plugin output directory?](https://github.com/MrDave1999/CPlugin.Net/issues/27)
544
+
See this thread: [Why can't I copy assemblies like Example.Contracts.dll and CPlugin.Net.Attributes.dll to the plugin output directory?](https://github.com/DevD4v3/CPlugin.Net/issues/27)
545
545
546
546
### Copy plugins to publishing directory
547
547
@@ -567,9 +567,9 @@ You need to add the package called [CopyPluginsToPublishDirectory](https://www.n
567
567
568
568
You can find a complete and functional example in these projects:
0 commit comments