https://github.com/ignatandrei/RSCG_CompositeProvider
Composite provider from interface . Given multiple implementation of an interface , return data from each / one
https://github.com/ignatandrei/RSCG_CompositeProvider
Last synced: about 2 months ago
JSON representation
Composite provider from interface . Given multiple implementation of an interface , return data from each / one
- Host: GitHub
- URL: https://github.com/ignatandrei/RSCG_CompositeProvider
- Owner: ignatandrei
- License: mit
- Created: 2025-02-16T13:39:51.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-02-16T19:17:24.000Z (about 2 months ago)
- Last Synced: 2025-02-16T20:25:06.476Z (about 2 months ago)
- Language: C#
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - https://github.com/ignatandrei/RSCG_CompositeProvider
README
# RSCG_CompositeProvider
Composite provider from interface . Given multiple implementation of an interface , return data from each / one
## Usage
Add the nuget package to your project
```
dotnet add package RSCG_CompositeProvider
dotnet add package RSCG_CompositeProviderCommon
```or put in your csproj file
```xml
```Then if you have an interface like this
```csharp
public interface IDataFrom
{
string Name { get; }
Task KeyFromValue(string value, bool isKey);
}
```and multiple implementation of the interface like this
```csharp
class DataFromHttp : IDataValue
{
public string Name { get { return "DataFromHttp"; } set { } }public async Task KeyFromValue(string key, bool defaultValue)
{
var http=new HttpClient();
var result = await http.GetStringAsync("https://www."+ Guid.NewGuid().ToString()+".com/" + key);
return result;
}
}class DataFromMemory : IDataValue
{
public string Name { get { return "DataFromMemory"; } set { } }public async Task KeyFromValue(string key, bool defaultValue)
{
await Task.Delay(1000);
return $"this is value for {key} from memory";
}
}
```then you can call the composite provider to get data from all the implementation of the interface like this
```csharp
IDataValue provider = new DataValue_CP(new DataFromHttp(), new DataFromMemory());
var result = await provider.KeyFromValue("test", false);
Console.WriteLine(result);
DataValue_CP realClass = (DataValue_CP)provider ;
var lastInterface = realClass.lastUsedInterface ?? -1;
Console.WriteLine("value was obtained from " + realClass.Get(lastInterface).Name);
```