tt.factory 1.3.1

dotnet add package tt.factory --version 1.3.1
                    
NuGet\Install-Package tt.factory -Version 1.3.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="tt.factory" Version="1.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="tt.factory" Version="1.3.1" />
                    
Directory.Packages.props
<PackageReference Include="tt.factory" />
                    
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 tt.factory --version 1.3.1
                    
#r "nuget: tt.factory, 1.3.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 tt.factory@1.3.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=tt.factory&version=1.3.1
                    
Install as a Cake Addin
#tool nuget:?package=tt.factory&version=1.3.1
                    
Install as a Cake Tool

How does the factory find a type to instantiate? Add the ClassDefinitionAttribute to any class you want to be available to the factory. Use an instance of TypePreferences to specify type requirements. If the Code property is set the factory will only instantiate it for clients that provide the code. The code is not case sensitive. The dictionary of properties will be used to find a type with corresponding properties that allows the values you have specified in the dictionary.

How do I use the factory to create an instance of an object? The generic parameter designates the type of object to create. It does not need to be a concrete type. The dictionary provides key-value pairs corresponding to properties on the object.

Here is an example that expects an instance of the IName interface. It will look for a class with a 'Name' property that can be set to 'Sam'. The default constructor for the class will be called and then the setter for the Name property will be used to set the name to 'Sam'. Factory.Create<IName>(new Dictionary<string, object>() { { "Name", "Sam" } });

What properties are available? Add the PropertyDefinitionAttribute to any property you want to be available to the factory.

How do I control what values can be assigned to a property? There are two properties on PropertyDefinitionAttribute; ValidationFunction and Value. ValidationFunction is checked first. The property will only be assigned with a value that is valid according to one of these two properties or if both properties are NULL.

  • ValidationFunction A function to determine if a value is valid for the property. The function must take the proposed value as an argument and return a boolean. If the function returns true, the value is considered a valid value for the property. The function must be defined in the class. It does not need to be public. It must be static.
  • Value A valid value.

How do I create a type that is defined in an assembly that isn't loaded in memory? Use the overload that takes an instance of TypePreferences. Add the path of each directory you would like to search to the SearchPaths list. If a matching type is not found in the assemblies that are loaded then these paths will be used to find a matching type.

Repository https://github.com/TrevorTubbs/factory

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.  net9.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.1

    • 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.3.1 665 5/9/2020
1.3.0 639 7/20/2019
1.2.0 1,285 5/12/2018
1.1.0 1,264 5/5/2018
1.0.0 1,323 5/1/2018

Added support for .NET Core.