Versioning
The OCPI.Net package supports multiple OCPI versions at the same time. The package uses the OcpiEndpoint
attribute to determine which OCPI versions are supported by a given controller.
Refer to the Implementation section for more information on how to implement OCPI modules using OCPI.Net.
How to implement OCPI Versions Module
After you have marked your OCPI controllers with the OcpiEndpoint
attribute, the package becomes aware of the OCPI versions supported by each controller. The package will automatically generate a list of supported OCPI versions for each module.
An example of how to implement the OCPI Versions module is provided in the Sample application.
In your Versions Module controller, inject the IOcpiVersionsService
service and use it to retrieve the list of supported OCPI versions for each module:
var versionService = serviceProvider.GetRequiredService<IOcpiVersionService>();
Use the GetVersions
method to get a list of all supported OCPI versions:
var versionInfo = versionService.GetVersions();
Use the GetVersionDetails
method to get a list of all supported OCPI endpoints for a given version:
var details = versionService.GetVersionDetails(request);
Example Versions Module implementation
[Route("versions")]
public class OcpiVersionsController : OcpiController
{
// This service scans your codebase and maps all OCPI paths from
// controllers marked with OcpiEndpoint attribute on startup.
private readonly IOcpiVersionService _versionService;
public OcpiVersionsController(IOcpiVersionService versionService)
{
_versionService = versionService;
}
[HttpGet]
public IActionResult GetVersionsAsync()
{
var versionInfo = _versionService.GetVersions();
return OcpiOk(versionInfo);
}
[HttpGet("{request}")]
public IActionResult GetVersionDetailsAsync([FromRoute] string request)
{
var details = _versionService.GetVersionDetails(request);
return OcpiOk(details);
}
}
How to support multiple OCPI versions at the same time
The package allows you to support multiple OCPI versions at the same time. You can do this by marking your controllers with the OcpiEndpoint
attribute and specifying the OCPI versions supported by each controller.
[OcpiEndpoint(OcpiModule.Credentials, "Receiver", "2.2, 2.2.1")]
[Route("2.2/credentials")]
[Route("2.2.1/credentials")]
public class OcpiCredentialsController : OcpiController
{
// Implement your module methods here
}
How to handle version-specific differences in OCPI modules
You can implement version-specific controllers for different versions of the same OCPI Module.
[OcpiEndpoint(OcpiModule.Credentials, "Receiver", "2.1.1")]
[Route("2.1.1/credentials")]
public class OcpiCredentialsV1Controller : OcpiController
{
// Code specific to OCPI 2.1.1
}
[OcpiEndpoint(OcpiModule.Credentials, "Receiver", "2.2.1")]
[Route("2.2.1/credentials")]
public class OcpiCredentialsV2Controller : OcpiController
{
// Code specific to OCPI 2.2.1
}