Browse Source

Added section: Creating a Simple Plug-In

pull/6710/head
Halil İbrahim Kalkan 6 years ago
parent
commit
21c46846ff
  1. 69
      docs/en/PlugIn-Modules.md
  2. BIN
      docs/en/images/simple-plug-in-dll-file.png
  3. BIN
      docs/en/images/simple-plugin-library.png

69
docs/en/PlugIn-Modules.md

@ -53,4 +53,71 @@ There are two more built-in Plug-In Source implementations:
* `PlugInSources.AddFiles()` gets a list of assembly (typically `dll`) files. This is a shortcut of using `FilePlugInSource` class. * `PlugInSources.AddFiles()` gets a list of assembly (typically `dll`) files. This is a shortcut of using `FilePlugInSource` class.
* `PlugInSources.AddTypes()` gets a list of module class types. If you use this, you need to load the assemblies of the modules yourself, but it provides flexibility when needed. This is a shortcut of using `TypePlugInSource` class. * `PlugInSources.AddTypes()` gets a list of module class types. If you use this, you need to load the assemblies of the modules yourself, but it provides flexibility when needed. This is a shortcut of using `TypePlugInSource` class.
If you need, you can create your own `IPlugInSource` implementation and add to the `options.PlugInSources` just like the others. If you need, you can create your own `IPlugInSource` implementation and add to the `options.PlugInSources` just like the others.
## Creating a Simple Plug-In
Create a simple **Class Library Project** in a solution:
![simple-plugin-library](images/simple-plugin-library.png)
You can add ABP Framework packages you need to use in the module. At least, you should add the `Volo.Abp.Core` package to the project:
````
Install-Package Volo.Abp.Core
````
Every [module](Module-Development-Basics.md) must declare a class derived from the `AbpModule`. Here, a simple module class that resolves a service and initializes it on the application startup:
````csharp
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
namespace MyPlugIn
{
public class MyPlungInModule : AbpModule
{
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var myService = context.ServiceProvider
.GetRequiredService<MyService>();
myService.Initialize();
}
}
}
````
`MyService` can be any class registered to [Dependency Injection](Dependency-Injection.md) system, as show below:
````csharp
using Microsoft.Extensions.Logging;
using Volo.Abp.DependencyInjection;
namespace MyPlugIn
{
public class MyService : ITransientDependency
{
private readonly ILogger<MyService> _logger;
public MyService(ILogger<MyService> logger)
{
_logger = logger;
}
public void Initialize()
{
_logger.LogInformation("MyService has been initialized");
}
}
}
````
Build the project, open the build folder, find the `MyPlugIn.dll`:
![simple-plug-in-dll-file](images/simple-plug-in-dll-file.png)
Copy `MyPlugIn.dll` into the plug-in folder (`D:\Temp\MyPlugIns` for this example).
If you have configured the main application like described above (see Basic Usage section), you should see the `MyService has been initialized` log in the application startup.

BIN
docs/en/images/simple-plug-in-dll-file.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
docs/en/images/simple-plugin-library.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Loading…
Cancel
Save