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 = "Bertrand Russell is feeling good-natured in Rothera";
public const string GeneratedNameSmall = "good-natured-Bertrand Russell";
public const string GeneratedName = "good-natured-Bertrand Russell-Rothera";
static TheAssemblyInfo(){
DateGeneratedUTC = System.DateTime.ParseExact("2025-02-24 14:32:51", "yyyy-MM-dd HH:mm:ss", null);
}
}
}

Usefull

Download Example (.NET C# )

Share RSCG_CompositeProvider

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

In the same category (Interface) - 11 other generators

Biwen.AutoClassGen

CopyCat

Farskeptic.AutoCompose

MakeInterface.Generator

Matryoshki

Minerals.AutoInterfaces

NetAutomaticInterface

ProxyGen

Roozie.AutoInterface

rscg_Interface_to_null_object

RSCG_Static