Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hidayatarg/sms.providers
Using multiple SMS Provider with Dependency Injection using Strategy Pattern .Net7.0
https://github.com/hidayatarg/sms.providers
asp-net-core dependency-injection strategy-pattern
Last synced: 1 day ago
JSON representation
Using multiple SMS Provider with Dependency Injection using Strategy Pattern .Net7.0
- Host: GitHub
- URL: https://github.com/hidayatarg/sms.providers
- Owner: hidayatarg
- Created: 2023-11-20T10:35:20.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-01T14:13:36.000Z (11 months ago)
- Last Synced: 2024-01-01T15:26:28.406Z (11 months ago)
- Topics: asp-net-core, dependency-injection, strategy-pattern
- Language: C#
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multiple SMS Providers with Dependency Injection using Strategy Pattern in .net-core 7.0
## SmsService
The `SmsService` is a part of the NT.Sms namespace, designed to facilitate sending SMS messages through various providers. It is implemented in C# using ASP.NET Core 7, making use of the SMS models and providers within the NT.Sms library.
## Overview
The `SmsService` class is responsible for sending SMS messages through different providers. It utilizes an IEnumerable of ISmsProvider to support multiple providers seamlessly.
## Usage
To use the `SmsService`, create an instance of it by providing an IEnumerable of ISmsProvider during initialization. This allows you to inject different SMS providers dynamically.
```csharp
var smsProviders = new List
{
new NexmoSmsProvider(), // Example provider implementation
new TwilioSmsProvider(),
// Add more providers as needed
};var smsService = new SmsService(smsProviders);
```After initializing the `SmsService`, you can send an SMS by calling the `SendSms` method and providing the phone number and message.
```csharp
smsService.SendSms("+123456789", "Hello, this is a test message!");
```The `SendSms` method internally determines the SMS provider based on a provider name retrieved from the database. The provider name is then mapped to an enum value, and the corresponding SMS provider is selected from the injected list.
### Supported Providers
- Nexmo
- Twilio
- Rizon (default if the provider is not recognized)## Dependencies
- ASP.NET Core
- NT.Sms.Models
- NT.Sms.Providers## License
This project is licensed under the [MIT License](LICENSE).
---
Feel free to customize this README according to your specific project needs.