Skip to main content

RSCG_CompositeProvider by Ignat Andrei

NuGet / site data

NugetNuget GitHub last commit GitHub Repo stars

Details

Info

Original Readme

note

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

  <ItemGroup>
<PackageReference Include="RSCG_CompositeProvider" Version="2025.218.2100" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="RSCG_CompositeProvider_Common" Version="2025.218.2100" />
</ItemGroup>

Then if you have an interface like this

public interface IDataFrom
{
string Name { get; }
Task<string> KeyFromValue(string value, bool isKey);
}

and multiple implementation of the interface like this

class DataFromHttp : IDataValue
{
public string Name { get { return "DataFromHttp"; } set { } }

public async Task<string> 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<string> 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


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);

About

note

Generate composite class from interface, using multiple sources

How to use

Example (source csproj, source files)

This is the CSharp Project that references RSCG_CompositeProvider

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="RSCG_CompositeProvider" Version="2025.218.2100" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="RSCG_CompositeProvider_Common" Version="2025.218.2100" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX


// <auto-generated/>
namespace Generated.CP_Console
{
public static class TheAssemblyInfo
{

public static readonly System.DateTime DateGeneratedUTC ;
public const string AssemblyName = "CP_Console";
public const string GeneratedNameNice = "Joseph Brodsky is feeling hard in Willemstad";
public const string GeneratedNameSmall = "hard-Joseph Brodsky";
public const string GeneratedName = "hard-Joseph Brodsky-Willemstad";
static TheAssemblyInfo(){
DateGeneratedUTC = System.DateTime.ParseExact("2025-07-24 04:41:22", "yyyy-MM-dd HH:mm:ss", null);
}
}
}

Useful

Download Example (.NET C#)

Share RSCG_CompositeProvider

https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_CompositeProvider

aaa

Category "Interface" has the following generators:

1 AutoInterface

2 Biwen.AutoClassGen

3 CopyCat

4 Farskeptic.AutoCompose

5 MakeInterface.Generator

6 Matryoshki

7 Minerals.AutoInterfaces

8 NetAutomaticInterface

9 ProxyGen

10 Roozie.AutoInterface

11 RSCG_CompositeProvider

12 rscg_Interface_to_null_object

13 RSCG_Static

14 ShadowWriterNullobjects

See category

Interface