Farskeptic.AutoCompose 1.0.2

dotnet add package Farskeptic.AutoCompose --version 1.0.2                
NuGet\Install-Package Farskeptic.AutoCompose -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Farskeptic.AutoCompose" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Farskeptic.AutoCompose --version 1.0.2                
#r "nuget: Farskeptic.AutoCompose, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Farskeptic.AutoCompose as a Cake Addin
#addin nuget:?package=Farskeptic.AutoCompose&version=1.0.2

// Install Farskeptic.AutoCompose as a Cake Tool
#tool nuget:?package=Farskeptic.AutoCompose&version=1.0.2                

AutoCompose

Nuget Nuget Preview License Downloads GitHub Sponsors GitHub

AutoCompose is a .NET source generator that enables composition without having to implement pass-thru code. There is no runtime reflection.

  • All unimplemented properties and methods on the interface are automatically generated as pass-thru logic.
  • Any implemented properties or methods will NOT be generated by AutoCompose.
  • As you add or remove implementations, AutoCompose re-generates to compensate.

This allows composition to be used as easily as inheritance.

Getting Started

Given an interface named ISample:

Create a class implementing ISample via composition using AutoCompose by:

  1. Implementing a partial class
  2. Adding the instance of the interface as a member variable (e.g. _sample)
  3. Injecting the variable in the constructor
  4. Decorating the class with the AutoCompose attribute
[AutoCompose(typeof(ISample), "_sample")]
public partial class Sample: ISample
{
    protected ISample _sample;

    // all non-implemented properties and methods are automatically generated as pass-thru logic
    public Sample(ISample sample) 
    {
        _sample = sample;
    }

    :
}

AutoCompose runs at compile time, and generates the source required to fully implement the interface.

Composition as easily as Inheritance

When trying to decide between inheritance or composition, the amount of pass-thru code that must be coded and maintained often plays a role in the decision.

Example: When we need to override the implementation of a single method for an interface that contains 10 methods, the code burden of implementing and maintaing the 9 pass-thru methods often causes developers to choose inheritance over composition, regardless of other considerations.

With AutoCompose, this issue goes away. The developer is free to choose inheritance or composition for purely architectural reasons, without having to worry about implementation or maintenance difficulties.

When should I use AutoCompose?

Any time you want to use composition, and have at least one property or method that would be implemented as pass-thru code, AutoCompose can take that burden away from you.

Known Limitations

  1. AutoCompose currently works for interfaces only. It DOES NOT work (yet) for abstract classes.
  2. AutoCompose may not work if your code has multiple definitions of an interface with the same name. AutoCompose (currently) just picks the first matching symbol, and so does not discriminate the target-interface based purely on namespaces.
  3. If your code contains extremely deep namespaces and would generate source code files with very long names, then there can be filename-length conflicts with the windows file system.
Product 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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

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.2 129 4/26/2024
1.0.1 143 3/16/2024
1.0.0 133 3/2/2024