FactoryFoundation 0.9.1
dotnet add package FactoryFoundation --version 0.9.1
NuGet\Install-Package FactoryFoundation -Version 0.9.1
<PackageReference Include="FactoryFoundation" Version="0.9.1" />
<PackageVersion Include="FactoryFoundation" Version="0.9.1" />
<PackageReference Include="FactoryFoundation" />
paket add FactoryFoundation --version 0.9.1
#r "nuget: FactoryFoundation, 0.9.1"
#:package FactoryFoundation@0.9.1
#addin nuget:?package=FactoryFoundation&version=0.9.1
#tool nuget:?package=FactoryFoundation&version=0.9.1
FactoryFoundation
A micro-library for factories in dotnet.

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:
- You prefer having a consistent way of creating objects
- 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 | Versions 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. |
-
net10.0
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.