Dependency Injection¶
The Imprevis plugin framework uses the concept of Dependency Injection to allow you to write better code. Each plugin runner is resolved from the dependency injection container, which means it will automatically resolve any of the dependencies in the constructor.
By default, the standard Dataverse services are registered in the dependency injection container and are available for use:
IOrganizationServiceFactoryIPluginExecutionContextILoggerITracingServiceIServiceEndpointNotificationService
In addition, there are a few other services registered which will help you when writing common plugins:
ICacheServiceIDataverseServiceFactoryIDateTimeServiceIHttpServiceILoggingServiceIPluginConfigService
If you want to register additional services, you can! This is done by overriding the ConfigureServices method of the plugin class. For example:
public class TestPlugin : Plugin<TestPluginRunner>
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IBusinessLogic, BusinessLogic>();
}
}
This will then make the IBusinessLogic interface available for injection into the plugin runner.