Spoleto.Delivery.Extensions.Cdek
1.0.24
See the version list below for details.
dotnet add package Spoleto.Delivery.Extensions.Cdek --version 1.0.24
NuGet\Install-Package Spoleto.Delivery.Extensions.Cdek -Version 1.0.24
<PackageReference Include="Spoleto.Delivery.Extensions.Cdek" Version="1.0.24" />
paket add Spoleto.Delivery.Extensions.Cdek --version 1.0.24
#r "nuget: Spoleto.Delivery.Extensions.Cdek, 1.0.24"
// Install Spoleto.Delivery.Extensions.Cdek as a Cake Addin #addin nuget:?package=Spoleto.Delivery.Extensions.Cdek&version=1.0.24 // Install Spoleto.Delivery.Extensions.Cdek as a Cake Tool #tool nuget:?package=Spoleto.Delivery.Extensions.Cdek&version=1.0.24
Spoleto.Delivery
Spoleto.Delivery is a comprehensive solution designed to integrate delivery functionality into your .NET applications. This project provides a maintainable architecture that simplifies interaction with various delivery providers (e.g., Cdek, MasterPost).
This project supports .NET Standard 2.0, .NET 7, and .NET 8.
https://github.com/spoleto-software/Spoleto.Delivery
Features
- Abstraction Layer: Simplifies the integration of delivery services by providing a unified interface.
- Multiple Providers: Supports various delivery providers, allowing you to switch or combine them easily.
- Async Support: Fully supports asynchronous operations for improved performance.
Quick setup
Begin by installing the package through the NuGet package manager with the command:
Install-Package Spoleto.Delivery
.
Usage
Main Interface
The main interface, IDeliveryService
, serves as an abstraction layer for the delivery of goods.
It includes all the necessary methods for work with delivery providers, such as getting available tariffs, creating and deleting delivery orders, and others.
DeliveryProvider
Each delivery provider must implement the IDeliveryProvider
interface.
DeliveryProvider is the underlying mechanisms that enable the actual delivery functionality. When you incorporate Spoleto.Delivery into your application, it's mandatory to install at least one of the available delivery providers.
The providers come as pre-configured NuGet packages:
- Spoleto.Delivery.Cdek: Delivery via CDEK https://www.cdek.ru/;
- Spoleto.Delivery.MasterPost: Delivery via MasterPost https://mplogistics.ru/;
Example
Here is a simple example to demonstrate how to use Spoleto.Delivery in your project:
using Spoleto.Delivery;
using Spoleto.Delivery.Providers;
public class Example
{
public async Task Run()
{
var deliveryService = new DeliveryServiceFactory()
.WithOptions(x => x.DefaultProvider == CdekProvider.ProviderName)
.AddProvider(new CdekProvider(cdekOptions))
.AddProvider(new MasterPostProvider(masterPostOptions))
.Build();
var cityRequest = new CityRequest
{
Name = "Москва"
};
var cities = await deliveryService.GetCitiesAsync(cityRequest);
var tariffRequest = new TariffRequest
{
FromLocation = new() { ProviderLocationCode = "270" },
ToLocation = new() { ProviderLocationCode = "44" },
Packages =
[
new()
{
Weight = 4000,
Height = 10,
Width = 10,
Length = 10
}
],
};
var tariffs = await deliveryService.GetTariffsAsync(tariffRequest);
var deliveryOrderRequest = new DeliveryOrderRequest
{
Type = OrderType.RegularDelivery,
Comment = "Just another test order",
FromLocation = new()
{
Address = "Москва, пр. Ленинградский, д.4",
},
ToLocation = new()
{
Address = "Москва, ул. Блюхера, 32"
},
TariffCode = tariffs.First().Code,
Packages =
[
new()
{
Number = "1",
Comment = "Test",
Weight = 1000,
Width = 10,
Height = 10,
Length = 10,
},
],
Sender = new()
{
Company = "Roga",
Name = "Copyta",
Email = "roga@copyta.com",
Phones =
[
new() { Number = "+71111111111" },
],
},
Recipient = new()
{
Company = "Ushi",
Name = "Hvost",
Email = "ushi@hvost.com",
Phones =
[
new() { Number = "+72222222222" },
],
},
};
var order = await deliveryService.CreateDeliveryOrderAsync(deliveryOrderRequest);
Console.WriteLine($"Order created with ID: {order.Uuid} and Number: {order.Number}");
}
}
More actual examples you can find in tests here:
https://github.com/spoleto-software/Spoleto.Delivery/tree/main/src/Tests
Dependency Injection
To integrate Spoleto.Delivery into Microsoft Dependency injection framework, you should utilize the Spoleto.Delivery.Extensions NuGet package. This package provides an extension method for the IServiceCollection
interface, which register the DeliveryService as a scoped service.
The extentions for Delivery providers come as pre-configured NuGet packages:
- Spoleto.Delivery.Extensions.Cdek: CDEK registration;
- Spoleto.Delivery.Extensions.MasterPost: MasterPost registration.
After ensuring that the Spoleto.Delivery.Extensions
package with at least one Delivery provider package are installed from NuGet, you can proceed with the registration of Spoleto.Delivery within the Startup.cs
or your DI configuration file in the following manner:
public void ConfigureServices(IServiceCollection services)
{
// Other DI registrations...
// Register Spoleto.Delivery as a scoped service:
services.AddDelivery(MasterPostProvider.ProviderName)
.AddMasterPost("MasterPost_IndividualClientNumber", "MasterPost_ApiKey", "MasterPost_ApiKey", "MasterPost_ServiceUrl")
.AddCdek("Cdek_CliendId", "Cdek_ClientSecret", "Cdek_ServiceUrl");
// Continue with the rest of your service configuration...
}
Injecting the Delivery Service into Your Classes
Once Spoleto.Delivery has been registered with your Dependency Injection framework, you can facilitate the injection of the Delivery service into any class within your application.
Inject the IDeliveryService
interface into the constructors of the classes where you want to use Delivery functionality:
public class YourDeliveryClass
{
private readonly ILogger<YourDeliveryClass> _logger;
private readonly IDeliveryService _deliveryService;
public YourDeliveryClass(ILogger<YourDeliveryClass> logger, IDeliveryService deliveryService)
{
_logger = logger;
_deliveryService = deliveryService;
}
public async Task CreateDeliveryOrder(ModelRequest from, ModelRequest to, ModelData data)
{
// create a DeliveryOrderRequest
var deliveryOrderRequest = CreateDeliveryOrderRequest(from, to, data);
// create the delivery order using the default Delivery provider:
var order = await _deliveryService.CreateDeliveryOrderAsync(deliveryOrderRequest);
// create the delivery order using the specified Delivery provider:
var order1 = await _deliveryService.CreateDeliveryOrderAsync(DeliveryProviderName.Cdek, deliveryOrderRequest);
var order2 = await _deliveryService.CreateDeliveryOrderAsync(DeliveryProviderName.MasterPost, deliveryOrderRequest);
// log the result:
_logger.LogInformation("Order created with ID: {order.Uuid} and Number: {order.Number}", order.Uuid, order.Number);
}
}
Spoleto.AddressResolver
Spoleto.AddressResolver is a library for parsing textual representations of addresses. It is designed to break down an address into its components, such as city, street, house number, fias, kladr and postal code.
This library is used in the following code:
- MasterPost provider to parse textual representations of an address to get a city Fias identifier, if it is not provided.
- Cdek provider in the GetDeliveryPoints method for the same reason.
Callbacks
Also the solution provides demo examples of implementation of services for updating delivery order statuses.
Spoleto.Delivery.Callback.Cdek
Web Api callback service for Cdek webhooks:
Spoleto.Delivery.Callback.MasterPost
Windows service to check delivery order statuses from MasterPost Web service with a specified frequency:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Spoleto.Delivery.Cdek (>= 1.0.24)
- Spoleto.Delivery.Extensions (>= 1.0.24)
-
net7.0
- Spoleto.Delivery.Cdek (>= 1.0.24)
- Spoleto.Delivery.Extensions (>= 1.0.24)
-
net8.0
- Spoleto.Delivery.Cdek (>= 1.0.24)
- Spoleto.Delivery.Extensions (>= 1.0.24)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.43 | 75 | 11/12/2024 |
1.0.42 | 73 | 11/12/2024 |
1.0.41 | 78 | 11/11/2024 |
1.0.40 | 76 | 11/8/2024 |
1.0.39 | 67 | 11/6/2024 |
1.0.38 | 68 | 11/6/2024 |
1.0.37 | 84 | 10/4/2024 |
1.0.36 | 71 | 10/4/2024 |
1.0.35 | 73 | 10/4/2024 |
1.0.34 | 68 | 10/4/2024 |
1.0.33 | 88 | 10/4/2024 |
1.0.32 | 77 | 10/4/2024 |
1.0.31 | 75 | 10/3/2024 |
1.0.30 | 68 | 10/3/2024 |
1.0.29 | 72 | 10/3/2024 |
1.0.28 | 70 | 10/3/2024 |
1.0.27 | 68 | 10/3/2024 |
1.0.26 | 70 | 10/3/2024 |
1.0.25 | 67 | 10/3/2024 |
1.0.24 | 75 | 10/3/2024 |
1.0.23 | 73 | 10/2/2024 |
1.0.22 | 75 | 10/2/2024 |
1.0.21 | 76 | 10/1/2024 |
1.0.20 | 78 | 9/30/2024 |
1.0.19 | 76 | 9/29/2024 |
1.0.18 | 78 | 9/28/2024 |
1.0.17 | 78 | 9/28/2024 |
1.0.16 | 84 | 9/25/2024 |
1.0.15 | 83 | 9/24/2024 |
1.0.14 | 91 | 9/24/2024 |
1.0.13 | 76 | 9/24/2024 |
1.0.12 | 85 | 9/23/2024 |
1.0.11 | 92 | 9/23/2024 |
1.0.10 | 79 | 9/23/2024 |
1.0.9 | 82 | 9/19/2024 |
1.0.8 | 88 | 9/19/2024 |
1.0.7 | 90 | 9/18/2024 |
1.0.6 | 80 | 9/18/2024 |
1.0.5 | 93 | 9/17/2024 |
1.0.4 | 112 | 9/12/2024 |
1.0.3 | 111 | 9/6/2024 |
1.0.2 | 94 | 8/7/2024 |
1.0.1 | 98 | 6/13/2024 |
1.0.0 | 101 | 6/12/2024 |