FactoryFoundation 0.9.1

dotnet add package FactoryFoundation --version 0.9.1
                    
NuGet\Install-Package FactoryFoundation -Version 0.9.1
                    
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="FactoryFoundation" Version="0.9.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FactoryFoundation" Version="0.9.1" />
                    
Directory.Packages.props
<PackageReference Include="FactoryFoundation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FactoryFoundation --version 0.9.1
                    
#r "nuget: FactoryFoundation, 0.9.1"
                    
#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.
#:package FactoryFoundation@0.9.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FactoryFoundation&version=0.9.1
                    
Install as a Cake Addin
#tool nuget:?package=FactoryFoundation&version=0.9.1
                    
Install as a Cake Tool

FactoryFoundation

A micro-library for factories in dotnet.

web-logo

build-status downloads nuget activity

Overview

FactoryFoundation gives you:

  • 🏭 Fully typed factories with zero reflection.
  • 🗒️ Consistency via common interfaces.
  • 📦 Auto-registration with the DI container.
  • 🐛 Easy debugging via normal step-through ability.

Table of Contents

Samples

If you would like code samples for FactoryFoundation, they can be found here in the documentation.

Advantages vs Disadvantages of FactoryFoundation

FactoryFoundation is a micro-library. The intention is to help you remove some, but not all, of the ceremony and boilerplate around factories and the mapping of objects from an entity to data transfer object.

Advantages:

  • Common interface and function naming
  • Method generation via your IDE
  • Auto DI registration and resolving
  • Easy debugging

Disadvantages:

  • No automatic mapping

Dependencies

FactoryFoundation has one dependency on the Microsoft.Extensions.DependencyInjection.Abstractions package to allow for easy integration with the DI container.

Installation

The easiest way to get started is to: Install with NuGet.

In your application layer:

Install-Package FactoryFoundation

Setup

FactoryFoundation has a method that will automatically register all of your factories with the DI container.

You may also pass a params of assemblies if required.

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Services.AddFactoryFoundation(Assembly.GetExecutingAssembly());

        // Continue setup below
    }
}

Quick Start

Defining Factories

Defining a factory is straight forward, have a class inherit from the "ICanTranslate" interface of type T and K, where "T" is your initial value and "K" is the value you are mapping to.

public class AirplaneFactory :
    ICanTranslate<Airplane, AirplaneResponse>
{
    public AirplaneResponse TranslateTo(Airplane initial)
    {
        // implementation.
    }
}

Using the Translator interface

When you require a factory, inject an "ITranslator" interface into whatever service or handler required.

public class MyService
{
    private readonly ITranslator _translator;

    public MyService(ITranslator translator)
    {
        _translator = translator;
    }
}

Call the "Translate" method and pass the initial and final type that you wish to translate between.

public class MyService
{
    private readonly ITranslator _translator;

    public MyService(ITranslator translator)
    {
        _translator = translator;
    }

    public MyResponse DoSomething()
    {
        // get data

        return _translator.Translate<MyEntity, MyResponse>(entity);
    }
}

You may also pass the "ICanTranslate" interface if you just need one specific translation.

Factory Helpers

FactoryFoundation comes with a small helper to make object creation easier.

var envelope = FactoryHelpers.TryCreateValidate(() => new Widget());

The function will attempt to create the object specified, if an exception is thrown, the proper envelope response will be returned.

FAQ

Do I Need FactoryFoundation?

The best reasons to use FactoryFoundation is:

  1. You prefer having a consistent way of creating objects
  2. You need a single interface for object mapping

Does FactoryFoundation do any auto mapping?

The library was designed specifically NOT to perform anything automatically. However, there are several advantages to this, FactoryFoundation is far easier to debug versus other automatic libraries. The mapping process can also be significantly faster than other libraries because the process is so simple.

How long does FactoryFoundation take to learn?

Anyone can learn FactoryFoundation in 3 minutes. There are only two interfaces to use, and a single line configuration.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.9.1 152 2/12/2026
0.9.0 89 1/20/2026